CASM  1.1.0
A Clusters Approach to Statistical Mechanics
jsonDatabase.hh
Go to the documentation of this file.
1 #ifndef CASM_jsonDatabase
2 #define CASM_jsonDatabase
3 
8 
9 namespace CASM {
10 
11 template <typename T>
12 struct traits;
13 
14 namespace DB {
15 template <typename DataObject>
17 class DatabaseHandler;
18 
19 struct jsonDB;
20 } // namespace DB
21 
22 template <>
23 struct traits<DB::jsonDB> {
24  static const std::string name;
25 
27  static const std::string version;
28 
30 };
31 
32 namespace DB {
33 
34 struct jsonDB {
35  static void insert(DatabaseHandler &);
36 
38  public:
39  DirectoryStructure(const fs::path _root);
40 
43  template <typename DataObject>
44  fs::path obj_list() const;
45 
48  template <typename DataObject>
49  fs::path props_list(std::string calctype) const;
50 
51  private:
52  std::string _calctype(std::string calctype) const;
53 
55  };
56 };
57 
71 template <>
72 class jsonDatabase<Supercell> : public Database<Supercell> {
73  public:
74  jsonDatabase<Supercell>(const PrimClex &_primclex);
75 
76  jsonDatabase<Supercell> &open() override;
77 
78  void commit() override;
79 
80  void close() override;
81 
82  private:
83  void _read_scel_list();
84 
85  void _read_SCEL();
86 
87  bool m_is_open;
88 };
89 
114 // the information of all the configurations that correspond to the supercell.
119 template <>
120 class jsonDatabase<Configuration> : public Database<Configuration> {
121  public:
122  jsonDatabase<Configuration>(const PrimClex &_primclex);
123 
124  jsonDatabase<Configuration> &open() override;
125 
126  void commit() override;
127 
128  void close() override;
129 
130  iterator begin() const override;
131 
132  iterator end() const override;
133 
134  size_type size() const override;
135 
136  std::pair<iterator, bool> insert(const Configuration &config) override;
137 
138  std::pair<iterator, bool> insert(const Configuration &&config) override;
139 
140  iterator update(const Configuration &config) override;
141 
142  iterator erase(iterator pos) override;
143 
144  iterator find(const std::string &name_or_alias) const override;
145 
153  const std::string &scelname) const override;
154 
156  iterator search(const Configuration &config) const override;
157 
158  private:
159  typedef std::set<Configuration>::iterator base_iterator;
162 
165  std::pair<iterator, bool> _on_insert_or_emplace(
166  std::pair<base_iterator, bool> &result, bool is_new);
167 
168  iterator _iterator(base_iterator name_it) const {
169  return iterator(db_set_iterator(name_it));
170  }
171 
172  bool m_is_open;
173 
174  // map name -> Configuration
175  std::map<std::string, base_iterator> m_name_to_config;
176 
177  // container of Configuration
178  std::set<Configuration> m_config_list;
179 
180  // map of scelname -> begin and last (not end) configuration in scel
181  std::map<std::string, std::pair<base_iterator, base_iterator> > m_scel_range;
182 
183  // map of scelname -> next id to assign to a new Configuration
184  std::map<std::string, Index> m_config_id;
185 };
186 
187 } // namespace DB
188 } // namespace CASM
189 
190 #endif
Provides access to all databases.
DatabaseIterator for implementations using std::set<ValueType>
std::string _calctype(std::string calctype) const
Definition: jsonDatabase.cc:90
fs::path props_list(std::string calctype) const
Definition: jsonDatabase.cc:85
DirectoryStructure(const fs::path _root)
Definition: jsonDatabase.cc:75
CASM::DirectoryStructure m_dir
Definition: jsonDatabase.hh:54
std::set< Configuration > m_config_list
DatabaseSetIterator< Configuration, jsonDatabase< Configuration > > db_set_iterator
std::set< Configuration >::iterator base_iterator
iterator _iterator(base_iterator name_it) const
std::map< std::string, Index > m_config_id
std::map< std::string, std::pair< base_iterator, base_iterator > > m_scel_range
std::map< std::string, base_iterator > m_name_to_config
Specification of CASM project directory structure.
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:55
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:51
void commit(ProjectSettings const &set)
std::string scelname(const Structure &prim, const Lattice &superlat)
Make supercell name name [deprecated].
Definition: Supercell.cc:497
DatabaseHandler & db_handler
Definition: jsonDatabase.cc:31
GenericDatumFormatter< bool, ConfigEnumDataType > is_new()
ConfigIO::GenericConfigFormatter< jsonParser > config()
Definition: ConfigIO.cc:777
Traits const & traits(std::string const &dof_key)
Lookup DoFType::Traits in the global dictionary.
Definition: DoFTraits.cc:46
Main CASM namespace.
Definition: APICommand.hh:8
Iterator find(Iterator begin, Iterator end, const T &value, BinaryCompare q)
Equivalent to std::find(begin, end, value), but with custom comparison.
Definition: algorithm.hh:16
pair_type calctype
Definition: settings.cc:143
static void insert(DatabaseHandler &)
Definition: jsonDatabase.cc:68
static const std::string version
Database format version, incremented separately from casm –version.
Definition: jsonDatabase.hh:27
static const std::string name
Definition: jsonDatabase.hh:24
static void insert(DB::DatabaseHandler &db_handler)