CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CASM::RandomAccessEnumeratorBase< ValueType, IsConst > Class Template Referenceabstract

#include <RandomAccessEnumerator.hh>

+ Inheritance diagram for CASM::RandomAccessEnumeratorBase< ValueType, IsConst >:

Detailed Description

template<typename ValueType, bool IsConst = true>
class CASM::RandomAccessEnumeratorBase< ValueType, IsConst >

Base class for implementing specialized random access enumerators.

InputEnumerator allow random access iteration over some objects of ValueType. The specialized class should document any guaranteed properties of the enumerated objects. For instance, some enumerators may guarantee that objects will be unique, others may not. Some may guarantee objects will be primitive or in canonical form, others may not. Etc.

Derived classes (ex. MyDerivedEnumClass) must implement:

  • constructors
    • Must call _initialize or _set_current_ptr to set pointer to first valid object
    • Ensure that the current step value = 0, via _initialize or _set_step
    • Ensure that the size of the enumerator is set, via _set_size
    • If due to the constructor arguments there are no valid objects, then call _invalidate
  • virtual destructor
  • void goto_step(step_type n)
    • Should do work to determine the 'n'-th object and then call goto_step(step_type n, value_type* ptr) setting a pointer to that object
    • If 'n' equals the current step, can immediately return

Derived classes should contain ENUMERATOR_MEMBERS(MyDerivedClass) in the class definition to automatically implement:

  • name

In CASM namespace near the derived class definition, include:

  • For enumerators only meant to be used internally:
    • In header:
      • ENUMERATOR_TRAITS(MyDerivedEnumClass)
    • In the source code file:
      • const std::string traits<MyDerivedEnumClass>::name = "MyDerivedEnumClass";
  • For enumerators only meant to be added to the API:
    • In header:
      • ENUMERATOR_INTERFACE_TRAITS(MyDerivedClass)
    • In the source code file:

Definition at line 251 of file RandomAccessEnumerator.hh.

Public Types

typedef RandomAccessEnumIterator< ValueType, IsConst > iterator
 
typedef std::reverse_iterator< iteratorreverse_iterator
 
typedef step_type size_type
 
typedef ValueType value_type
 
typedef CASM_TMP::ConstSwitch< IsConst, ValueType > & reference
 
typedef long step_type
 

Public Member Functions

 RandomAccessEnumeratorBase (size_type size=0)
 
virtual ~RandomAccessEnumeratorBase ()
 
iterator begin ()
 
iterator end ()
 
reverse_iterator rbegin ()
 
reverse_iterator rend ()
 
size_type size () const
 Number of elements in enumerator. More...
 
reference front ()
 Reference to first element in enumerator. More...
 
reference back ()
 Reference to last element in enumerator. More...
 
reference initial ()
 Reference to first element in enumerator. More...
 
reference final ()
 Reference to last element in enumerator. More...
 
reference operator[] (size_type n)
 Reference an element in enumerator. More...
 
reference current () const
 Access the current ObjectType by reference. More...
 
virtual std::string name () const=0
 Derived enumerators must implement name, via ENUM_MEMBERS. More...
 
virtual std::string name () const =0
 Derived enumerators must implement name, via ENUM_MEMBERS. More...
 
virtual jsonParser source (step_type step) const
 
virtual jsonParser source (step_type step) const
 
step_type step () const
 Increments with each enumerated object. More...
 
step_type step () const
 Increments with each enumerated object. More...
 
bool valid () const
 Returns false if enumeration is complete. More...
 
bool valid () const
 Returns false if enumeration is complete. More...
 

Protected Member Functions

void _set_size (size_type val)
 Set size value. More...
 
void _initialize (CASM_TMP::ConstSwitch< IsConst, value_type > *_initial)
 
void _initialize ()
 
void _set_current_ptr (CASM_TMP::ConstSwitch< IsConst, value_type > *_new)
 Change the pointer. More...
 
