Fix incorrect free and leak.
[libdcp.git] / src / lut_cache.h
1 #ifndef LIBDCP_LUT_CACHE_H
2 #define LIBDCP_LUT_CACHE_H
3
4 #include <list>
5 #include <boost/shared_ptr.hpp>
6
7 template<class T>
8 class LUTCache
9 {
10 public:
11         boost::shared_ptr<T> get (int bit_depth, float gamma)
12         {
13                 for (typename std::list<boost::shared_ptr<T> >::iterator i = _cache.begin(); i != _cache.end(); ++i) {
14                         if ((*i)->bit_depth() == bit_depth && (*i)->gamma() == gamma) {
15                                 return *i;
16                         }
17                 }
18
19                 boost::shared_ptr<T> lut (new T (bit_depth, gamma));
20                 _cache.push_back (lut);
21                 return lut;
22         }
23
24 private:
25         std::list<boost::shared_ptr<T> > _cache;
26 };
27
28 #endif