CASM  1.1.0
A Clusters Approach to Statistical Mechanics
DBInterface.hh
Go to the documentation of this file.
1 #ifndef CASM_DBInterface
2 #define CASM_DBInterface
3 
5 #include "casm/casm_io/Log.hh"
7 
8 namespace CASM {
9 
10 class APICommandBase;
11 class QueryCommand;
12 class SelectCommand;
13 
14 namespace DB {
15 
16 template <typename T>
17 class Selection;
18 
19 template <typename CommandType,
20  template <typename> class ImplType = CommandType::template Impl>
21 struct ConstructImpl {
22  typedef typename CommandType::ImplBase ImplBase;
23  template <typename DataObject>
24  using Impl = ImplType<DataObject>;
25 
26  ConstructImpl(std::unique_ptr<ImplBase> &_impl, const CommandType &_cmd)
27  : impl(_impl), cmd(_cmd) {}
28 
29  template <typename T>
30  void eval() {
31  impl.reset(new Impl<T>(cmd));
32  }
33 
34  std::unique_ptr<ImplBase> &impl;
35  const CommandType &cmd;
36 };
37 
38 template <typename DataObject>
40  public:
41  InterfaceData(const QueryCommand &cmd);
42  InterfaceData(const SelectCommand &cmd);
43 
44  const DataFormatterDictionary<DataObject> &dict() const { return *m_dict; }
45 
46  std::string sel_str() const { return m_ss.str(); }
47 
48  double sel_size() const { return m_sel.size(); }
49 
50  Selection<DataObject> &sel(Index i = 0) { return *m_sel[i]; }
51 
52  const Selection<DataObject> &sel(Index i = 0) const { return *m_sel[i]; }
53 
54  private:
55  void _make_dict(const APICommandBase &cmd);
56 
58 
59  std::unique_ptr<DataFormatterDictionary<DataObject>> m_standard_dict;
60 
61  std::vector<std::unique_ptr<Selection<DataObject>>> m_sel;
62 
63  std::stringstream m_ss;
64 };
65 } // namespace DB
66 } // namespace CASM
67 
68 #endif
std::stringstream m_ss
Definition: DBInterface.hh:63
double sel_size() const
Definition: DBInterface.hh:48
void _make_dict(const APICommandBase &cmd)
const DataFormatterDictionary< DataObject > * m_dict
Definition: DBInterface.hh:57
std::unique_ptr< DataFormatterDictionary< DataObject > > m_standard_dict
Definition: DBInterface.hh:59
const DataFormatterDictionary< DataObject > & dict() const
Definition: DBInterface.hh:44
std::string sel_str() const
Definition: DBInterface.hh:46
InterfaceData(const QueryCommand &cmd)
Selection< DataObject > & sel(Index i=0)
Definition: DBInterface.hh:50
const Selection< DataObject > & sel(Index i=0) const
Definition: DBInterface.hh:52
std::vector< std::unique_ptr< Selection< DataObject > > > m_sel
Definition: DBInterface.hh:61
Main CASM namespace.
Definition: APICommand.hh:8
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
std::unique_ptr< ImplBase > & impl
Definition: DBInterface.hh:34
CommandType::ImplBase ImplBase
Definition: DBInterface.hh:22
ConstructImpl(std::unique_ptr< ImplBase > &_impl, const CommandType &_cmd)
Definition: DBInterface.hh:26
const CommandType & cmd
Definition: DBInterface.hh:35
ImplType< DataObject > Impl
Definition: DBInterface.hh:24