NCBI C++ ToolKit
Public Types | Public Member Functions | Private Types | List of all members
CStaticPairArrayMap< KeyType, ValueType, KeyCompare > Class Template Reference

Search Toolkit Book for CStaticPairArrayMap

class CStaticArrayMap<> is an array adaptor that provides an STLish interface to statically-defined arrays, while making efficient use of the inherent sort order of such arrays. More...

#include <util/static_map.hpp>

+ Inheritance diagram for CStaticPairArrayMap< KeyType, ValueType, KeyCompare >:
+ Collaboration diagram for CStaticPairArrayMap< KeyType, ValueType, KeyCompare >:

Public Types

typedef TBase::value_type value_type
 
typedef TBase::const_iterator const_iterator
 
typedef TBase::size_type size_type
 
typedef TBase::key_compare key_compare
 
- Public Types inherited from CStaticArraySearchBase< NStaticArray::PKeyValuePair< SStaticPair< KeyType, ValueType > >, less< KeyType > >
enum  
 
typedef NStaticArray::PKeyValuePair< SStaticPair< KeyType, ValueType > > getter
 
typedef getter::value_type value_type
 
typedef getter::key_type key_type
 
typedef getter::mapped_type mapped_type
 
typedef less< KeyType > key_compare
 
typedef NStaticArray::PLessByKey< getter, key_comparevalue_compare
 
typedef const value_typeconst_reference
 
typedef const value_typeconst_iterator
 
typedef size_t size_type
 
typedef ssize_t difference_type
 

Public Member Functions

template<size_t Size>
 CStaticPairArrayMap (const value_type(&arr)[Size], const char *file, int line, NStaticArray::ECopyWarn warn=NStaticArray::eCopyWarn_default)
 default constructor. More...
 
template<size_t Size>
 CStaticPairArrayMap (const value_type(&arr)[Size], const key_compare &comp, const char *file, int line, NStaticArray::ECopyWarn warn=NStaticArray::eCopyWarn_default)
 Constructor to initialize comparator object. More...
 
template<class Type >
 CStaticPairArrayMap (const Type *array_ptr, size_t array_size, const char *file, int line, NStaticArray::ECopyWarn warn=NStaticArray::eCopyWarn_default)
 default constructor. More...
 
template<class Type >
 CStaticPairArrayMap (const Type *array_ptr, size_t array_size, const key_compare &comp, const char *file, int line, NStaticArray::ECopyWarn warn=NStaticArray::eCopyWarn_default)
 Constructor to initialize comparator object. More...
 
 CStaticPairArrayMap (const_iterator obj, size_type array_size)
 
 CStaticPairArrayMap (const_iterator obj, size_type array_size, const key_compare &comp)
 
- Public Member Functions inherited from CStaticArraySearchBase< NStaticArray::PKeyValuePair< SStaticPair< KeyType, ValueType > >, less< KeyType > >
 CStaticArraySearchBase (const value_type(&arr)[Size], const char *file, int line, NStaticArray::ECopyWarn warn)
 Default constructor. More...
 
 CStaticArraySearchBase (const value_type(&arr)[Size], const key_compare &comp, const char *file, int line, NStaticArray::ECopyWarn warn)
 Constructor to initialize comparator object. More...
 
 CStaticArraySearchBase (const Type *array_ptr, size_type array_size, const char *file, int line, NStaticArray::ECopyWarn warn)
 Default constructor. More...
 
 CStaticArraySearchBase (const Type *array_ptr, size_type array_size, const key_compare &comp, const char *file, int line, NStaticArray::ECopyWarn warn)
 Constructor to initialize comparator object. More...
 
 ~CStaticArraySearchBase (void)
 Destructor. More...
 
const value_comparevalue_comp () const
 
const key_comparekey_comp () const
 
const_iterator begin () const
 Return the start of the controlled sequence. More...
 
const_iterator end () const
 Return the end of the controlled sequence. More...
 
bool empty () const
 Return true if the container is empty. More...
 
size_type size () const
 Return number of elements in the container. More...
 
const_iterator lower_bound (const key_type &key) const
 Return an iterator into the sequence such that the iterator's key is less than or equal to the indicated key. More...
 
