CASM  1.1.0
A Clusters Approach to Statistical Mechanics
InputEnumerator.hh
Go to the documentation of this file.
1 #ifndef CASM_InputEnumerator
2 #define CASM_InputEnumerator
3 
4 #include <string>
5 
7 
8 namespace CASM {
9 
10 template <typename ValueType, bool IsConst>
11 class InputEnumeratorBase;
12 
13 template <typename ValueType, bool IsConst>
14 class InputEnumIterator;
15 
16 template <typename ValueType, bool IsConst = true>
17 class InputEnumIteratorBase : public ValEnumIterator<ValueType, IsConst> {
19 
20  public:
24 
26 
28  bool is_end)
29  : ValEnumIterator<ValueType, IsConst>(enumerator),
31 
34 
38  virtual step_type step() const override {
39  this->_assert_ptr();
40  return _enum().step();
41  }
42 
51  virtual bool is_end() const override {
52  this->_assert_ptr();
53  return _constructed_as_end() || !this->_enum().valid();
54  }
55 
56  std::unique_ptr<InputEnumIteratorBase> clone() const {
57  return std::unique_ptr<InputEnumIteratorBase>(this->_clone());
58  }
59 
60  protected:
62 
63  bool _constructed_as_end() const { return m_constructed_as_end; }
64 
65  private:
68  }
69 
71  virtual reference dereference() const override { return _enum().current(); }
72 
74  virtual void increment() { _enum().increment(); }
75 
78  return static_cast<InputEnumeratorBase<ValueType, IsConst> &>(*_enum_ptr());
79  }
80 
83  return static_cast<InputEnumeratorBase<ValueType, IsConst> &>(*_enum_ptr());
84  }
85 
87 };
88 
89 template <typename ValueType, bool IsConst = true>
91 
92  public boost::iterator_facade<InputEnumIterator<ValueType, IsConst>,
93  ValueType, std::input_iterator_tag,
94  CASM_TMP::ConstSwitch<IsConst, ValueType> &,
95  long> {
96  public:
97  typedef
99  typedef ValueType value_type;
100  typedef
102 
105 
108  : m_ptr(notstd::clone(it)) {}
109 
110  step_type step() const { return m_ptr->step(); }
111 
112  jsonParser source() const { return m_ptr->source(); }
113 
114  std::string name() const { return m_ptr->name(); }
115 
116  private:
117  friend boost::iterator_core_access;
118 
120  void increment() { m_ptr->increment(); }
121 
123  reference dereference() const { return m_ptr->dereference(); }
124 
126  bool equal(const InputEnumIterator &B) const {
127  return m_ptr->equal(*(B.m_ptr));
128  }
129 
131 };
132 
196 template <typename ValueType, bool IsConst = true>
197 class InputEnumeratorBase : public ValEnumerator<ValueType, IsConst> {
199 
200  public:
205 
207 
208  virtual ~InputEnumeratorBase() {}
209 
213  using ValEnumerator<ValueType, IsConst>::name; // pure virtual
215 
217  return InputEnumIteratorBase<ValueType, IsConst>(*this, false);
218  }
219 
221  return InputEnumIteratorBase<ValueType, IsConst>(*this, true);
222  }
223 
224  protected:
230 
231  private:
232  // using ValEnumerator<ValueType, IsConst>::_decrement_step; // hide
233  virtual void increment() = 0;
234 };
235 
241 template <typename ValueType, bool IsConst = true>
243  public:
245  typedef
249 
251 
253  : ptr(notstd::clone(e)) {}
254 
255  InputEnumerator(const InputEnumerator &) = delete;
257 
259  step_type step() const { return ptr->step(); }
260 
262  bool valid() const { return ptr->valid(); }
263 
264  jsonParser source(step_type step) const { return ptr->source(step); }
265 
267  std::string name() const { return ptr->name(); }
268 
270  reference current() const { return ptr->current(); }
271 
272  iterator begin() { return ptr->begin(); }
273 
274  iterator end() { return ptr->end(); }
275 
276  std::unique_ptr<InputEnumeratorBase<ValueType, IsConst> > ptr;
277 };
278 
279 } // namespace CASM
280 
281 #endif
EnumeratorBase::step_type step_type
Definition: Enumerator.hh:225
std::string name() const
Uses enumerator class 'name' implementation.
Definition: Enumerator.hh:246
jsonParser source() const
Definition: Enumerator.hh:243
InputEnumeratorBase< ValueType, IsConst > & _enum()
static_cast enumerator pointer to InputEnumeratorBase&
InputEnumeratorBase< ValueType, IsConst > & _enum() const
static_cast enumerator pointer to InputEnumeratorBase&
virtual void increment()
boost::iterator_facade implementation
virtual step_type step() const override
virtual reference dereference() const override
boost::iterator_facade implementation
virtual InputEnumIteratorBase< ValueType, IsConst > * _clone() const override
InputEnumIteratorBase(InputEnumeratorBase< ValueType, IsConst > &enumerator, bool is_end)
std::unique_ptr< InputEnumIteratorBase > clone() const
virtual bool is_end() const override
InputEnumIteratorBase< ValueType, IsConst >::reference reference
std::string name() const
reference dereference() const
boost::iterator_facade implementation
jsonParser source() const
bool equal(const InputEnumIterator &B) const
boost::iterator_facade implementation
InputEnumIterator(const InputEnumIteratorBase< ValueType, IsConst > &it)
Construct iterator.
InputEnumIterator()
Default constructor.
InputEnumIteratorBase< ValueType, IsConst >::step_type step_type
void increment()
boost::iterator_facade implementation
notstd::cloneable_ptr< InputEnumIteratorBase< ValueType, IsConst > > m_ptr
step_type step() const
Base class for implementing specialized input enumerators.
virtual void increment()=0
InputEnumIterator< ValueType, IsConst > iterator
friend InputEnumIteratorBase< ValueType, IsConst >
Generic input enumerator.
std::unique_ptr< InputEnumeratorBase< ValueType, IsConst > > ptr
step_type step() const
Increments with each enumerated object.
InputEnumerator(const InputEnumerator &)=delete
bool valid() const
Returns false if enumeration is complete.
InputEnumerator(std::unique_ptr< InputEnumeratorBase< ValueType, IsConst > > e)
InputEnumeratorBase< ValueType, IsConst >::value_type value_type
InputEnumerator & operator=(const InputEnumerator &)=delete
InputEnumeratorBase< ValueType, IsConst >::step_type step_type
InputEnumeratorBase< ValueType, IsConst >::reference reference
std::string name() const
Derived enumerators must implement name.
InputEnumeratorBase< ValueType, IsConst >::iterator iterator
jsonParser source(step_type step) const
reference current() const
Access the current ObjectType by reference.
EnumeratorBase::step_type step_type
Definition: Enumerator.hh:225
ValEnumerator< ValueType, IsConst >::reference reference
Definition: Enumerator.hh:310
ValueType value_type
Definition: Enumerator.hh:173
CASM_TMP::ConstSwitch< IsConst, ValueType > & reference
Definition: Enumerator.hh:174
A 'cloneable_ptr' can be used in place of 'unique_ptr'.
Main CASM namespace.
Definition: APICommand.hh:8
Non-std smart pointer classes and functions.
std::unique_ptr< T > clone(const T &obj)