CASM  1.1.0
A Clusters Approach to Statistical Mechanics
jsonPropertiesDatabase.hh
Go to the documentation of this file.
1 #ifndef CASM_jsonPropertiesDatabase
2 #define CASM_jsonPropertiesDatabase
3 
4 #include <boost/filesystem/path.hpp>
5 
7 
8 namespace CASM {
9 namespace DB {
10 
11 class jsonPropertiesDatabase;
12 
14  public:
16 
17  std::unique_ptr<jsonPropertiesDatabaseIterator> clone() const {
18  return std::unique_ptr<jsonPropertiesDatabaseIterator>(this->_clone());
19  }
20 
21  private:
22  typedef typename std::map<std::string, MappedProperties>::const_iterator
25 
27 
28  base_iterator base() const { return m_it; }
29 
30  bool equal(const PropertiesDatabaseIteratorBase &other) const override {
31  return m_it ==
32  static_cast<const jsonPropertiesDatabaseIterator &>(other).m_it;
33  }
34 
35  void increment() override { ++m_it; }
36 
37  const MappedProperties &dereference() const override { return m_it->second; }
38 
39  long distance_to(const PropertiesDatabaseIteratorBase &other) const override {
40  return std::distance(
41  m_it, static_cast<const jsonPropertiesDatabaseIterator &>(other).m_it);
42  }
43 
45  return new jsonPropertiesDatabaseIterator(*this);
46  }
47 
49 };
50 
53  public:
61  jsonPropertiesDatabase(const PrimClex &_primclex, std::string calc_type,
62  fs::path location);
63 
64  DatabaseBase &open() override;
65 
66  void commit() override;
67 
68  void close() override;
69 
71  void from_json(jsonParser const &json);
72 
74  jsonParser &to_json(jsonParser &json) const;
75 
77  iterator begin() const override;
78 
80  iterator end() const override;
81 
82  size_type size() const override;
83 
88  iterator find_via_to(std::string to_configname) const override;
89 
92  iterator find_via_origin(std::string origin) const override;
93 
95  std::set<std::string, Compare> all_origins(
96  std::string to_configname) const override;
97 
99  void set_score_method(std::string to_configname,
100  const ScoreMappedProperties &score) override;
101 
102  private:
104 
106  std::pair<iterator, bool> _insert(const MappedProperties &value) override;
107 
109  iterator _erase(iterator pos) override;
110 
112  void _set_all_origins(std::string to_configname,
113  const std::set<std::string, Compare> &_set) override;
114 
115  std::set<std::string, Compare> _make_set(
116  std::string to_configname, const ScoreMappedProperties &score) const;
117 
118  bool m_is_open;
119 
120  std::string m_calc_type;
121  fs::path m_location;
122 
124 
125  // a key whose 'from' value is modified to find MappedProperties in m_data
126  // mutable MappedProperties m_key;
127 
128  // the MappedProperties container
129  std::map<std::string, MappedProperties> m_data;
130 
131  // to -> {from, from, ...}, used to find best mapping
132  std::map<std::string, std::set<std::string, Compare> > m_origins;
133 };
134 
135 } // namespace DB
136 } // namespace CASM
137 
138 #endif
Fully generic database interface for use by DatabaseHandler.
Definition: Database.hh:25
double score(std::string origin) const
Score mapping 'origin'->'to'.
Wrapper class for specializations PropertiesDatabaseIteratorBase.
An implementation of PropertiesDatabase for reading/writing JSON.
std::set< std::string, Compare > _make_set(std::string to_configname, const ScoreMappedProperties &score) const
jsonPropertiesDatabase(const PrimClex &_primclex, std::string calc_type, fs::path location)
void set_score_method(std::string to_configname, const ScoreMappedProperties &score) override
Change the score method for a single configuration.
iterator end() const override
End iterator.
std::map< std::string, std::set< std::string, Compare > > m_origins
std::set< std::string, Compare > all_origins(std::string to_configname) const override
Names of all configurations that relaxed 'origin'->'to'.
iterator find_via_origin(std::string origin) const override
Return iterator to MappedProperties that is from the specified config.
iterator begin() const override
Begin iterator.
iterator find_via_to(std::string to_configname) const override
Return iterator to MappedProperties that is the best mapping to specified config.
std::map< std::string, MappedProperties > m_data
iterator _erase(iterator pos) override
Private _erase MappedProperties, without modifying 'relaxed_from'.
std::pair< iterator, bool > _insert(const MappedProperties &value) override
Private _insert MappedProperties, without modifying 'relaxed_from'.
void from_json(jsonParser const &json)
Clear all and read from JSON.
void _set_all_origins(std::string to_configname, const std::set< std::string, Compare > &_set) override
Names of all configurations that relaxed 'from'->'to'.
jsonParser & to_json(jsonParser &json) const
Export all to JSON.
iterator _iterator(jsonPropertiesDatabaseIterator::base_iterator _it) const
long distance_to(const PropertiesDatabaseIteratorBase &other) const override
std::map< std::string, MappedProperties >::const_iterator base_iterator
jsonPropertiesDatabaseIterator * _clone() const override
std::unique_ptr< jsonPropertiesDatabaseIterator > clone() const
bool equal(const PropertiesDatabaseIteratorBase &other) const override
const MappedProperties & dereference() const override
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:55
GenericDatumFormatter< std::string, Result > to_configname()
Definition: ConfigData.cc:92
Main CASM namespace.
Definition: APICommand.hh:8