CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
SymGroupRepID.hh
Go to the documentation of this file.
1 #ifndef SYMGROUPREPID_HH
2 #define SYMGROUPREPID_HH
3 
5 #include <iostream>
6 
7 namespace CASM {
8 
13 
19  class SymGroupRepID {
20  public:
24  SymGroupRepID(Index _group_index, Index _rep_index) :
25  m_group_index(_group_index),
26  m_rep_index(_rep_index) {
27  if(!(valid_index(_group_index) && valid_index(_rep_index))) {
28  throw std::runtime_error(std::string("SymGroupRepID initialized with out-of-bounds values!\n"));
29  }
30  }
31 
34  SymGroupRepID() : SymGroupRepID(-1, -1, true) {}
35 
39  return SymGroupRepID(-2, dim, true);
40  }
41 
44  Index group_index() const {
45  return m_group_index;
46  }
47 
50  Index rep_index() const {
51  return m_rep_index;
52  }
53 
55  bool is_identity() const {
56  return group_index() == Index(-2);
57  }
58 
60  bool empty() const {
61  return group_index() == Index(-1) || rep_index() == Index(-1);
62  }
63 
65  jsonParser const &from_json(jsonParser const &json) {
66  json.get_else(m_group_index, "group_index", Index(-1));
67  json.get_else(m_rep_index, "group_index", Index(-1));
68  return json;
69  }
70 
71  private:
73  SymGroupRepID(Index _group_index, Index _rep_index, bool override) :
74  m_group_index(_group_index),
75  m_rep_index(_rep_index) {
76 
77  }
78 
81  };
82 
84  inline
85  bool operator==(SymGroupRepID const &a, SymGroupRepID const &b) {
86  return a.group_index() == b.group_index() && a.rep_index() == b.rep_index();
87  }
88 
90  inline
91  bool operator!=(SymGroupRepID const &a, SymGroupRepID const &b) {
92  return !(a == b);
93  }
94 
96  inline
97  bool operator<(SymGroupRepID const &a, SymGroupRepID const &b) {
98  return (a.group_index() < b.group_index()) ||
99  (a.group_index() == b.group_index() && a.rep_index() < b.rep_index());
100  }
101 
102  inline
104  json["group_index"] = _id.group_index();
105  json["rep_index"] = _id.rep_index();
106  return json;
107  }
108 
109  inline
110  jsonParser const &from_json(SymGroupRepID &_id, jsonParser const &json) {
111  return _id.from_json(json);
112  }
113 
114  inline
115  std::ostream &operator<<(std::ostream &out, SymGroupRepID const &_id) {
116  out << "{group_index = " << _id.group_index() << ", rep_index = " << _id.rep_index() << "}";
117  return out;
118  }
119 
121 }
122 #endif
Index rep_index() const
Index of SymGroupRep within the master group Used internally to MasterSymGroup to access the correct ...
void from_json(ClexDescription &desc, const jsonParser &json)
Type-safe ID object for communicating and accessing Symmetry representation info. ...
bool empty() const
Returns true if SymGroupRepID has not been initialized with valid group_index or rep_index.
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
bool is_identity() const
Returns true if SymGroupRepID corresponds to an Identity representation.
bool operator<(const ClexDescription &A, const ClexDescription &B)
Compare using name strings: A.name < B.name.
SymGroupRepID(Index _group_index, Index _rep_index)
Construct from group index (i.e., MasterSymGroup::group_index()) and representation index This constr...
Main CASM namespace.
Definition: complete.cpp:8
bool operator!=(const UnitCellCoord &A, const UnitCellCoord &B)
Compare UnitCellCoord.
Index group_index() const
Index of master group in which the corresponding SymGroupRep is stored Used internally to MasterSymGr...
std::ostream & operator<<(std::ostream &_stream, const FormattedPrintable &_formatted)
bool operator==(const UnitCellCoord &A, const UnitCellCoord &B)
Compare UnitCellCoord.
EigenIndex Index
For long integer indexing:
bool get_else(T &t, const std::string &key, const T &default_value, Args...args) const
Definition: jsonParser.hh:749
SymGroupRepID(Index _group_index, Index _rep_index, bool override)
Private constructor skips bounds checks – Used for identity() and default construction.
SymGroupRepID()
Default constructor initializes group_index and rep_index as out-of-bounds SymGroupRepID::empty() ret...
jsonParser const & from_json(jsonParser const &json)
Output internal state to JSON.
static SymGroupRepID identity(Index dim)
Static function to construct an ID for identity representations.
bool valid_index(Index i)