CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CASM::BaseCounter< DerivedCounter > Class Template Reference

#include <BaseCounter.hh>

+ Inheritance diagram for CASM::BaseCounter< DerivedCounter >:

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++);
size_type size() const
Definition: BaseCounter.hh:178
const Container & increment() const
Definition: BaseCounter.hh:233
const Container & initial() const
Definition: BaseCounter.hh:221

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 125 of file BaseCounter.hh.

Public Types

typedef traits< DerivedCounter >::Container Container
 
typedef traits< DerivedCounter >::value_type value_type
 
typedef traits< DerivedCounter >::size_type size_type
 
typedef traits< DerivedCounter >::Access Access
 
typedef 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
 
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

◆ Access

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

Definition at line 130 of file BaseCounter.hh.

◆ Compare

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

Definition at line 131 of file BaseCounter.hh.

◆ const_value_iterator

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

Definition at line 132 of file BaseCounter.hh.

◆ Container

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

Definition at line 127 of file BaseCounter.hh.

◆ size_type

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

Definition at line 129 of file BaseCounter.hh.

◆ value_type

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

Definition at line 128 of file BaseCounter.hh.

Constructor & Destructor Documentation

◆ BaseCounter() [1/2]

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

Default construct a Counter.

Definition at line 135 of file BaseCounter.hh.

◆ BaseCounter() [2/2]

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 142 of file BaseCounter.hh.

Member Function Documentation

◆ _current() [1/3]

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 259 of file BaseCounter.hh.

◆ _current() [2/3]

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 253 of file BaseCounter.hh.

◆ _current() [3/3]

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 244 of file BaseCounter.hh.

◆ _final() [1/2]

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 291 of file BaseCounter.hh.

◆ _final() [2/2]

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 282 of file BaseCounter.hh.

◆ _increment() [1/2]

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 307 of file BaseCounter.hh.

◆ _increment() [2/2]

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 298 of file BaseCounter.hh.

◆ _initial() [1/2]

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 275 of file BaseCounter.hh.

◆ _initial() [2/2]

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 266 of file BaseCounter.hh.

◆ _lower() [1/2]

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 341 of file BaseCounter.hh.

◆ _lower() [2/2]

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 332 of file BaseCounter.hh.

◆ _upper() [1/2]

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 325 of file BaseCounter.hh.

◆ _upper() [2/2]

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 316 of file BaseCounter.hh.

◆ _valid()

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

non-const reference bool validity flag

Definition at line 237 of file BaseCounter.hh.

◆ compare()

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 193 of file BaseCounter.hh.

◆ current() [1/2]

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 201 of file BaseCounter.hh.

◆ current() [2/2]

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 207 of file BaseCounter.hh.

◆ final()

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.

◆ increment()

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 233 of file BaseCounter.hh.

◆ initial()

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 221 of file BaseCounter.hh.

◆ operator bool()

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

Definition at line 162 of file BaseCounter.hh.

◆ operator const Container &()

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 168 of file BaseCounter.hh.

◆ operator()()

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 215 of file BaseCounter.hh.

◆ operator[]()

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

Definition at line 170 of file BaseCounter.hh.

◆ size()

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 178 of file BaseCounter.hh.

◆ valid()

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 160 of file BaseCounter.hh.

◆ value_begin()

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

Definition at line 180 of file BaseCounter.hh.

◆ value_end()

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

Definition at line 184 of file BaseCounter.hh.

Member Data Documentation

◆ m_access

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 346 of file BaseCounter.hh.

◆ m_compare

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

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

Definition at line 349 of file BaseCounter.hh.

◆ m_current

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

The current state of the container.

Definition at line 367 of file BaseCounter.hh.

◆ m_final

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

Final container values.

Definition at line 355 of file BaseCounter.hh.

◆ m_increment

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

Amount to increment each container value.

Definition at line 358 of file BaseCounter.hh.

◆ m_initial

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

Initial container values.

Definition at line 352 of file BaseCounter.hh.

◆ m_lower

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

The minimum of each value of m_initial and m_final.

Definition at line 361 of file BaseCounter.hh.

◆ m_upper

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

The maximum of each value of m_initial and m_final.

Definition at line 364 of file BaseCounter.hh.

◆ m_valid

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 371 of file BaseCounter.hh.


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