CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
CASM::BaseCounter< DerivedCounter > Class Template Reference

#include <BaseCounter.hh>

Detailed Description

template<typename DerivedCounter>
class CASM::BaseCounter< DerivedCounter >

A Counter allows looping over many incrementing variables in one loop.

Template Parameters
ContainerThe type of container containing the variables begin looped over. Container should be fully specified, so 'std::vector<int>', not 'std::vector'.
value_typeThe type of variable contained by the Container. Must have valid operators '+=' and '+'.
size_typeThe type of the index into the Container.
AccessA Functor or function with signature 'value_type& Access::operator()(Container &, size_type);', which provides a reference to a element of the Container.

Default container access using the CASM_TMP::BracketAccess functor is identical to 'container[index]'. Parentheses access, like 'container(index)', can be obtained by setting the Access parameter using the CASM_TMP::ParenthesesAccess functor.

Default value_type comparison is as 'value_type < value_type'. Custom comparison can be provided using the Compare functor.

Several typedefs are provided:

The first element of the container is the inner loop, and the last element of the container is the outer loop.

Example:

int size = 3;
std::vector<int> initial(size, 0);
std::vector<int> final(size, 1);
std::vector<int> increment(size, 1);
casm::Counter<std::vector<int> > counter(initial, final, increment);
do {
for( int i=0; i<counter.size(); i++) {
std::cout << counter()[i] << " ";
}
std::cout << std::endl;
} while(counter++);

Output:

0 0 0
1 0 0
0 1 0
1 1 0
0 0 1
1 0 1
0 1 1
1 1 1

Definition at line 114 of file BaseCounter.hh.

Public Types

typedef CASM_TMP::traits
< DerivedCounter >::Container 
Container
 
typedef CASM_TMP::traits
< DerivedCounter >::value_type 
value_type
 
typedef CASM_TMP::traits
< DerivedCounter >::size_type 
size_type
 
typedef CASM_TMP::traits
< DerivedCounter >::Access 
Access
 
typedef CASM_TMP::traits
< DerivedCounter >::Compare 
Compare
 
typedef CounterValueIterator
< DerivedCounter > 
const_value_iterator
 

Public Member Functions

 BaseCounter ()
 Default construct a Counter. More...
 
 BaseCounter (const Container &_initial, const Container &_final, const Container &_increment, Access _access=Access(), Compare _compare=Compare())
 Construct a Counter-type object. More...
 
bool valid () const
 
 operator bool () const
 
 operator const Container & () const
 
const value_typeoperator[] (size_type index) const
 
size_type size () const
 
const_value_iterator value_begin () const
 
const_value_iterator value_end () const
 
bool compare (const value_type &A, const value_type &B)
 
const Containercurrent () const
 
const value_typecurrent (size_type index) const
 
const Containeroperator() () const
 
const Containerinitial () const
 
const Containerfinal () const
 
const Containerincrement () const
 

Protected Member Functions

bool & _valid ()
 non-const reference bool validity flag More...
 
const value_type_current (size_type index) const
 
value_type_current (size_type index)
 
Container_current ()
 
const value_type_initial (size_type index) const
 
value_type_initial (size_type index)
 
const value_type_final (size_type index) const
 
value_type_final (size_type index)
 
const value_type_increment (size_type index) const
 
value_type_increment (size_type index)
 
const value_type_upper (size_type index) const
 
value_type_upper (size_type index)
 
const value_type_lower (size_type index) const
 
value_type_lower (size_type index)
 

Private Attributes

Access m_access
 A functor that enables different ways of accessing the container, by default: container[index]. More...
 
Compare m_compare
 A functor that enables custom comparison, by default: operator<. More...
 
Container m_initial
 Initial container values. More...
 
Container m_final
 Final container values. More...
 
Container m_increment
 Amount to increment each container value. More...
 
Container m_lower
 The minimum of each value of m_initial and m_final. More...
 
Container m_upper
 The maximum of each value of m_initial and m_final. More...
 
Container m_current
 The current state of the container. More...
 
bool m_valid
 

Member Typedef Documentation

template<typename DerivedCounter>
typedef CASM_TMP::traits<DerivedCounter>::Access CASM::BaseCounter< DerivedCounter >::Access

Definition at line 120 of file BaseCounter.hh.

template<typename DerivedCounter>
typedef CASM_TMP::traits<DerivedCounter>::Compare CASM::BaseCounter< DerivedCounter >::Compare

Definition at line 121 of file BaseCounter.hh.

template<typename DerivedCounter>
typedef CounterValueIterator<DerivedCounter> CASM::BaseCounter< DerivedCounter >::const_value_iterator

Definition at line 122 of file BaseCounter.hh.

template<typename DerivedCounter>
typedef CASM_TMP::traits<DerivedCounter>::Container CASM::BaseCounter< DerivedCounter >::Container

Definition at line 117 of file BaseCounter.hh.

template<typename DerivedCounter>
typedef CASM_TMP::traits<DerivedCounter>::size_type CASM::BaseCounter< DerivedCounter >::size_type

