CASM  1.1.0
A Clusters Approach to Statistical Mechanics
Cache.hh
Go to the documentation of this file.
1 #ifndef CASM_Cache
2 #define CASM_Cache
3 
4 #include <string>
5 
7 
8 namespace CASM {
9 
10 namespace DB {
11 
13 class Cache {
14  public:
15  Cache() : m_cache_updated(false) {}
16 
26  template <typename T>
27  void cache_insert(std::string name, const T &data) const {
28  if (!m_cache.contains(name)) {
29  m_cache[name] = data;
30  m_cache_updated = true;
31  }
32  }
33 
35  void set_initial_cache(jsonParser const &_cache) {
36  m_cache = _cache;
37  m_cache_updated = false;
38  }
39 
41  void update_cache(jsonParser const &_cache) {
42  m_cache = _cache;
43  m_cache_updated = true;
44  }
45 
47  const jsonParser &cache() const { return m_cache; }
48 
50  bool cache_updated() const { return m_cache_updated; }
51 
56  void cache_clear() const {
57  m_cache.put_obj();
58  m_cache_updated = true;
59  }
60 
61  protected:
65  jsonParser &cache() { return m_cache; }
66 
67  private:
69  mutable bool m_cache_updated;
70 };
71 } // namespace DB
72 
73 } // namespace CASM
74 
75 #endif
Store data in JSON.
Definition: Cache.hh:13
const jsonParser & cache() const
Access the configuration cache, which will be saved in the database.
Definition: Cache.hh:47
bool m_cache_updated
Definition: Cache.hh:69
void cache_clear() const
Definition: Cache.hh:56
void cache_insert(std::string name, const T &data) const
Definition: Cache.hh:27
jsonParser & cache()
Definition: Cache.hh:65
void update_cache(jsonParser const &_cache)
Upate the configuration cache.
Definition: Cache.hh:41
bool cache_updated() const
Check if cache updated.
Definition: Cache.hh:50
jsonParser m_cache
Definition: Cache.hh:68
void set_initial_cache(jsonParser const &_cache)
Set the configuration cache as read from the database.
Definition: Cache.hh:35
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
Definition: jsonParser.cc:601
jsonParser & put_obj()
Puts new empty JSON object.
Definition: jsonParser.hh:354
Main CASM namespace.
Definition: APICommand.hh:8
GenericDatumFormatter< std::string, DataObject > name()