CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare > Class Template Reference

#include <Counter.hh>

+ Inheritance diagram for CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >:

Detailed Description

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
class CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >

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.
CompareA Functor or function with signature 'bool Compare::operator()(const value_type& A, const value_type& B);', which provides a less than comparison, like 'operator<'.

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 71 of file Counter.hh.

Public Types

typedef _Container Container
 
typedef _value_type value_type
 
typedef _size_type size_type
 
typedef _Access Access
 
typedef _Compare Compare
 
typedef CounterValueIterator
< Counter< _Container,
_value_type, _size_type,
_Access, _Compare > > 
const_value_iterator
 

Public Member Functions

 Counter ()
 Default construct a Counter. More...
 
 Counter (const Container &_initial, const Container &_final, const Container &_increment, Access _access=Access(), Compare _compare=Compare())
 Construct a Counter-type object. More...
 
Counteroperator++ ()
 
void operator++ (int)
 
void set_current (const Container &new_current)
 
void reset ()
 Reset the current value of the Counter to the initial value. 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 Types

typedef CASM_TMP::traits
< Counter >::Base 
Base
 

Private Member Functions

void _init ()
 Called from the constructor to set m_lower and m_upper appropriately. More...
 
bool _compute_validity ()
 

Member Typedef Documentation

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
typedef _Access CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::Access

Definition at line 103 of file Counter.hh.

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
typedef CASM_TMP::traits<Counter>::Base CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::Base
private

Definition at line 91 of file Counter.hh.

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
typedef _Compare CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::Compare

Definition at line 104 of file Counter.hh.

typedef CounterValueIterator<Counter< _Container, _value_type, _size_type, _Access, _Compare > > CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::const_value_iterator
inherited

Definition at line 122 of file BaseCounter.hh.

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
typedef _Container CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::Container

Definition at line 100 of file Counter.hh.

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
typedef _size_type CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::size_type

Definition at line 102 of file Counter.hh.

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
typedef _value_type CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::value_type

Definition at line 101 of file Counter.hh.

Constructor & Destructor Documentation

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::Counter ( )
inline

Default construct a Counter.

Definition at line 116 of file Counter.hh.

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::Counter ( 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 124 of file Counter.hh.

Member Function Documentation

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
bool CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::_compute_validity ( )
inlineprivate

Definition at line 190 of file Counter.hh.

const value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_current ( size_type  index) const
inlineprotectedinherited

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.

value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_current ( size_type  index)
inlineprotectedinherited

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.

Container& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_current ( )
inlineprotectedinherited

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.

const value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_final ( size_type  index) const
inlineprotectedinherited

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.

value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_final ( size_type  index)
inlineprotectedinherited

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.

const value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_increment ( size_type  index) const
inlineprotectedinherited

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.

value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_increment ( size_type  index)
inlineprotectedinherited

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 _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
void CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::_init ( )
inlineprivate

Called from the constructor to set m_lower and m_upper appropriately.

Definition at line 177 of file Counter.hh.

const value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_initial ( size_type  index) const
inlineprotectedinherited

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.

value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_initial ( size_type  index)
inlineprotectedinherited

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.

const value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_lower ( size_type  index) const
inlineprotectedinherited

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.

value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_lower ( size_type  index)
inlineprotectedinherited

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.

const value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_upper ( size_type  index) const
inlineprotectedinherited

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.

value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_upper ( size_type  index)
inlineprotectedinherited

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.

bool& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::_valid ( )
inlineprotectedinherited

non-const reference bool validity flag

Definition at line 241 of file BaseCounter.hh.

bool CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::compare ( const value_type A,
const value_type B 
)
inlineinherited

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.

const Container& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::current ( ) const
inlineinherited

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.

const value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::current ( size_type  index) const
inlineinherited

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.

const Container& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::final ( ) const
inlineinherited

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.

const Container& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::increment ( ) const
inlineinherited

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.

const Container& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::initial ( ) const
inlineinherited

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.

CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::operator bool ( ) const
inlineinherited

Definition at line 150 of file BaseCounter.hh.

CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::operator const Container & ( ) const
inlineinherited

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.

const Container& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::operator() ( ) const
inlineinherited

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 _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
Counter& CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::operator++ ( )
inline

Increment the Counter

Returns
true if the Counter is in a valid state after incrementing

Definition at line 137 of file Counter.hh.

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
void CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::operator++ ( int  )
inline

Definition at line 154 of file Counter.hh.

const value_type& CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::operator[] ( size_type  index) const
inlineinherited

Definition at line 163 of file BaseCounter.hh.

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
void CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::reset ( )
inline

Reset the current value of the Counter to the initial value.

Definition at line 170 of file Counter.hh.

template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
void CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::set_current ( const Container new_current)
inline

Definition at line 158 of file Counter.hh.

size_type CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::size ( ) const
inlineinherited

Return the size of the Container

Returns
the size of the Container

Definition at line 171 of file BaseCounter.hh.

bool CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::valid ( ) const
inlineinherited
Returns
false if the Counter::current value has been incremented past the Counter::final

Definition at line 146 of file BaseCounter.hh.

const_value_iterator CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::value_begin ( ) const
inlineinherited

Definition at line 175 of file BaseCounter.hh.

const_value_iterator CASM::BaseCounter< Counter< _Container, _value_type, _size_type, _Access, _Compare > >::value_end ( ) const
inlineinherited

Definition at line 179 of file BaseCounter.hh.


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