void _decrement_step ()
 Decrement current step value. More...
 
void _increment_step ()
 Increment current step value. More...
 
void _invalidate ()
 Call if enumeration complete. More...
 
void _set_step (step_type val)
 Set current step value. More...
 
void _set_step (step_type val)
 Set current step value. More...
 
void _validate ()
 Used if random access enumerator step is moved into valid range. More...
 

Private Member Functions

virtual CASM_TMP::ConstSwitch< IsConst, value_type > * at_step (step_type n)=0
 
void goto_step (step_type n)
 
void increment () override
 

Private Attributes

friend RandomAccessEnumIteratorBase< ValueType, IsConst >
 
size_type m_size
 
friend InputEnumIteratorBase< ValueType, IsConst >
 
CASM_TMP::ConstSwitch< IsConst, value_type > * m_current_ptr
 
bool m_valid
 
step_type m_step
 

Member Typedef Documentation

◆ iterator

template<typename ValueType , bool IsConst = true>
typedef RandomAccessEnumIterator<ValueType, IsConst> CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::iterator

Definition at line 259 of file RandomAccessEnumerator.hh.

◆ reference

template<typename ValueType , bool IsConst = true>
typedef CASM_TMP::ConstSwitch<IsConst, ValueType>& CASM::ValEnumerator< ValueType, IsConst >::reference
inherited

Definition at line 174 of file Enumerator.hh.

◆ reverse_iterator

template<typename ValueType , bool IsConst = true>
typedef std::reverse_iterator<iterator> CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::reverse_iterator

Definition at line 260 of file RandomAccessEnumerator.hh.

◆ size_type

template<typename ValueType , bool IsConst = true>
typedef step_type CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::size_type

Definition at line 261 of file RandomAccessEnumerator.hh.

◆ step_type

template<typename ValueType , bool IsConst = true>
typedef long CASM::EnumeratorBase::step_type
inherited

Definition at line 107 of file Enumerator.hh.

◆ value_type

template<typename ValueType , bool IsConst = true>
typedef ValueType CASM::ValEnumerator< ValueType, IsConst >::value_type
inherited

Definition at line 173 of file Enumerator.hh.

Constructor & Destructor Documentation

◆ RandomAccessEnumeratorBase()

template<typename ValueType , bool IsConst = true>
CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::RandomAccessEnumeratorBase ( size_type  size = 0)
inline

Definition at line 263 of file RandomAccessEnumerator.hh.

◆ ~RandomAccessEnumeratorBase()

template<typename ValueType , bool IsConst = true>
virtual CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::~RandomAccessEnumeratorBase ( )
inlinevirtual

Definition at line 266 of file RandomAccessEnumerator.hh.

Member Function Documentation

◆ _decrement_step()

template<typename ValueType , bool IsConst = true>
void CASM::EnumeratorBase::_decrement_step
inlineprotectedinherited

Decrement current step value.

Definition at line 156 of file Enumerator.hh.

◆ _increment_step()

template<typename ValueType , bool IsConst = true>
void CASM::EnumeratorBase::_increment_step
inlineprotectedinherited

Increment current step value.

Definition at line 153 of file Enumerator.hh.

◆ _initialize() [1/2]

template<typename ValueType , bool IsConst = true>
void CASM::EnumeratorBase::_initialize
inlineprotectedinherited

Initialize

  • Sets step to 0
  • Sets valid to true

Definition at line 144 of file Enumerator.hh.

◆ _initialize() [2/2]

template<typename ValueType , bool IsConst = true>
void CASM::ValEnumerator< ValueType, IsConst >::_initialize ( CASM_TMP::ConstSwitch< IsConst, value_type > *  _initial)
inlineprotectedinherited

Initialize

  • Sets current to point at _initial
  • Sets step to 0
  • Sets valid to true

Definition at line 197 of file Enumerator.hh.

◆ _invalidate()

template<typename ValueType , bool IsConst = true>
void CASM::EnumeratorBase::_invalidate
inlineprotectedinherited

