| 136 | |
| 137 | template <typename T> |
| 138 | std::shared_ptr<T> LUTManager::get_lut_table(LUTInfo info) |
| 139 | { |
| 140 | auto &map = get_map<T>(); |
| 141 | const auto itr = map.find(info); |
| 142 | auto s_ptr = (itr != map.end()) ? itr->second.lock() : nullptr; // nullptr if invalid or not found. |
| 143 | if (s_ptr != nullptr) |
| 144 | { |
| 145 | // Found and valid |
| 146 | return s_ptr; // Return weak ptr as shared ptr |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | // Not found, or pointer not valid |
| 151 | // We do not use make_shared to prevent the weak_ptr keeping the control block alive |
| 152 | std::shared_ptr<T> ptr(new T); |
| 153 | init_lut(*ptr, info); |
| 154 | map[info] = ptr; |
| 155 | return ptr; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | template std::shared_ptr<LookupTable256> LUTManager::get_lut_table<LookupTable256>(LUTInfo info); |
| 160 | template std::shared_ptr<LookupTable65536> LUTManager::get_lut_table<LookupTable65536>(LUTInfo info); |