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 <string>
6 
7 #include "ReadSkyModel.h"
8 #include "SkyModel.h"
9 #include "SkyModelSelection.h"
10 
11 namespace dp3::sky_model {
12 
14  public:
16  static SkyModelCache instance;
17  return instance;
18  }
19 
20  SkyModel GetSkyModel(const std::string& filename) {
21  auto iterator = cache_.find(filename);
22  if (iterator == cache_.end()) {
23  return cache_.insert_or_assign(filename, ReadSkyModel(filename))
24  .first->second;
25  } else {
26  return iterator->second;
27  }
28  }
29 
31  const std::string& filename, const std::vector<std::string>& patterns) {
32  SkyModelSelection selection(GetSkyModel(filename));
33  selection.SelectMatchingPatches(patterns);
34  return selection;
35  }
36 
38  const std::string& filename,
39  const std::vector<std::string>& patch_names) {
40  SkyModelSelection selection(GetSkyModel(filename));
41  selection.SelectPatchList(patch_names);
42  return selection;
43  }
44 
45  void Clear() { cache_.clear(); }
46 
47  private:
48  std::map<std::string, SkyModel> cache_;
49 };
50 
51 } // namespace dp3::sky_model
52 
53 #endif
Class holding all functions needed to convert a .sky_model text file into a .sourcedb directory.
Definition: SkyModelCache.h:13
SkyModel GetSkyModel(const std::string &filename)
Definition: SkyModelCache.h:20
SkyModelSelection GetSkyModelPatches(const std::string &filename, const std::vector< std::string > &patch_names)
Definition: SkyModelCache.h:37
static SkyModelCache & GetInstance()
Definition: SkyModelCache.h:15
SkyModelSelection GetMatchedSkyModel(const std::string &filename, const std::vector< std::string > &patterns)
Definition: SkyModelCache.h:30
void Clear()
Definition: SkyModelCache.h:45
Definition: SkyModelSelection.h:13
void SelectPatchList(const std::vector< std::string > &patch_names)
void SelectMatchingPatches(const std::vector< std::string > &filter)
Definition: SkyModel.h:15
Definition: Patch.h:14
SkyModel ReadSkyModel(const std::string &filename, const std::string &format)