Template Class MapManager

Class Documentation

template<typename MapType>
class backend::MapManager

Provides an interface to access the the maps in the MapStorage.

Some of the methods of MapManager directly forward the calls to MapStorage. Check with the documentation of MapStorage to get a list of possible failure cases. The methods in here lock the MapStorage.

Sample usage:

// Create a local map manager.
backend::MapManager<MapType> map_manager;
// E.g. to use the MapManager for VIMaps, you can set MapType to
`vi_map::VIMap`.

// Get a map.
MapType& map = map_manager.getMap("key_of_map");

// Do work on map.
// ...

When you are done with the changes to the map, you can simply let the reference to the map and the MapManager go out of scope. There is no need to commit the changes.

If you want to access the map in a threadsafe way, use:

// Create a local map manager.
backend::MapManager map_manager;

// Get a map (threadsafe).
backend::MapManager<MapType>::MapThreadSafeAccess vi_map =
    map_manager.getMapThreadSafe("key_of_map");
// Map is now locked, other threads asking for a threadsafe map will be
blocked.

// Do work on map.
// ...

tparam MapType

Type of the map.

Public Types

typedef common::Monitor<MapType>::WriteAccess MapWriteAccess

A container for the map that automatically locks the mutex belonging to the map until the thread safe access is out of scope.

See common::Monitor for details.

typedef common::Monitor<MapType>::ReadAccess MapReadAccess

Public Functions

MapManager()
inline ~MapManager()
MapType *getMapMutable(const std::string &key)

Gets a map from the storage.

Calls MapStorage::getMap().

Parameters

key[in] Key of the map to be returned.

Returns

Reference to the map.

const MapType &getMap(const std::string &key) const
MapWriteAccess getMapWriteAccess(const std::string &key)

Returns a map for write access to use in a thread safe context.

The map is automatically locked when using this function.

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

Parameters

key – Key of the map to be returned.

Returns

Thread safe write access of the map.

MapReadAccess getMapReadAccess(const std::string &key) const

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

The map is automatically locked when using this function.

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

Parameters

key – Key of the map to be returned.

Returns

Thread safe read access of the map.

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

Checks if a specified map exists.

Calls MapStorage::hasMap().

Parameters

key[in] Key of the map.

Returns

True if map exists.

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

Checks if the given key is valid and doesn’t contain any prohibited characters.

Calls MapStorage::isKeyValid().

Parameters

key – Key to check.

Returns

True if the key is valid.

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

Removes any prohibited character from the string.

Calls MapStorage::removeProhibitedCharactersFromKey().

Parameters

key – Key where prohibited characters should be removed.

Returns

Original key without any prohibited character.

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

Gets a list with keys of all maps saved in the storage.

Calls MapStorage::getAllMapKeys().

Parameters

all_map_keys_list[out] Set where map keys are inserted.

void getAllMapKeys(std::vector<std::string> *all_map_keys_list) const
size_t numberOfMaps() const

Gets the number of maps saved in the storage.

Calls MapStorage::numberOfMaps().

Returns

Number of maps saved in the storage.

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

Inserts a map into the storage.

Calls MapStorage::addMap().

Parameters
  • key[in] Key under which the map will be stored.

  • map[inout] Pointer to the map that will be inserted into the storage. If the insertion was successful, the given unique pointer will point to nullptr. Otherwise, the map remains managed by the given unique pointer.

void deleteMap(const std::string &key)

Removes a map from the storage.

Calls MapStorage::deleteMap().

Parameters

key[in] Key of the map to be removed.

AlignedUniquePtr<MapType> releaseMap(const std::string &key)

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

Calls MapStorage::releaseMap().

Parameters

key[in] – Key of the map to be released. returns Unique pointer to the released map.

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

Renames a map in the storage.

Calls MapStorage::renameMap().

Parameters
  • old_key[in] The key under which the map is currently stored.

  • new_key[in] The new key that the map should have.

void copyMap(const std::string &source_key, const std::string &target_key)

Copies the map specified by source_key into target_key.

Crashes if the source map doesn’t exist or if a map under target_key already exists.

Parameters
  • source_key – Key of the map to be copied.

  • target_key – Key under which the copy will be stored.

bool mergeMaps(const std::string &source_key_merge_base, const std::string &source_key_merge_from)

Merges source_key_merge_from into source_key_merge_base.

Parameters
  • source_key_merge_base – The base map for the merge operation.

  • source_key_merge_from – The map which will be merged into the base map.

  • generate_new_ids – If set to true, this will generate new ids for the missions, vertices, edges and landmarks in source_key_b. returns true if the merge was successful, false otherwise.

