LibreOffice Module canvas (master) 1
Classes | Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
canvas::tools::ValueMap< ValueType > Class Template Reference

A very simplistic map for ASCII strings and arbitrary value types. More...

#include <canvastools.hxx>

Collaboration diagram for canvas::tools::ValueMap< ValueType >:
[legend]

Classes

struct  MapEntry
 

Public Member Functions

 ValueMap (const MapEntry *pMap, ::std::size_t nEntries, bool bCaseSensitive)
 Create a ValueMap for the given array of MapEntries. More...
 
bool lookup (const OUString &rName, ValueType &o_rResult) const
 Lookup a value for the given query string. More...
 

Static Private Member Functions

static bool mapComparator (const MapEntry &rLHS, const MapEntry &rRHS)
 

Private Attributes

const MapEntrympMap
 
::std::size_t mnEntries
 
bool mbCaseSensitive
 

Detailed Description

template<typename ValueType>
class canvas::tools::ValueMap< ValueType >

A very simplistic map for ASCII strings and arbitrary value types.

This class internally references a constant, static array of sorted MapEntries, and performs a binary search to look up values for a given query string. Note that this map is static, i.e. not meant to be extended at runtime.

Template parameter: \n ValueType
The value type this map should store, associated with an ASCII string.

Definition at line 421 of file canvastools.hxx.

Constructor & Destructor Documentation

◆ ValueMap()

template<typename ValueType >
canvas::tools::ValueMap< ValueType >::ValueMap ( const MapEntry pMap,
::std::size_t  nEntries,
bool  bCaseSensitive 
)
inline

Create a ValueMap for the given array of MapEntries.

Parameters
pMapPointer to a static array of MapEntries. Must live longer than this object! Make absolutely sure that the string entries passed via pMap are ASCII-only - everything else might not yield correct string comparisons, and thus will result in undefined behaviour.
nEntriesNumber of entries for pMap
bCaseSensitiveWhether the map query should be performed case sensitive or not. When bCaseSensitive is false, all MapEntry strings must be lowercase!

Definition at line 447 of file canvastools.hxx.

References aStr, i, maKey, canvas::tools::ValueMap< ValueType >::MapEntry::maKey, canvas::tools::ValueMap< ValueType >::mapComparator(), canvas::tools::ValueMap< ValueType >::mbCaseSensitive, canvas::tools::ValueMap< ValueType >::mnEntries, and SAL_WARN.

Member Function Documentation

◆ lookup()

template<typename ValueType >
bool canvas::tools::ValueMap< ValueType >::lookup ( const OUString &  rName,
ValueType o_rResult 
) const
inline

Lookup a value for the given query string.

Parameters
rNameThe string to lookup. If the map was created with the case insensitive flag, the lookup is performed case-insensitive, otherwise, case-sensitive.
o_rResultOutput parameter, which receives the value associated with the query string. If no value was found, the referenced object is kept unmodified.
Returns
true, if a matching entry was found.

Definition at line 501 of file canvastools.hxx.

References canvas::tools::ValueMap< ValueType >::MapEntry::maKey, canvas::tools::ValueMap< ValueType >::mapComparator(), canvas::tools::ValueMap< ValueType >::MapEntry::maValue, canvas::tools::ValueMap< ValueType >::mbCaseSensitive, canvas::tools::ValueMap< ValueType >::mnEntries, canvas::tools::ValueMap< ValueType >::mpMap, and OUStringToOString().

◆ mapComparator()

template<typename ValueType >
static bool canvas::tools::ValueMap< ValueType >::mapComparator ( const MapEntry rLHS,
const MapEntry rRHS 
)
inlinestaticprivate

Member Data Documentation

◆ mbCaseSensitive

template<typename ValueType >
bool canvas::tools::ValueMap< ValueType >::mbCaseSensitive
private

◆ mnEntries

template<typename ValueType >
::std::size_t canvas::tools::ValueMap< ValueType >::mnEntries
private

◆ mpMap

template<typename ValueType >
const MapEntry* canvas::tools::ValueMap< ValueType >::mpMap
private

Definition at line 543 of file canvastools.hxx.

Referenced by canvas::tools::ValueMap< ValueType >::lookup().


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