Template Class MapStorage

Nested Relationships

Class Documentation

template<typename MapType>
class backend::MapStorage

Stores and owns all maps.

The MapStorage is responsible for storing all the maps. The maps are stored as a pair of a key and a unique pointer to the map. Each MapType has its own separate MapStorage. The methods in this class are not thread safe. If thread safe access is desired, the methods in MapManager should be used.

Template Parameters
  • MapType: Type of the map to be managed.

Public Functions

MapType *getMapMutable(const std::string &key)

Gets a map with a given key.

Crashes when no map can be found under the given key or when the stored map is nullptr.

Return

Pointer to the map.

Parameters
  • [in] key: Key of the map.

const MapType &getMap(const std::string &key) const
common::Monitor<MapType>::WriteAccess getMapWriteAccess(const std::string &key)

Returns a map for write access to use in a threadsafe context.

The map is automatically locked when using this function.

Crashes when no map can be found under the given key.

Return

Thread safe write access of the map.

Parameters
  • key: Key of the map to be returned.

common::Monitor<MapType>::ReadAccess getMapReadAccess(const std::string &key) const

Returns a const map for read access to use in a threadsafe context.

The map is automatically locked when using this function.

Crashes when no map can be found under the given key.

Return

Thread safe read access of the map.

Parameters
  • key: Key of the map to be returned.

bool hasMap(const std::string &key) const

Checks if a map with the given key exists.

Return

True if a map with the given key exists.

Parameters
  • [in] key: Key of the map to check.

bool isKeyValid(const std::string &key) const

Checks if the key is valid.

A key is valid if it is not empty and only contains alphanumeric characters, “-” or “_”. Other characters are prohibited because they might not be supported on all filesystems.

This only checks for general validity of the key, this doesn’t check if a map is already stored under the given key. Use hasMap() to see if the key is already used.

Return

True if the key is valid.

Parameters
  • key: The key to check.

std::string removeProhibitedCharactersFromKey(const std::string &key) const

Removes any prohibited character from the string.

A prohibited character is any character that isn’t alphanumeric, “-” or “_”. The prohibited characters contain characters that are not supported by all file systems or might need escaping on a command line.

Return

Original key without any prohibited character.

Parameters
  • key: Key where prohibited characters should be removed.

inline size_t numberOfMaps() const

Queries the number of maps stored.

Return

Number of maps stored for this MapType.

void getAllMapKeys(std::unordered_set<std::string> *all_map_keys_list) const

Fills a list with keys of all maps saved.

Crashes when the input is not a valid pointer.

Parameters
  • [out] all_map_keys_list: Set in which the keys should be outputted. The set will be cleared at the start of the method.

void getAllMapKeys(std::vector<std::string> *all_map_keys_list) const
void addMap(const std::string &key, AlignedUniquePtr<MapType> &map)

Inserts a map into the storage.

Crashes when the key already exists in the storage, the key is invalid or the map is nullptr.

Parameters
  • key[in]: Key under which the map should be saved.

  • map[inout]: Unique pointer containing the map to be saved. On success, the given unique pointer will point to nullptr after this operation.

std::unique_ptr<MapAndMutex> releaseMapAndMutex(const std::string &key)

Removes a map and mutex from the storage and returns a unique pointer pointing to it.

Crashes if no map with the given key exists.

Parameters
  • key[in]: Key of the map to be released. returns Unique pointer to the released map and mutex.

void renameMap(const std::string &old_key, const std::string &new_key)

Renames a certain map by changing the key associated with it.

Crashes when no map exists under old_key or when a map already exists under new_key.

Parameters
  • old_key: Key under which the map is currently saved.

  • new_key: Key under which the map should be saved from now on.

aslam::ReaderWriterMutex *getContainerMutex() const

Returns a ReaderWriterMutex to lock the MapStorage for threadsafe access.

Return

Pointer to the MapStorage’s ReaderWriterMutex.