Call if enumeration complete.

Definition at line 159 of file Enumerator.hh.

◆ _set_current_ptr()

template<typename ValueType , bool IsConst = true>
void CASM::ValEnumerator< ValueType, IsConst >::_set_current_ptr ( CASM_TMP::ConstSwitch< IsConst, value_type > *  _new)
inlineprotectedinherited

Change the pointer.

Definition at line 215 of file Enumerator.hh.

◆ _set_size()

template<typename ValueType , bool IsConst = true>
void CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::_set_size ( size_type  val)
inlineprotected

Set size value.

Definition at line 322 of file RandomAccessEnumerator.hh.

◆ _set_step() [1/2]

void CASM::EnumeratorBase::_set_step ( step_type  val)
inlineprotectedinherited

Set current step value.

Definition at line 150 of file Enumerator.hh.

◆ _set_step() [2/2]

template<typename ValueType , bool IsConst = true>
void CASM::EnumeratorBase::_set_step
inlineprotectedinherited

Set current step value.

Definition at line 150 of file Enumerator.hh.

◆ _validate()

void CASM::EnumeratorBase::_validate ( )
inlineprotectedinherited

Used if random access enumerator step is moved into valid range.

Definition at line 162 of file Enumerator.hh.

◆ at_step()

template<typename ValueType , bool IsConst = true>
virtual CASM_TMP::ConstSwitch<IsConst, value_type>* CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::at_step ( step_type  n)
privatepure virtual

Must be implemented in derived enumerator

  • Should return a pointer to the object 'at' step n
  • May be implemented by returning pointers to different objects, or by modifying the object being pointed at and returning the same pointer

◆ back()

template<typename ValueType , bool IsConst = true>
reference CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::back ( )
inline

Reference to last element in enumerator.

Definition at line 296 of file RandomAccessEnumerator.hh.

◆ begin()

template<typename ValueType , bool IsConst = true>
iterator CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::begin ( )
inline

Definition at line 274 of file RandomAccessEnumerator.hh.

◆ current()

template<typename ValueType , bool IsConst = true>
reference CASM::ValEnumerator< ValueType, IsConst >::current ( ) const
inlineinherited

Access the current ObjectType by reference.

Definition at line 211 of file Enumerator.hh.

◆ end()

template<typename ValueType , bool IsConst = true>
iterator CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::end ( )
inline

Definition at line 278 of file RandomAccessEnumerator.hh.

◆ final()

template<typename ValueType , bool IsConst = true>
reference CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::final ( )
inline

Reference to last element in enumerator.

Definition at line 305 of file RandomAccessEnumerator.hh.

◆ front()

template<typename ValueType , bool IsConst = true>
reference CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::front ( )
inline

Reference to first element in enumerator.

Definition at line 290 of file RandomAccessEnumerator.hh.

◆ goto_step()

template<typename ValueType , bool IsConst = true>
void CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::goto_step ( step_type  n)
inlineprivate

Sets step, current pointer via call to 'at_step', and enumerator validity

  • If n in valid range, calls at_step to set the current object and sets the enumerator state to valid
  • If n not in valid range, will set enumerator state to not valid

Definition at line 336 of file RandomAccessEnumerator.hh.

◆ increment()

template<typename ValueType , bool IsConst = true>
void CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::increment ( )
inlineoverrideprivatevirtual

Pure virtual function inherited from InputEnumeratorBase, needed when incrementing from InputEnumeratorBase*

Implements CASM::InputEnumeratorBase< ValueType, true >.

Definition at line 351 of file RandomAccessEnumerator.hh.

◆ initial()

template<typename ValueType , bool IsConst = true>
reference CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::initial ( )
inline

Reference to first element in enumerator.

Definition at line 302 of file RandomAccessEnumerator.hh.

◆ name() [1/2]

virtual std::string CASM::EnumeratorBase::name ( ) const
pure virtualinherited