Definition at line 119 of file BaseCounter.hh.

template<typename DerivedCounter>
typedef CASM_TMP::traits<DerivedCounter>::value_type CASM::BaseCounter< DerivedCounter >::value_type

Definition at line 118 of file BaseCounter.hh.

Constructor & Destructor Documentation

template<typename DerivedCounter>
CASM::BaseCounter< DerivedCounter >::BaseCounter ( )
inline

Default construct a Counter.

Definition at line 125 of file BaseCounter.hh.

template<typename DerivedCounter>
CASM::BaseCounter< DerivedCounter >::BaseCounter ( const Container _initial,
const Container _final,
const Container _increment,
Access  _access = Access(),
Compare  _compare = Compare() 
)
inline

Construct a Counter-type object.

Parameters
_initialthe initial Container values
_finalthe final valid Container values
_incrementthe amount to increment each Container value by

Definition at line 133 of file BaseCounter.hh.

Member Function Documentation

template<typename DerivedCounter>
const value_type& CASM::BaseCounter< DerivedCounter >::_current ( size_type  index) const
inlineprotected

const Access to element in the current value of the Container

Returns
a const reference to the element 'index' in the current value of the Container

Definition at line 250 of file BaseCounter.hh.

template<typename DerivedCounter>
value_type& CASM::BaseCounter< DerivedCounter >::_current ( size_type  index)
inlineprotected

non-const Access to element in the current value of the Container

Returns
a non-const reference to the element 'index' in the current value of the Container

Definition at line 258 of file BaseCounter.hh.

template<typename DerivedCounter>
Container& CASM::BaseCounter< DerivedCounter >::_current ( )
inlineprotected

non-const Access the current value of the Container

Returns
a non-const reference to the current value of the Container

Definition at line 267 of file BaseCounter.hh.

template<typename DerivedCounter>
const value_type& CASM::BaseCounter< DerivedCounter >::_final ( size_type  index) const
inlineprotected

const Access to element in the final value of the Container

Returns
a const reference to the element 'index' in the final value of the Container

Definition at line 291 of file BaseCounter.hh.

template<typename DerivedCounter>
value_type& CASM::BaseCounter< DerivedCounter >::_final ( size_type  index)
inlineprotected

non-const Access to element in the final value of the Container

Returns
a non-const reference to the element 'index' in the final value of the Container

Definition at line 299 of file BaseCounter.hh.

template<typename DerivedCounter>
const value_type& CASM::BaseCounter< DerivedCounter >::_increment ( size_type  index) const
inlineprotected

const Access to element in the increment value of the Container

Returns
a const reference to the element 'index' in the increment value of the Container

Definition at line 307 of file BaseCounter.hh.

template<typename DerivedCounter>
value_type& CASM::BaseCounter< DerivedCounter >::_increment ( size_type  index)
inlineprotected

non-const Access to element in the increment value of the Container

Returns
a non-const reference to the element 'index' in the increment value of the Container

Definition at line 315 of file BaseCounter.hh.

template<typename DerivedCounter>
const value_type& CASM::BaseCounter< DerivedCounter >::_initial ( size_type  index) const
inlineprotected

const Access to element in the initial value of the Container

Returns
a const reference to the element 'index' in the initial value of the Container

Definition at line 275 of file BaseCounter.hh.

template<typename DerivedCounter>
value_type& CASM::BaseCounter< DerivedCounter >::_initial ( size_type  index)
inlineprotected

non-const Access to element in the initial value of the Container

Returns
a non-const reference to the element 'index' in the initial value of the Container

Definition at line 283 of file BaseCounter.hh.

template<typename DerivedCounter>
const value_type& CASM::BaseCounter< DerivedCounter >::_lower ( size_type  index) const
inlineprotected

const Access to element in the lower value of the Container

Returns
a const reference to the element 'index' in the lower value of the Container

Definition at line 339 of file BaseCounter.hh.

template<typename DerivedCounter>
value_type& CASM::BaseCounter< DerivedCounter >::_lower ( size_type  index)
inlineprotected

non-const Access to element in the lower value of the Container

Returns
a non-const reference to the element 'index' in the lower value of the Container

Definition at line 347 of file BaseCounter.hh.

template<typename DerivedCounter>
const value_type& CASM::BaseCounter< DerivedCounter >::_upper ( size_type  index) const
inlineprotected

const Access to element in the upper value of the Container

Returns
a const reference to the element 'index' in the upper value of the Container

Definition at line 323 of file BaseCounter.hh.

template<typename DerivedCounter>
value_type& CASM::BaseCounter< DerivedCounter >::_upper ( size_type  index)
inlineprotected

non-const Access to element in the upper value of the Container

Returns
a non-const reference to the element 'index' in the upper value of the Container

Definition at line 331 of file BaseCounter.hh.

template<typename DerivedCounter>
bool& CASM::BaseCounter< DerivedCounter >::_valid ( )
inlineprotected

non-const reference bool validity flag

Definition at line 241 of file BaseCounter.hh.