bool mergeSubmapIntoBaseMap(const std::string &source_key_merge_base_map, const std::string &source_key_merge_submap)

Merges source_key_merge_from into source_key_merge_base.

Parameters
  • source_key_merge_base_map – The base map for the merge operation.

  • source_key_merge_submap – The submap which will be attached to its correspinding vertex in the base map. returns true if the merge was successful, false otherwise.

void getMapFolder(const std::string &map_key, std::string *map_folder) const

Return the currently set map folder of a map.

Crashes if the map doesn’t contain any metadata.

Parameters
  • map_key[in] Key of the map.

  • map_folder[out] Pointer to return the map folder.

void setMapFolder(const std::string &map_key, const std::string &map_folder)

Sets the map folder of a map.

Parameters
  • map_key[in] Key of the map.

  • map_folder[in] New map folder.

bool loadMapFromFolder(const std::string &folder_path, const std::string &key_in)

Loads a map from the given file path into the storage.

Loads the map from the folder given by path. The folder should contain a map folder, its folder name is implementation specific and can be checked by using the getSubFolderName() function.

Parameters
  • path[in] Path to the folder containing the map data.

  • key_in[in] Key under which the map is stored. If no key is provided, the key is generated from the folder name.

  • key_out[out] If the map key should be automatically generated, the function will write the generated key into this variable. Optional variable.

Returns

True if the operation was successful.

bool loadMapFromFolder(const std::string &folder_path, std::string *key_out)
bool loadMapFromFolder(const std::string &folder_path)
bool loadAllMapsFromFolder(const std::string &folder_path)

Loads all maps in a given folder.

This method recursively scans the given folder and searches for a map file in all its subdirectories.

The keys under which the maps are stored are determined by the filename. If a key already exists in the storage, this operation will fail.

Parameters

folder_path – Path of the folder containing the maps to load.

Returns

True if all maps in the folder are successfully loaded and at least one map has been loaded.

bool loadAllMapsFromFolder(const std::string &folder_path, std::unordered_set<std::string> *new_keys)
bool saveMapToFolder(const std::string &key, const std::string &folder_path) const

Saves a map to a folder.

By default, this will create a folder folder_path/key and save the map in there. The implementation will create another folder in there with the name given by getSubFolderName(). folder_path.

Parameters
  • key – Key of the map to save.

  • overwrite_existing_file – If set to true, any already existing file will be overwritten. Set to false by default.

  • folder_path – Folder in which the map should be saved.

Returns

True if the operation was successful.

bool saveMapToFolder(const std::string &key, const std::string &folder_path, const SaveConfig &config) const
bool saveMapToMapFolder(const std::string &key) const

Saves a map into its map folder as specified by the map’s metadata.

Parameters
  • key – Key of the map to save.

  • overwrite_existing_file – If set to true, any already existing file will be overwritten. Set to false by default.

Returns

True if the operation was successful.

bool saveMapToMapFolder(const std::string &key, const SaveConfig &config) const
bool saveAllMapsToFolder(const std::string &folder_path) const

Saves all map in the storage to a given folder on the file system.

Creates a folder named after the key for each map in folder_path. The map data is saved in its folder. The save implementation for each map will create an additional folder in there whose name can be checked using the getSubFolderName() function.

Parameters
  • folder_path – Path of the folder where the maps will be saved. If folder_path is an empty string, all maps will be saved into their respective map folder.

  • overwrite_existing_file – If set to true, any already existing file will be overwritten. Set to false by default.

Returns

True if all maps are successfully saved.

bool saveAllMapsToFolder(const std::string &folder_path, const SaveConfig &config) const
bool saveAllMapsToMapFolder() const

Saves all maps into each map’s map folder as specified by the map’s metadata.

Parameters

overwrite_existing_file – If set to true, any already existing file will be overwritten. Set to false by default.

Returns

True if all maps are successfully saved.

bool saveAllMapsToMapFolder(const SaveConfig &config) const
bool hasMapOnFileSystem(const std::string &folder_path) const

Checks if all map data exists on the file system.

Parameters

folder_path – Path to the folder containing the map.

Returns

True if the map exists on the file system.

void getDefaultMapKeys(const std::vector<std::string> &map_list, std::vector<std::string> *key_list)

Returns the default map keys for a given list of maps folders.

Parameters
  • map_list – List of map folders.

  • key_list – The default keys of the given maps.

void listAllMapsInFolder(const std::string &folder_path, std::vector<std::string> *map_list)

Lists all maps in a given folder.

This method recursively scans the given folder and searches for map files in all its subdirectories.

Parameters
  • folder_path – Folder to search.

  • map_list – List of map folders found in the given folder.

Protected Attributes

MapStorage<MapType> *map_storage_