const_iterator upper_bound (const key_type &key) const
 Return an iterator into the sequence such that the iterator's key is greater than the indicated key. More...
 
const_iterator find (const key_type &key) const
 Return a const_iterator pointing to the specified element, or to the end if the element is not found. More...
 
size_type count (const key_type &key) const
 Return the count of the elements in the sequence. More...
 
pair< const_iterator, const_iteratorequal_range (const key_type &key) const
 Return a pair of iterators bracketing the given element in the controlled sequence. More...
 
difference_type index_of (const key_type &key) const
 Return the index of the indicated element, or eNpos if the element is not found. More...
 

Private Types

typedef CStaticArraySearchBase< NStaticArray::PKeyValuePair< SStaticPair< KeyType, ValueType > >, KeyCompare > TBase
 

Additional Inherited Members

- Protected Types inherited from CStaticArraySearchBase< NStaticArray::PKeyValuePair< SStaticPair< KeyType, ValueType > >, less< KeyType > >
typedef void(* TDeallocateFunc) (const_iterator &begin, const_iterator &end)
 
- Protected Member Functions inherited from CStaticArraySearchBase< NStaticArray::PKeyValuePair< SStaticPair< KeyType, ValueType > >, less< KeyType > >
void x_Set (const value_type *array_ptr, size_t array_size, const char *file, int line, NStaticArray::ECopyWarn)
 Assign array pointer and end pointer without conversion. More...
 
void x_Set (const Type *array2_ptr, size_t array2_size, const char *file, int line, NStaticArray::ECopyWarn warn)
 Assign array pointer and end pointer from differently typed array. More...
 
- Static Protected Member Functions inherited from CStaticArraySearchBase< NStaticArray::PKeyValuePair< SStaticPair< KeyType, ValueType > >, less< KeyType > >
static void x_Validate (const value_type *array, size_t size, const value_compare &comp, const char *file, int line)
 Perform sort-order validation. This is a no-op in release mode. More...
 
static void x_DeallocateFunc (const_iterator &begin_ref, const_iterator &end_ref)
 Function used for array destruction and deallocation if it was created from a differently typed static array. More...
 

Detailed Description

template<class KeyType, class ValueType, class KeyCompare = less<KeyType>>
class CStaticPairArrayMap< KeyType, ValueType, KeyCompare >

class CStaticArrayMap<> is an array adaptor that provides an STLish interface to statically-defined arrays, while making efficient use of the inherent sort order of such arrays.

This class can be used both to verify sorted order of a static array and to access a static array cleanly. The template parameters are as follows:

KeyType – type of key object used for access ValueType – type of object used for access KeyCompare – comparison functor. This must provide an operator(). This is patterned to accept PCase and PNocase and similar objects.

To use this class, define your static array as follows:

static const char* sc_MyArray[] = { "val1", "val2", "val3" };

Then, declare a static variable such as:

typedef StaticArraySet<const char*, PNocase_CStr> TStaticArray; static TStaticArray sc_Array(sc_MyArray, sizeof(sc_MyArray));

In debug mode, the constructor will scan the list of items and insure that they are in the sort order defined by the comparator used. If the sort order is not correct, then the constructor will ASSERT().

This can then be accessed as

if (sc_Array.find(some_value) != sc_Array.end()) { ... }

or

size_t idx = sc_Array.index_of(some_value); if (idx != TStaticArray::eNpos) { ... }

class CStaticPairArrayMap<> provides access to a static array of pairs in much the same way as CStaticArraySet<>, except that it provides binding of a value type to each sorted key, much like an STL map<> would. Its first template parameter must satisfy STL pair<> requirements: 1. it must define first_type and second_type typedefs, 2. it must have two data members: first and second.

Definition at line 103 of file static_map.hpp.

Member Typedef Documentation

◆ const_iterator

template<class KeyType , class ValueType , class KeyCompare = less<KeyType>>
typedef TBase::const_iterator CStaticPairArrayMap< KeyType, ValueType, KeyCompare >::const_iterator

Definition at line 109 of file static_map.hpp.

◆ key_compare

template<class KeyType , class ValueType , class KeyCompare = less<KeyType>>
typedef TBase::key_compare CStaticPairArrayMap< KeyType, ValueType, KeyCompare >::key_compare

Definition at line 111 of file static_map.hpp.

◆ size_type

template<class KeyType , class ValueType , class KeyCompare = less<KeyType>>
typedef TBase::size_type CStaticPairArrayMap< KeyType, ValueType, KeyCompare >::size_type

Definition at line 110 of file static_map.hpp.

◆ TBase

template<class KeyType , class ValueType , class KeyCompare = less<KeyType>>
typedef CStaticArraySearchBase<NStaticArray::PKeyValuePair< SStaticPair<KeyType, ValueType> >, KeyCompare> CStaticPairArrayMap< KeyType, ValueType, KeyCompare >::TBase
private

Definition at line 106 of file static_map.hpp.

◆ value_type

template<class KeyType , class ValueType , class KeyCompare = less<KeyType>>
typedef TBase::value_type CStaticPairArrayMap< KeyType, ValueType, KeyCompare >::value_type

Definition at line 108 of file static_map.hpp.

Constructor & Destructor Documentation

◆ CStaticPairArrayMap() [1/6]

template<class KeyType , class ValueType , class KeyCompare = less<KeyType>>
template<size_t Size>
CStaticPairArrayMap< KeyType, ValueType, KeyCompare >::CStaticPairArrayMap ( const value_type(&)  arr[Size],
const char *  file,
int  line,
NStaticArray::ECopyWarn  warn = NStaticArray::eCopyWarn_default 
)
inline

default constructor.

This will build a map around a given array; the storage of the end pointer is based on the supplied array size. In debug mode, this will verify that the array is sorted.

Definition at line 117 of file static_map.hpp.

◆ CStaticPairArrayMap() [2/6]

template<class KeyType , class ValueType , class KeyCompare = less<KeyType>>
template<size_t Size>
CStaticPairArrayMap< KeyType, ValueType, KeyCompare >::CStaticPairArrayMap ( const value_type(&)  arr[Size],
const key_compare comp,
const char *  file,
int  line,
NStaticArray::ECopyWarn  warn = NStaticArray::eCopyWarn_default 
)
inline

Constructor to initialize comparator object.

Definition at line 126 of file static_map.hpp.

◆ CStaticPairArrayMap() [3/6]

template<class KeyType , class ValueType , class KeyCompare = less<KeyType>>
template<class Type >
CStaticPairArrayMap< KeyType, ValueType, KeyCompare >::CStaticPairArrayMap ( const Type array_ptr,
size_t  array_size,
const char *  file,
int  line,
NStaticArray::ECopyWarn  warn = NStaticArray::eCopyWarn_default 
)
inline

default constructor.

This will build a map around a given array; the storage of the end pointer is based on the supplied array size. In debug mode, this will verify that the array is sorted.

Definition at line 138 of file static_map.hpp.

◆ CStaticPairArrayMap() [4/6]

template<class KeyType , class ValueType , class KeyCompare = less<KeyType>>
template<class Type >
CStaticPairArrayMap< KeyType, ValueType, KeyCompare >::CStaticPairArrayMap ( const Type array_ptr,
size_t  array_size,
const key_compare comp,
const char *  file,
int  line,
NStaticArray::ECopyWarn  warn = NStaticArray::eCopyWarn_default 
)
inline

Constructor to initialize comparator object.

Definition at line 147 of file static_map.hpp.

◆ CStaticPairArrayMap() [5/6]

template<class KeyType , class ValueType , class KeyCompare >
CStaticPairArrayMap< KeyType, ValueType, KeyCompare >::CStaticPairArrayMap ( const_iterator  obj,
size_type  array_size 
)
inline

Definition at line 241 of file static_map.hpp.

◆ CStaticPairArrayMap() [6/6]

template<class KeyType , class ValueType , class KeyCompare >
CStaticPairArrayMap< KeyType, ValueType, KeyCompare >::CStaticPairArrayMap ( const_iterator  obj,
size_type  array_size,
const key_compare comp 
)
inline

Definition at line 250 of file static_map.hpp.


The documentation for this class was generated from the following file:
Modified on Sun Apr 21 03:45:20 2024 by modify_doxy.py rev. 669887