◆ name() [2/2]

template<typename ValueType , bool IsConst = true>
virtual std::string CASM::EnumeratorBase::name
inherited

Derived enumerators must implement name, via ENUM_MEMBERS.

◆ operator[]()

template<typename ValueType , bool IsConst = true>
reference CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::operator[] ( size_type  n)
inline

Reference an element in enumerator.

Definition at line 308 of file RandomAccessEnumerator.hh.

◆ rbegin()

template<typename ValueType , bool IsConst = true>
reverse_iterator CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::rbegin ( )
inline

Definition at line 282 of file RandomAccessEnumerator.hh.

◆ rend()

template<typename ValueType , bool IsConst = true>
reverse_iterator CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::rend ( )
inline

Definition at line 284 of file RandomAccessEnumerator.hh.

◆ size()

template<typename ValueType , bool IsConst = true>
size_type CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::size ( ) const
inline

Number of elements in enumerator.

Definition at line 287 of file RandomAccessEnumerator.hh.

◆ source() [1/2]

virtual jsonParser CASM::EnumeratorBase::source ( step_type  step) const
inlinevirtualinherited

Default Object source just uses step#

Returns:

{
"enumerated_by": "<enumerator_type>",
"step": <step #>
}
step_type step() const
Increments with each enumerated object.
Definition: Enumerator.hh:115

Definition at line 129 of file Enumerator.hh.

◆ source() [2/2]

template<typename ValueType , bool IsConst = true>
virtual jsonParser CASM::EnumeratorBase::source
inlineinherited

Default Object source just uses step#

Returns:

{
"enumerated_by": "<enumerator_type>",
"step": <step #>
}

Definition at line 129 of file Enumerator.hh.

◆ step() [1/2]

step_type CASM::EnumeratorBase::step ( ) const
inlineinherited

Increments with each enumerated object.

Definition at line 115 of file Enumerator.hh.

◆ step() [2/2]

template<typename ValueType , bool IsConst = true>
step_type CASM::EnumeratorBase::step
inlineinherited

Increments with each enumerated object.

Definition at line 115 of file Enumerator.hh.

◆ valid() [1/2]

bool CASM::EnumeratorBase::valid ( ) const
inlineinherited

Returns false if enumeration is complete.

Definition at line 118 of file Enumerator.hh.

◆ valid() [2/2]

template<typename ValueType , bool IsConst = true>
bool CASM::EnumeratorBase::valid
inlineinherited

Returns false if enumeration is complete.

Definition at line 118 of file Enumerator.hh.

Member Data Documentation

◆ InputEnumIteratorBase< ValueType, IsConst >

friend CASM::InputEnumeratorBase< ValueType, IsConst >::InputEnumIteratorBase< ValueType, IsConst >
privateinherited

Definition at line 198 of file InputEnumerator.hh.

◆ m_current_ptr

template<typename ValueType , bool IsConst = true>
CASM_TMP::ConstSwitch<IsConst, value_type>* CASM::ValEnumerator< ValueType, IsConst >::m_current_ptr
privateinherited

Definition at line 220 of file Enumerator.hh.

◆ m_size

template<typename ValueType , bool IsConst = true>
size_type CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::m_size
private

Definition at line 353 of file RandomAccessEnumerator.hh.

◆ m_step

step_type CASM::EnumeratorBase::m_step
privateinherited

Definition at line 167 of file Enumerator.hh.

◆ m_valid

bool CASM::EnumeratorBase::m_valid
privateinherited

Definition at line 165 of file Enumerator.hh.

◆ RandomAccessEnumIteratorBase< ValueType, IsConst >

template<typename ValueType , bool IsConst = true>
friend CASM::RandomAccessEnumeratorBase< ValueType, IsConst >::RandomAccessEnumIteratorBase< ValueType, IsConst >
private

Definition at line 253 of file RandomAccessEnumerator.hh.


The documentation for this class was generated from the following file: