Garmin Fleet Management Controller  2.19.0
FileBackedMap< T > Class Template Reference

Map whose contents are also saved to a file. More...

#include <FileBackedMap.h>

Public Types

typedef std::map< key_type, T >::const_iterator const_iterator
 Iterator for read-only traversal through the map. More...
 
typedef T::key_type key_type
 key type More...
 

Public Member Functions

 FileBackedMap (const char *aFileName)
 Create a new FileBackedMap. More...
 
const_iterator begin ()
 Iterator positioned at the first element in the map. More...
 
void clear ()
 Remove all elements from the map. More...
 
bool contains (const key_type &aKey)
 Check whether the specified key is in the map. More...
 
uint32 count () const
 The number of items in the map. More...
 
bool empty ()
 Check whether the map is empty. More...
 
const_iterator end ()
 Iterator positioned after the last element in the map. More...
 
T & get (const key_type &aKey)
 Get the item by key. More...
 
const key_typegetKeyAt (uint32 aIndex) const
 Get the key for the item at a given list index. More...
 
void put (T &aValue)
 Add (or replace) an item in the map. More...
 
void remove (const key_type &aKey)
 Remove an item from the map. More...
 
void save ()
 Save the map to disk. More...
 
uint32 validCount () const
 The number of valid items in the map. More...
 

Private Member Functions

void load ()
 Read the contents of the backing file into the map. More...
 

Private Attributes

const char * mFileName
 The name of the file that this map is saved to. More...
 
std::vector< key_typemKeyList
 Map of indexes to keys. More...
 
std::map< key_type, T > mMap
 The underlying map in memory. More...
 

Detailed Description

template<class T>
class FileBackedMap< T >

Map whose contents are also saved to a file.

A FileBackedMap is a map of uint32 to a value type. Each value in the map for which isValid() returns TRUE is saved to a text file, with one line per item.

Methods are provided to add/replace, remove, check for, and get items from the underlying map, iterate through the items in the map, and clear the map's contents. All keep the underlying file in sync.

Template Parameters
TThe value type for items in the map.
Since
Protocol A603

Definition at line 32 of file FileBackedMap.h.

Member Typedef Documentation

template<class T>
typedef std::map<key_type, T>::const_iterator FileBackedMap< T >::const_iterator

Iterator for read-only traversal through the map.

Definition at line 54 of file FileBackedMap.h.

template<class T>
typedef T::key_type FileBackedMap< T >::key_type

key type

Definition at line 36 of file FileBackedMap.h.

Constructor & Destructor Documentation

template<class T>
FileBackedMap< T >::FileBackedMap ( const char *  aFileName)
inline

Create a new FileBackedMap.

Construct a FileBackedMap and load all items from file

Parameters
aFileNameThe file associated with this map.
Note
In this implementation, aFileName must be static const; the name is referenced, not copied.

Definition at line 46 of file FileBackedMap.h.

Member Function Documentation

template<class T>
bool FileBackedMap< T >::contains ( const key_type aKey)
inline

Check whether the specified key is in the map.

Parameters
aKeyThe key to look for
Returns
true if the item is in the map, false otherwise

Definition at line 78 of file FileBackedMap.h.

Referenced by FileBackedMap< StopListItem >::end(), FmiApplicationLayer::getNextStopId(), FmiApplicationLayer::procDriverStatusUpdate(), FmiApplicationLayer::rx(), FmiApplicationLayer::sendAOBRDDriverDownloadResponseV2(), and FmiApplicationLayer::sendDeleteWaypoint().

template<class T>
uint32 FileBackedMap< T >::count ( ) const
inline

The number of items in the map.

Returns
The total number of items in the map

Definition at line 197 of file FileBackedMap.h.

template<class T>
bool FileBackedMap< T >::empty ( )
inline

Check whether the map is empty.

Returns
true if there are no elements in the map, false otherwise

Definition at line 163 of file FileBackedMap.h.

Referenced by FmiApplicationLayer::getNextStopId(), and FmiApplicationLayer::removeStopByIndex().

template<class T>
const key_type& FileBackedMap< T >::getKeyAt ( uint32  aIndex) const
inline

Get the key for the item at a given list index.

Parameters
aIndexThe key of the item to retrieve. Must be less than validCount().
Returns
The key of the item at the specified index.

Definition at line 119 of file FileBackedMap.h.

Referenced by FileBackedMap< StopListItem >::get(), CWaypointDlg::getCatIds(), and CWaypointDlg::OnBnClickedWptBtnDelete().

template<class T>
void FileBackedMap< T >::load ( )
inlineprivate

Read the contents of the backing file into the map.

Load all items from mFileName into mMap.

Definition at line 216 of file FileBackedMap.h.

Referenced by FileBackedMap< StopListItem >::FileBackedMap().

template<class T>
void FileBackedMap< T >::remove ( const key_type aKey)
inline

Remove an item from the map.

Parameters
aKeyThe key of the item to remove

Definition at line 147 of file FileBackedMap.h.

Referenced by FmiApplicationLayer::removeStopByIndex(), FmiApplicationLayer::rx(), and FmiApplicationLayer::sendDeleteWaypoint().

template<class T>
uint32 FileBackedMap< T >::validCount ( ) const
inline

The number of valid items in the map.

Returns
The number of valid items in the map

Definition at line 206 of file FileBackedMap.h.

Member Data Documentation

template<class T>
const char* FileBackedMap< T >::mFileName
private

The name of the file that this map is saved to.

Definition at line 240 of file FileBackedMap.h.

Referenced by FileBackedMap< StopListItem >::load(), and FileBackedMap< StopListItem >::save().

template<class T>
std::vector<key_type> FileBackedMap< T >::mKeyList
private

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