41 #define NCBI_USE_ERRCODE_X Corelib_Env
82 if (it->second == &mapper) {
89 "CEnvironmentRegistry::RemoveMapper:"
90 " unknown mapper (already removed?)", 0);
100 ITERATE (list<string>, it, l) {
101 if (mapper->second->EnvToReg(*it, section, name)) {
142 string var_name = it->second->RegToEnv(section, name);
143 const string* resultp = &
m_Env->
Get(var_name, &found);
190 TEntrySet entry_set(use_case);
191 string parsed_section, parsed_name;
195 ITERATE (list<string>, it, l) {
196 if (mapper->second->EnvToReg(*it, parsed_section, parsed_name)) {
197 if (section.empty()) {
198 entry_set.insert(parsed_section);
199 }
else if (
NStr::Equal(section, parsed_section, use_case)) {
200 entry_set.insert(parsed_name);
205 ITERATE (TEntrySet, it, entry_set) {
230 string var_name = it->second->RegToEnv(section, name);
231 if ( !var_name.empty() ) {
232 string cap_name = var_name;
234 string old_value =
m_Env->
Get(var_name);
248 "no mapping defined for [" << section <<
']' << name);
258 string var_name = it->second->RegToEnv(section, name);
260 if (var_name.empty()) {
269 string cap_name = var_name;
285 <<
"CEnvironmentRegistry::x_SetComment: unsupported operation");
293 : m_Section(section), m_Prefix(
prefix), m_Suffix(
suffix)
313 name =
env.substr(plen,
env.length() - tlen);
334 result += name.substr(1) +
"__" + section;
336 result +=
"_" + section +
"__" + name;
338 #ifdef UPPER_CASE_ONLY
355 if (s.
size() == 3 && s ==
"DOT") {
360 if (s.
size() == 6 && s ==
"HYPHEN") {
368 }
else if (s ==
"SPACE") {
387 #ifdef UPPER_CASE_ONLY
388 for (
auto c : env_in ) {
394 vector<CTempString> v;
397 env.reserve(env_in.size());
398 for (
const auto& it : v) {
401 if (&it != &v.back() && !
env.empty() &&
env[l - 1] ==
'_'
407 if (&it != &v.back()) {
417 for ( ; section_start_pos <
env.size(); section_start_pos++) {
420 SIZE_TYPE uu_pos =
env.find(
"__", section_start_pos + 1);
421 if (uu_pos ==
NPOS || uu_pos ==
env.size() - 2) {
425 if (
env[kPfxLen] ==
'_') {
426 section =
env.substr(kPfxLen + 1, uu_pos - kPfxLen - 1);
427 name =
env.substr(uu_pos + 2);
429 name =
env.substr(kPfxLen - 1, uu_pos - kPfxLen + 1);
432 section =
env.substr(uu_pos + 2);
435 ERR_POST(
Info <<
"Invalid registry section name in environment "
439 ERR_POST(
Info <<
"Invalid registry entry name in environment "
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
iterator insert(const value_type &val)
container_type::value_type value_type
static char s_IdentifySubstitution(const CTempString &s)
Classes to support using environment variables as a backend for the registry framework.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
#define REVERSE_ITERATE(Type, Var, Cont)
ITERATE macro to reverse sequence through container elements.
@ eTakeOwnership
An object can take ownership of another.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
void Set(const string &name, const string &value)
Set an environment variable by name.
const string & Get(const string &name, bool *found=NULL) const
Get environment value by name.
void Unset(const string &name)
Delete an environment variable by name.
void Enumerate(list< string > &names, const string &prefix=kEmptyStr) const
Find all variable names starting with an optional prefix.
void Warning(CExceptionArgs_Base &args)
#define NCBI_THROW2(exception_class, err_code, message, extra)
Throw exception with extra parameter.
void Info(CExceptionArgs_Base &args)
CSimpleEnvRegMapper(const string §ion, const string &prefix, const string &suffix=kEmptyStr)
int TFlags
Binary OR of "EFlags".
bool x_Unset(const string §ion, const string &name, TFlags flags)
string RegToEnv(const string §ion, const string &name) const
Returns empty strings for unsupported (section, name) pairs.
void RemoveMapper(const IEnvRegMapper &mapper)
AutoPtr< CNcbiEnvironment > m_Env
~CEnvironmentRegistry()
Destructor.
void x_Clear(TFlags flags)
Called locked, like the virtual methods inherited from IRegistry.
string GetPrefix(void) const
Can be overriden to speed enumeration.
const string & x_Get(const string §ion, const string &name, TFlags flags) const
static bool MaybeSet(string &target, const string &value, TFlags flags)
bool EnvToReg(const string &env, string §ion, string &name) const
The return value indicates whether the environment variable was appropriately formatted.
bool x_HasEntry(const string §ion, const string &name, TFlags flags) const
const string & x_GetComment(const string §ion, const string &name, TFlags flags) const
bool x_Empty(TFlags flags) const
Implementations of the fundamental operations above, to be run with the lock already acquired and som...
TPriorityMap m_PriorityMap
int TPriority
Not restricted to ePriority_*.
string GetPrefix(void) const
Can be overriden to speed enumeration.
void x_ChildLockAction(FLockAction action)
bool x_Set(const string §ion, const string &name, const string &value, TFlags flags, const string &comment)
void x_SetModifiedFlag(bool modified, TFlags flags)
bool x_Modified(TFlags flags) const
string RegToEnv(const string §ion, const string &name) const
Returns empty strings for unsupported (section, name) pairs.
void x_Enumerate(const string §ion, list< string > &entries, TFlags flags) const
bool m_Modified
only tracks mods made through this.
static bool IsNameEntry(const string &str, TFlags flags)
void AddMapper(const IEnvRegMapper &mapper, TPriority prio=ePriority_Default)
bool x_SetComment(const string &comment, const string §ion, const string &name, TFlags flags)
static bool IsNameSection(const string &str, TFlags flags)
Check if "str" consists of alphanumeric and '_' only Treat the case of set fSectionlessEntries separa...
static const char * sm_Prefix
bool EnvToReg(const string &env, string §ion, string &name) const
The return value indicates whether the environment variable was appropriately formatted.
CEnvironmentRegistry(TFlags flags=0)
Constructors.
@ fPersistent
Persistent – saved when file is written.
@ fInternalSpaces
Allow internal whitespace in names.
@ fSectionCase
Create with case-sensitive section names.
@ fTransient
Transient – not saved by default.
@ fInSectionComments
Indicates that we want in-section comments from x_Enumerate.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
NCBI_NS_STD::string::size_type SIZE_TYPE
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
ECase
Which type of string comparison.
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
static string & ToUpper(string &str)
Convert string to upper case – string& version.
size_type size(void) const
Return the length of the represented array.
@ eNocase
Case insensitive compare.
@ eCase
Case sensitive compare.
enum ENcbiOwnership EOwnership
Ownership relations between objects.
Definition of all error codes used in corelib (xncbi.lib).
Defines unified interface to application:
static const char * suffix[]
static const char * prefix[]
static wxAcceleratorEntry entries[3]