CASM  1.1.0
A Clusters Approach to Statistical Mechanics
FunctionVisitor.hh
Go to the documentation of this file.
1 #ifndef FUNCTIONVISITOR_HH
2 #define FUNCTIONVISITOR_HH
3 
4 #include <iostream>
5 #include <map>
6 #include <sstream>
7 #include <vector>
8 
10 
11 namespace CASM {
12 class BasisSet;
13 
14 class Function;
15 class Variable;
16 class PolynomialFunction;
17 class OccupantFunction;
18 
19 template <typename T>
20 class Array;
21 
22 namespace FunctionLabel_impl {
23 std::pair<bool, std::string> make_label(Function const &host,
24  BasisSet const *bset_ptr);
25 }
26 
35  public:
36  virtual ~FunctionVisitor() {}
37 
38  virtual std::string type_name() const = 0;
39 
40  virtual bool visit(Variable const &host, BasisSet const *bset_ptr) const;
41 
42  virtual bool visit(Variable &host, BasisSet const *bset_ptr) const;
43 
44  virtual bool visit(OccupantFunction const &host,
45  BasisSet const *bset_ptr) const;
46 
47  virtual bool visit(OccupantFunction &host, BasisSet const *bset_ptr) const;
48 
49  virtual bool visit(PolynomialFunction const &host,
50  BasisSet const *bset_ptr) const;
51 
52  virtual bool visit(PolynomialFunction &host, BasisSet const *bset_ptr) const;
53 
54  private:
55  virtual bool _generic_visit(Function &host, BasisSet const *bset_ptr) const;
56 
57  virtual bool _generic_visit(Function const &host,
58  BasisSet const *bset_ptr) const;
59 
60  virtual bool _visit(const Array<Function *> &host_list,
61  BasisSet const *bset_ptr) const {
62  return false;
63  }
64 };
65 
66 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75 
77  std::vector<std::string> m_sub_strings;
78 
79  public:
80  OccFuncLabeler(const std::string &_template);
81 
82  std::string type_name() const { return "OccFuncLabeler"; }
83 
84  bool visit(OccupantFunction &host, BasisSet const *bset_ptr) const;
85 };
86 
87 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88 
91 
92  public:
93  OccFuncBasisIndexer(int _new_index) : m_new_index(_new_index) {}
94 
95  std::string type_name() const { return "OccFuncBasisIndexer"; }
96 
97  bool visit(OccupantFunction &host, BasisSet const *bset_ptr) const;
98 };
99 
100 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103  public:
104  OccFuncEvaluator(int state) : m_state(state) {}
105 
106  double value() { return m_value; }
107 
108  std::string type_name() const { return "OccFuncEvaluator"; }
109 
110  bool visit(OccupantFunction &host, BasisSet const *bset_ptr) const;
111 
112  bool visit(OccupantFunction const &host, BasisSet const *bset_ptr) const;
113 
114  private:
115  bool _generic_visit(Function const &host, BasisSet const *bset_ptr) const {
116  throw std::runtime_error(
117  "OccFuncEvaluator can only be applied to OccupantFunction!");
118  return false;
119  }
120 
121  int m_state;
122  mutable double m_value;
123 };
124 
125 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136 
138  public:
139  VariableLabeler(std::string const &m_type_name, std::string const &_template);
140 
141  std::string type_name() const { return "VariableLabeler"; }
142 
143  bool visit(Variable &host, BasisSet const *bset_ptr) const;
144 
145  private:
146  std::string m_type_name;
147  std::vector<std::string> m_sub_strings;
148 };
149 
150 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152  public:
153  SubExpressionLabeler(const std::string &_bset_name,
154  const std::string &_template);
155 
157 
158  std::string type_name() const { return "SubExpressionLabeler"; }
159 
160  private:
161  bool _generic_visit(Function &host, BasisSet const *bset_ptr) const;
162 
163  bool _generic_visit(Function const &host, BasisSet const *bset_ptr) const {
164  throw std::runtime_error(
165  "Application of a SubExpressionLabeler to a const Function is not "
166  "allowed!!\n");
167  }
168 
169  std::string m_bset_name;
170  std::vector<std::string> m_sub_strings;
171 };
172 
173 } // namespace CASM
174 #endif
virtual bool _visit(const Array< Function * > &host_list, BasisSet const *bset_ptr) const
virtual bool visit(Variable const &host, BasisSet const *bset_ptr) const
virtual bool _generic_visit(Function &host, BasisSet const *bset_ptr) const
virtual std::string type_name() const =0
OccFuncBasisIndexer(int _new_index)
bool visit(OccupantFunction &host, BasisSet const *bset_ptr) const
std::string type_name() const
bool _generic_visit(Function const &host, BasisSet const *bset_ptr) const
bool visit(OccupantFunction &host, BasisSet const *bset_ptr) const
std::string type_name() const
std::string type_name() const
OccFuncLabeler(const std::string &_template)
std::vector< std::string > m_sub_strings
bool visit(OccupantFunction &host, BasisSet const *bset_ptr) const
SubExpressionLabeler(const std::string &_bset_name, const std::string &_template)
bool _generic_visit(Function const &host, BasisSet const *bset_ptr) const
SubExpressionLabeler(SubExpressionLabeler const &)=default
std::string type_name() const
std::vector< std::string > m_sub_strings
bool _generic_visit(Function &host, BasisSet const *bset_ptr) const
VariableLabeler(std::string const &m_type_name, std::string const &_template)
std::vector< std::string > m_sub_strings
bool visit(Variable &host, BasisSet const *bset_ptr) const
std::string type_name() const
std::pair< bool, std::string > make_label(Function const &host, BasisSet const *bset_ptr)
Main CASM namespace.
Definition: APICommand.hh:8