CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ConfigIterator.hh
Go to the documentation of this file.
1 #ifndef ConfigIterator_HH
2 #define ConfigIterator_HH
3 
4 #include <iterator>
5 
7 
8 namespace CASM {
9 
10  template <typename ConfigType, typename PrimClexType>
12 
13  template<typename ConfigType, typename PrimClexType>
15 
21  template <typename ConfigType, typename PrimClexType>
22  class ConfigIterator : public std::iterator <std::bidirectional_iterator_tag, const ConfigType> {
23 
24  PrimClexType *m_primclex;
27  bool m_selected;
28  public:
29 
31 
32  //ConfigIterator(const ConfigIterator &iter);
33 
34  ConfigIterator(PrimClexType *primclex,
35  Index scel_index,
36  Index config_index,
37  bool _selected = false);
38 
39  //ConfigIterator &operator=(ConfigIterator iter);
40 
41  ConfigType &operator*() const;
42 
43  ConfigType *operator->() const;
44 
45  // could be const, but that seems weird
46  void set_selected(bool _select);
47 
48  bool selected() const;
49 
50  bool operator==(const ConfigIterator &iter) const;
51 
52  bool operator!=(const ConfigIterator &iter) const;
53 
55 
57 
59 
61 
62  Index config_ind() const {
63  return m_config_index;
64  }
65  Index scel_ind() const {
66  return m_scel_index;
67  }
68 
69  friend void swap<>(ConfigIterator &a, ConfigIterator &b);
70 
71  private:
72 
73  int config_list_size() const;
74  void _next_config();
75  };
76 
77 
78 
80 
81  template <typename ConfigType, typename PrimClexType>
83 
84  /*
85  template <typename ConfigType, typename PrimClexType>
86  ConfigIterator<ConfigType, PrimClexType>::ConfigIterator(const ConfigIterator<ConfigType, PrimClexType> &iter)
87  : m_primclex(iter.m_primclex), m_scel_index(iter.m_scel_index), m_config_index(iter.m_config_index) {
88  }
89  */
90 
91  template <typename ConfigType, typename PrimClexType>
93  Index scel_index,
94  Index config_index,
95  bool _selected)
96  : m_primclex(primclex), m_scel_index(scel_index), m_config_index(config_index), m_selected(_selected) {
97  }
98 
99  /*
100  template <typename ConfigType, typename PrimClexType>
101  ConfigIterator<ConfigType, PrimClexType> &ConfigIterator<ConfigType, PrimClexType>::operator=(ConfigIterator<ConfigType, PrimClexType> iter) {
102  swap(*this, iter);
103  return *this;
104  }
105  */
106 
108  template <typename ConfigType, typename PrimClexType>
110  return m_primclex->get_supercell(m_scel_index).get_config(m_config_index);
111  }
112  //template<> Configuration &ConfigIterator<Configuration, PrimClex>::operator*();
113  //template<> const Configuration &ConfigIterator<const Configuration, const PrimClex>::operator*();
114  //template<> Transition &ConfigIterator<Transition, const PrimClexType>::operator*();
115  //template<> const Transition &ConfigIterator<const Transition, const PrimClexType>::operator*();
116 
117  template <typename ConfigType, typename PrimClexType>
119  return &(operator*());
120  }
121 
122  template <typename ConfigType, typename PrimClexType>
124  return (operator*()).selected();
125  }
126 
127  template <typename ConfigType, typename PrimClexType>
129  return (m_primclex == iter.m_primclex && m_scel_index == iter.m_scel_index && m_config_index == iter.m_config_index && m_selected == iter.m_selected);
130  }
131 
132  template <typename ConfigType, typename PrimClexType>
134  return !(*this == iter);
135  }
136 
137 
138  template <typename ConfigType, typename PrimClexType>
140  m_config_index++;
141  while(m_scel_index < m_primclex->get_supercell_list().size() && m_config_index >= config_list_size()) {
142  m_scel_index++;
143  m_config_index = 0;
144  }
145  //return *this;
146  }
147 
148  template <typename ConfigType, typename PrimClexType>
150  //std::cout << "m_scel_index = " << m_scel_index << "; m_config_index = " << m_config_index << ";";
151  //if(m_scel_index < m_primclex->get_supercell_list().size() && m_config_index < config_list_size())
152  // std::cout << " selected = " << m_primclex->get_supercell(m_scel_index).get_config(m_config_index).selected();
153  //std::cout << "\n -increment-\n";
154  _next_config();
155  // don't increment past the end
156  while(m_scel_index < m_primclex->get_supercell_list().size() && (m_selected && !(m_primclex->get_supercell(m_scel_index).get_config(m_config_index).selected()))) {
157  _next_config();
158  }
159  //std::cout << "m_scel_index = " << m_scel_index << "; m_config_index = " << m_config_index << ";";
160  //if(m_scel_index < m_primclex->get_supercell_list().size() && m_config_index < config_list_size())
161  // std::cout << " selected = " << m_primclex->get_supercell(m_scel_index).get_config(m_config_index).selected();
162  //std::cout << "\n\n";
163  return *this;
164  }
165 
166  template <typename ConfigType, typename PrimClexType>
169  ++(*this);
170  return cp;
171  }
172 
173 
174  template <typename ConfigType, typename PrimClexType>
176  // Can't always dereference result if supercell[0] has no configurations, but should be okay if you compare to
177  // PrimClex::config_begin();
178  while(m_config_index == 0 && (m_scel_index > 0 || config_list_size() == 0)) {
179  m_scel_index--;
180  m_config_index = config_list_size();
181  }
182 
183  m_config_index--;
184  }
185 
186  template <typename ConfigType, typename PrimClexType>
189  --(*this);
190  return cp;
191  }
192 
193 
194  template<typename ConfigType, typename PrimClexType>
196  using std::swap;
197 
198  swap(a.m_primclex, b.m_primclex);
201  }
202 
204  //template<> int ConfigIterator<Configuration, PrimClex>::config_list_size() const;
205  //template<> int ConfigIterator<const Configuration, const PrimClex>::config_list_size() const;
206  //template<> int ConfigIterator<Transition, PrimClex>::config_list_size() const;
207  //template<> int ConfigIterator<const Transition, const PrimClex>::config_list_size() const;
208 
209 }
210 #endif
bool operator==(const ConfigIterator &iter) const
ConfigIterator()
Definitions.
int config_list_size() const
PrimClex * primclex
Definition: settings.cc:101
bool selected() const
Main CASM namespace.
Definition: complete.cpp:8
void swap(ConfigIterator< ConfigType, PrimClexType > &a, ConfigIterator< ConfigType, PrimClexType > &b)
void set_selected(bool _select)
ConfigType & operator*() const
Specialize for Configuration, const Configuration, Transition, const Transition.
PrimClexType * m_primclex
void swap(ConfigDoF &A, ConfigDoF &B)
Definition: ConfigDoF.cc:195
BasisSet operator*(const SymOp &LHS, const BasisSet &RHS)
Definition: BasisSet.cc:1154
EigenIndex Index
For long integer indexing:
ConfigIterator & operator--()
ConfigIterator & operator++()
ConfigType * operator->() const
Index scel_ind() const
Index config_ind() const
bool operator!=(const ConfigIterator &iter) const