DP3
SkyModelCache.h
Go to the documentation of this file.
1 #ifndef SKY_MODEL_CACHE_H_
2 #define SKY_MODEL_CACHE_H_
3 
4 #include <map>
5 #include <stdexcept>
6 #include <string>
7 
8 #include "SourceDBUtil.h"
9 
10 namespace dp3::model {
11 
13  public:
15  static SkyModelCache instance;
16  return instance;
17  }
18 
19  SourceDBWrapper GetSkyModel(const std::string& filename) {
20  if (!HasSkymodelExtension(filename)) {
21  throw std::runtime_error(
22  "Sky models in the 'source db' format are no longer supported by "
23  "DP3. Models need to be provided in the textual format and do not "
24  "require conversion using the 'makesourcedb' tool. If you do not "
25  "have the original text model file, the 'showsourcedb' tool can be "
26  "used to convert a sourcedb back to text format.");
27  } else {
28  auto iterator = cache_.find(filename);
29  if (iterator == cache_.end()) {
30  return cache_.insert_or_assign(filename, SourceDBWrapper(filename))
31  .first->second;
32  } else {
33  return iterator->second;
34  }
35  }
36  }
37 
38  void Clear() { cache_.clear(); }
39 
40  private:
41  std::map<std::string, SourceDBWrapper> cache_;
42 };
43 
44 } // namespace dp3::model
45 
46 #endif
Definition: SkyModelCache.h:12
SourceDBWrapper GetSkyModel(const std::string &filename)
Definition: SkyModelCache.h:19
void Clear()
Definition: SkyModelCache.h:38
static SkyModelCache & GetInstance()
Definition: SkyModelCache.h:14
Definition: SourceDBUtil.h:104
Definition: Patch.h:14
bool HasSkymodelExtension(const std::string &source_db_name)
Definition: SourceDBUtil.h:26