template<typename DerivedCounter>
bool CASM::BaseCounter< DerivedCounter >::compare ( const value_type A,
const value_type B 
)
inline

Use internal Compare object to compare two values

Returns
bool that is result of Compare()(value A, value B)

Definition at line 187 of file BaseCounter.hh.

template<typename DerivedCounter>
const Container& CASM::BaseCounter< DerivedCounter >::current ( ) const
inline

const Access the current value of the Container

Returns
a const reference to the current value of the Container

Definition at line 195 of file BaseCounter.hh.

template<typename DerivedCounter>
const value_type& CASM::BaseCounter< DerivedCounter >::current ( size_type  index) const
inline

const Access the element 'index' of the current value of the Container

Returns
a const reference to an element of the Container

Definition at line 203 of file BaseCounter.hh.

template<typename DerivedCounter>
const Container& CASM::BaseCounter< DerivedCounter >::final ( ) const
inline

const Access the final value of the Container

Returns
a const reference to the final value of the Container

Definition at line 227 of file BaseCounter.hh.

template<typename DerivedCounter>
const Container& CASM::BaseCounter< DerivedCounter >::increment ( ) const
inline

const Access the incrementing values of the Container

Returns
a const reference to the incrementing value of the Container

Definition at line 235 of file BaseCounter.hh.

template<typename DerivedCounter>
const Container& CASM::BaseCounter< DerivedCounter >::initial ( ) const
inline

const Access the intial value of the Container

Returns
a const reference to the initial value of the Container

Definition at line 219 of file BaseCounter.hh.

template<typename DerivedCounter>
CASM::BaseCounter< DerivedCounter >::operator bool ( ) const
inline

Definition at line 150 of file BaseCounter.hh.

template<typename DerivedCounter>
CASM::BaseCounter< DerivedCounter >::operator const Container & ( ) const
inline

const Access the current value of the Container (identical to current)

Returns
a const reference to the current value of the Container

Definition at line 158 of file BaseCounter.hh.

template<typename DerivedCounter>
const Container& CASM::BaseCounter< DerivedCounter >::operator() ( ) const
inline

const Access the current value of the Container (identical to current)

Returns
a const reference to the current value of the Container

Definition at line 211 of file BaseCounter.hh.

template<typename DerivedCounter>
const value_type& CASM::BaseCounter< DerivedCounter >::operator[] ( size_type  index) const
inline

Definition at line 163 of file BaseCounter.hh.

template<typename DerivedCounter>
size_type CASM::BaseCounter< DerivedCounter >::size ( ) const
inline

Return the size of the Container

Returns
the size of the Container

Definition at line 171 of file BaseCounter.hh.

template<typename DerivedCounter>
bool CASM::BaseCounter< DerivedCounter >::valid ( ) const
inline
Returns
false if the Counter::current value has been incremented past the Counter::final

Definition at line 146 of file BaseCounter.hh.

template<typename DerivedCounter>
const_value_iterator CASM::BaseCounter< DerivedCounter >::value_begin ( ) const
inline

Definition at line 175 of file BaseCounter.hh.

template<typename DerivedCounter>
const_value_iterator CASM::BaseCounter< DerivedCounter >::value_end ( ) const
inline

Definition at line 179 of file BaseCounter.hh.

Member Data Documentation

template<typename DerivedCounter>
Access CASM::BaseCounter< DerivedCounter >::m_access
private

A functor that enables different ways of accessing the container, by default: container[index].

Definition at line 353 of file BaseCounter.hh.

template<typename DerivedCounter>
Compare CASM::BaseCounter< DerivedCounter >::m_compare
private

A functor that enables custom comparison, by default: operator<.

Definition at line 356 of file BaseCounter.hh.

template<typename DerivedCounter>
Container CASM::BaseCounter< DerivedCounter >::m_current
private

The current state of the container.

Definition at line 374 of file BaseCounter.hh.

template<typename DerivedCounter>
Container CASM::BaseCounter< DerivedCounter >::m_final
private

Final container values.

Definition at line 362 of file BaseCounter.hh.

template<typename DerivedCounter>
Container CASM::BaseCounter< DerivedCounter >::m_increment
private

Amount to increment each container value.

Definition at line 365 of file BaseCounter.hh.

template<typename DerivedCounter>
Container CASM::BaseCounter< DerivedCounter >::m_initial
private

Initial container values.

Definition at line 359 of file BaseCounter.hh.

template<typename DerivedCounter>
Container CASM::BaseCounter< DerivedCounter >::m_lower
private

The minimum of each value of m_initial and m_final.

Definition at line 368 of file BaseCounter.hh.

template<typename DerivedCounter>
Container CASM::BaseCounter< DerivedCounter >::m_upper
private

The maximum of each value of m_initial and m_final.

Definition at line 371 of file BaseCounter.hh.

template<typename DerivedCounter>
bool CASM::BaseCounter< DerivedCounter >::m_valid
private

True if m_current is within the allowed bounds, false once all values have been incremented to their limit

Definition at line 378 of file BaseCounter.hh.


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