BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlc::IndexClerk Class Reference

#include <bdlc_indexclerk.h>

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (IndexClerk, bslma::UsesBslmaAllocator)
 
 IndexClerk (bslma::Allocator *basicAllocator=0)
 
 IndexClerk (const IndexClerk &original, bslma::Allocator *basicAllocator=0)
 
 ~IndexClerk ()
 Destroy this index clerk.
 
IndexClerkoperator= (const IndexClerk &rhs)
 
template<class STREAM >
STREAM & bdexStreamIn (STREAM &stream, int version)
 
int getIndex ()
 
void putIndex (int index)
 
void removeAll ()
 
template<class STREAM >
STREAM & bdexStreamOut (STREAM &stream, int version) const
 
IndexClerkIter begin () const
 
IndexClerkIter end () const
 
bool isInUse (int index) const
 
int numCommissionedIndices () const
 Return the number of indices currently in use.
 
int numDecommissionedIndices () const
 Return the number of indices that are currently decommissioned.
 
int nextNewIndex () const
 
bsl::ostream & print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
 

Static Public Member Functions

static int maxSupportedBdexVersion (int versionSelector)
 
static int maxSupportedBdexVersion ()
 

Friends

bool operator== (const IndexClerk &, const IndexClerk &)
 
bool operator!= (const IndexClerk &, const IndexClerk &)
 

Detailed Description

This class defines an efficient, value-semantic manager type for reusable, non-negative integer indices. The class invariants are that the all decommissioned indices must be non-negative, less than the next new index, and unique.

See bdlc_indexclerk

Constructor & Destructor Documentation

◆ IndexClerk() [1/2]

bdlc::IndexClerk::IndexClerk ( bslma::Allocator basicAllocator = 0)
inlineexplicit

Create a new index clerk that dispenses consecutive non-negative integers beginning with 0, 1, 2, ...; however, indices returned via putIndex will be reissued before any new ones are created. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ IndexClerk() [2/2]

bdlc::IndexClerk::IndexClerk ( const IndexClerk original,
bslma::Allocator basicAllocator = 0 
)
inline

Create a new index clerk having the value of the specified original index clerk. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ ~IndexClerk()

bdlc::IndexClerk::~IndexClerk ( )
inline

Member Function Documentation

◆ bdexStreamIn()

template<class STREAM >
STREAM & bdlc::IndexClerk::bdexStreamIn ( STREAM &  stream,
int  version 
)

Assign to this object the value read from the specified input stream using the specified version format, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, this object is unaltered and stream is invalidated, but otherwise unmodified. If version is supported but stream becomes invalid during this operation, this object has an undefined, but valid, state. Note that no version is read from stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.

◆ bdexStreamOut()

template<class STREAM >
STREAM & bdlc::IndexClerk::bdexStreamOut ( STREAM &  stream,
int  version 
) const
inline

Write the value of this object, using the specified version format, to the specified output stream, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, stream is invalidated, but otherwise unmodified. Note that version is not written to stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.

◆ begin()

IndexClerkIter bdlc::IndexClerk::begin ( ) const
inline

Return a IndexClerkIter referring to the first index returned to this IndexClerk that is currently unused, or end() if there are currently no decommissioned indices.

◆ BSLMF_NESTED_TRAIT_DECLARATION()

bdlc::IndexClerk::BSLMF_NESTED_TRAIT_DECLARATION ( IndexClerk  ,
bslma::UsesBslmaAllocator   
)

◆ end()

IndexClerkIter bdlc::IndexClerk::end ( ) const
inline

Return a IndexClerkIter referring to an invalid index, indicating the end of the sequence of decommissioned index.

◆ getIndex()

int bdlc::IndexClerk::getIndex ( )
inline

Return the next available unused integer index. Existing decommissioned indices are reissued before new ones are created.

◆ isInUse()

bool bdlc::IndexClerk::isInUse ( int  index) const

Return true if the specified index is currently in use, and false otherwise. The behavior is undefined unless 0 <= index and index < nextNewIndex(). Note that this method runs in time proportional to the number of decommissioned indices.

◆ maxSupportedBdexVersion() [1/2]

int bdlc::IndexClerk::maxSupportedBdexVersion ( )
inlinestatic
Deprecated:
Use maxSupportedBdexVersion(int) instead.

Return the most current BDEX streaming version number supported by this class.

◆ maxSupportedBdexVersion() [2/2]

int bdlc::IndexClerk::maxSupportedBdexVersion ( int  versionSelector)
inlinestatic

Return the maximum valid BDEX format version, as indicated by the specified versionSelector, to be passed to the bdexStreamOut method. Note that it is highly recommended that versionSelector be formatted as "YYYYMMDD", a date representation. Also note that versionSelector should be a compile-time-chosen value that selects a format version supported by both externalizer and unexternalizer. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.

◆ nextNewIndex()

int bdlc::IndexClerk::nextNewIndex ( ) const
inline

Return the smallest (non-negative) index that has not been issued by this index clerk. Note that this function offers the client a "peek" at the next "new" index, but has no effect on the value of this index clerk.

◆ numCommissionedIndices()

int bdlc::IndexClerk::numCommissionedIndices ( ) const
inline

◆ numDecommissionedIndices()

int bdlc::IndexClerk::numDecommissionedIndices ( ) const
inline

◆ operator=()

IndexClerk & bdlc::IndexClerk::operator= ( const IndexClerk rhs)
inline

Assign to this index clerk the value of the specified rhs index clerk, and return a reference to this modifiable index clerk.

◆ print()

bsl::ostream & bdlc::IndexClerk::print ( bsl::ostream &  stream,
int  level = 0,
int  spacesPerLevel = 4 
) const

Format this index clerk to the specified output stream at the (absolute value of) the optionally specified indentation level and return a reference to stream. If level is specified, optionally specify spacesPerLevel, the number of spaces per indentation level for this and all of its nested objects. If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level). If stream is not valid on entry, this operation has no effect.

◆ putIndex()

void bdlc::IndexClerk::putIndex ( int  index)
inline

Return the specified index to this index clerk, which indicates that index is no longer in use and may be reissued. The behavior is undefined if index has never been generated by this clerk or is currently decommissioned.

◆ removeAll()

void bdlc::IndexClerk::removeAll ( )
inline

Remove all of the indices from this index clerk. Note that the following post conditions apply:

assert(0 == numCommissionedIndices());
assert(0 == numDecommissionedIndices());
assert(0 == nextNewIndex());
int numDecommissionedIndices() const
Return the number of indices that are currently decommissioned.
Definition bdlc_indexclerk.h:686
int numCommissionedIndices() const
Return the number of indices currently in use.
Definition bdlc_indexclerk.h:668
int nextNewIndex() const
Definition bdlc_indexclerk.h:692

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const IndexClerk ,
const IndexClerk  
)
friend

Return true if the specified lhs and rhs index clerks do not have the same value, and false otherwise. Two IndexClerk objects do not have the same value if they do not have the same nextNewIndex(), or might generate different sequences of integer indices.

◆ operator==

bool operator== ( const IndexClerk ,
const IndexClerk  
)
friend

Return true if the specified lhs and rhs index clerks have the same value, and false otherwise. Two IndexClerk objects have the same value if they have the same nextNewIndex() and would always generate the same sequence of integer indices.


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