You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.9 KiB

//Copyright 2020 Siemens Digital Industries Software
//==================================================
//Copyright $2010.
//Siemens Product Lifecycle Management Software Inc.
//All Rights Reserved.
//==================================================
//Copyright 2020 Siemens Digital Industries Software
/**
@file
Contains environment variable name mapping methods, based on prefix replacements.
<br>The mapping can be used to help renaming environment variables, e.g. from OLDPREFIX_nametrailer to NEWPREFIX_nametrailer.
The class can only be constructed once and the singleton can be accessed through a static function.
Non-member functions are available in the Teamcenter namespace for convenience.
If a name prefix mapping such as "OLDPREFIX_" ==> "NEWPREFIX_" is defined
then the system automatically accesses the new name "NEWPREFIX_nametrailer"
even if the old source code still reference "OLDPREFIX_nametrailer"
for as long as all access to names is routed through this mapping table.
*/
#ifndef BASE_UTILS_OSENVNAMEMAPPING_HXX
#define BASE_UTILS_OSENVNAMEMAPPING_HXX
#include <string>
#include <map>
#include <base_utils/libbase_utils_exports.h>
namespace Teamcenter
{
class OSEnvNameMapping
{
public:
/** Retrieves the singleton instance */
static OSEnvNameMapping& getInstance();
/**
Adds a name prefix mapping, e.g. from "OLDPREFIX_" to "NEWPREFIX_".
<br>Subsequent calls to getMappedName() with "OLDPREFIX_nametrailer" will return "NEWPREFIX_nametrailer"
*/
void addPrefixMapping(
const std::string & oldPrefix, /**< (I) The name prefix that should be mapped to a new_prefix */
const std::string & newPrefix /**< (I) The replacement prefix */
);
/**
Removes the prefix mapping that has previously been associated through a call to addPrefixMapping()
<br>Subsequent calls to getMappedName() with "OLDPREFIX_nametrailer" will return "OLDPREFIX_nametrailer"
*/
void removePrefixMapping(
const std::string &oldPrefix /**< (I) The name prefix that should no longer be mapped to a new prefix */
);
/**
Returns the mapped name that applies to the provided name.
<br>E.g. it returns "NEWPREFIX_nametrailer" for an input "OLDPREFIX_nametrailer" if the mappings "OLDPREFIX_"
to "NEWPREFIX_" has been set through addPrefixMapping().
@returns The mapped name
*/
std::string getMappedName(
const std::string & originalName /**< (I) The name to be checked against mapping */
) const;
/**
Retrieves the actual map of prefixes.
*/
const std::map< std::string, std::string > & getNamePrefixMap() const;
private:
OSEnvNameMapping();
virtual ~OSEnvNameMapping();
/** The prefix mapping */
std::map< std::string, std::string > m_namePrefixMap;
};
}
#include <base_utils/libbase_utils_undef.h>
#endif