CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
CASM::InputEnumeratorBase< ValueType, IsConst > Class Template Referenceabstract

#include <InputEnumerator.hh>

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

Detailed Description

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

Base class for implementing specialized input enumerators.

InputEnumerator allow single pass 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
    • If due to the constructor arguments there are no valid objects, then call _invalidate
  • virtual destructor
  • void increment()
    • Implementation must do work, using _set_current_ptr if necessary to point the enumerator at the object to be deferenced
    • Then if still valid call _increment_step, or if no longer valid ('end' has been reached) call _invalidate

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 CASM_TMP::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:
      • const std::string CASM_TMP::traits<MyDerivedEnumClass>::name = "MyDerivedEnumClass";
        "MyDerivedEnumClass: \n\n"
        " kwarg1: type (default=X) \n"
        " Description of kwarg1... \n\n"
        " kwarg2: type (default=X) \n"
        " Description of kwarg2... \n\n"
        " ... \n";
        int EnumInterface<MyDerivedEnumClass>::run(PrimClex &primclex, const jsonParser &kwargs) const {
        ...
        implementation to run a MyDerivedEnumClass enumerator constructed
        using the JSON input in 'kwargs' and store & save results in primclex
        ...
        return (returncode);
        }

Definition at line 11 of file InputEnumerator.hh.

Public Types

typedef InputEnumIterator
< ValueType, IsConst > 
iterator
 
typedef ValueType value_type
 
typedef CASM_TMP::ConstSwitch
< IsConst, ValueType > & 
reference
 
typedef long step_type
 

Public Member Functions

 InputEnumeratorBase ()
 
virtual ~InputEnumeratorBase ()
 
iterator begin ()
 
iterator end ()
 
reference current () const
 Access the current ObjectType by reference. More...
 
step_type step () const
 Increments with each enumerated object. More...
 
bool valid () const
 Returns false if enumeration is complete. More...
 
virtual jsonParser source (step_type step) const
 
virtual std::string name () const =0
 Derived enumerators must implement name, via ENUM_MEMBERS. More...
 

Protected Member Functions

void _initialize (value_type *_initial)
 
void _initialize ()
 
void _set_current_ptr (value_type *_new)
 Change the pointer. More...
 
value_type_current ()
 Access the current ObjectType by reference. More...
 
void _set_step (step_type val)
 Set current step value. More...
 
void _increment_step ()
 Increment current step value. More...
 
void _decrement_step ()
 Decrement current step value. More...
 
void _invalidate ()
 Call if enumeration complete. More...
 
void _validate ()
 Used if random access enumerator step is moved into valid range. More...
 

Private Member Functions

virtual void increment ()=0
 

Private Attributes

friend InputEnumIteratorBase< ValueType, IsConst >
 

Member Typedef Documentation

template<typename ValueType, bool IsConst = true>
typedef InputEnumIterator<ValueType, IsConst> CASM::InputEnumeratorBase< ValueType, IsConst >::iterator

Definition at line 231 of file InputEnumerator.hh.

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

Definition at line 192 of file Enumerator.hh.

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

Definition at line 103 of file Enumerator.hh.

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

Definition at line 191 of file Enumerator.hh.

Constructor & Destructor Documentation

template<typename ValueType, bool IsConst = true>
CASM::InputEnumeratorBase< ValueType, IsConst >::InputEnumeratorBase ( )
inline

Definition at line 234 of file InputEnumerator.hh.

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

Definition at line 236 of file InputEnumerator.hh.

Member Function Documentation

template<typename ValueType, bool IsConst = true>
value_type& CASM::ValEnumerator< ValueType, IsConst >::_current ( )
inlineprotectedinherited

Access the current ObjectType by reference.

Definition at line 244 of file Enumerator.hh.

void CASM::EnumeratorBase::_decrement_step ( )
inlineprotectedinherited

Decrement current step value.

Definition at line 164 of file Enumerator.hh.

void CASM::EnumeratorBase::_increment_step ( )
inlineprotectedinherited

Increment current step value.

Definition at line 159 of file Enumerator.hh.

void CASM::EnumeratorBase::_initialize ( )
inlineprotectedinherited

Initialize

  • Sets step to 0
  • Sets valid to true

Definition at line 148 of file Enumerator.hh.

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

Initialize

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

Definition at line 216 of file Enumerator.hh.

void CASM::EnumeratorBase::_invalidate ( )
inlineprotectedinherited

Call if enumeration complete.

Definition at line 169 of file Enumerator.hh.

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

Change the pointer.

Definition at line 239 of file Enumerator.hh.

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

Set current step value.

Definition at line 154 of file Enumerator.hh.

void CASM::EnumeratorBase::_validate ( )
inlineprotectedinherited

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

Definition at line 174 of file Enumerator.hh.

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

Definition at line 245 of file InputEnumerator.hh.

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

Access the current ObjectType by reference.

Definition at line 232 of file Enumerator.hh.

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

Definition at line 249 of file InputEnumerator.hh.

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

Default Object source just uses step#

Returns:

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

Definition at line 131 of file Enumerator.hh.

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

Increments with each enumerated object.

Definition at line 113 of file Enumerator.hh.

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

Returns false if enumeration is complete.

Definition at line 118 of file Enumerator.hh.

Member Data Documentation

template<typename ValueType, bool IsConst = true>
friend CASM::InputEnumeratorBase< ValueType, IsConst >::InputEnumIteratorBase< ValueType, IsConst >
private

Definition at line 224 of file InputEnumerator.hh.


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