11 #ifndef _FILEBACKEDMAP_H 12 #define _FILEBACKEDMAP_H 47 const char * aFileName
82 return mMap.end() !=
mMap.find( aKey );
103 const key_type & aKey
106 T& item =
mMap[aKey];
108 item.setParent(
this );
137 aValue.setParent(
this );
138 mMap[ aValue.getId() ] = aValue;
148 const key_type & aKey
151 std::map<key_type, T>::iterator iter =
mMap.find( aKey );
152 if( iter !=
mMap.end() )
173 std::ofstream outputStream;
174 std::map<key_type, T>::iterator iter;
176 outputStream.open(
mFileName, std::ios::out );
178 if( outputStream.good() )
181 for( iter =
mMap.begin(); iter !=
mMap.end(); ++iter )
183 if( iter->second.isValid() )
185 iter->second.writeToStream( outputStream );
190 outputStream.close();
218 std::ifstream inputStream(
mFileName, std::ios_base::in );
220 if( inputStream.good() )
223 while( !inputStream.eof() && !inputStream.fail() )
226 item.setParent(
this );
227 item.readFromStream( inputStream );
228 mMap[ item.getId() ] = item;
std::vector< key_type > mKeyList
Map of indexes to keys.
const_iterator begin()
Iterator positioned at the first element in the map.
uint32 count() const
The number of items in the map.
void put(T &aValue)
Add (or replace) an item in the map.
std::map< key_type, T >::const_iterator const_iterator
Iterator for read-only traversal through the map.
const_iterator end()
Iterator positioned after the last element in the map.
bool contains(const key_type &aKey)
Check whether the specified key is in the map.
FileBackedMap(const char *aFileName)
Create a new FileBackedMap.
void clear()
Remove all elements from the map.
bool empty()
Check whether the map is empty.
void load()
Read the contents of the backing file into the map.
const char * mFileName
The name of the file that this map is saved to.
std::map< key_type, T > mMap
The underlying map in memory.
uint32 validCount() const
The number of valid items in the map.
const key_type & getKeyAt(uint32 aIndex) const
Get the key for the item at a given list index.
Map whose contents are also saved to a file.
unsigned long int uint32
32-bit unsigned integer
void save()
Save the map to disk.
T::key_type key_type
key type