00001 #ifndef CORELIB___ENV_REG__HPP
00002 #define CORELIB___ENV_REG__HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <corelib/ncbienv.hpp>
00038 #include <corelib/ncbireg.hpp>
00039
00040
00041
00042
00043
00044
00045
00046
00047 BEGIN_NCBI_SCOPE
00048
00049
00050
00051
00052
00053
00054
00055
00056 class IEnvRegMapper : public CObject
00057 {
00058 public:
00059
00060 virtual string RegToEnv(const string& section, const string& name) const
00061 = 0;
00062
00063
00064
00065 virtual bool EnvToReg(const string& env, string& section, string& name)
00066 const = 0;
00067
00068
00069 virtual string GetPrefix(void) const { return kEmptyStr; }
00070 };
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 class CEnvironmentRegistry : public IRWRegistry
00087 {
00088 public:
00089
00090 CEnvironmentRegistry(TFlags flags = 0);
00091 CEnvironmentRegistry(CNcbiEnvironment& env, EOwnership own = eNoOwnership,
00092 TFlags flags = 0);
00093
00094
00095 ~CEnvironmentRegistry();
00096
00097 enum EPriority {
00098 ePriority_Min = kMin_Int,
00099 ePriority_Default = 0,
00100 ePriority_Max = kMax_Int
00101 };
00102 typedef int TPriority;
00103
00104 void AddMapper(const IEnvRegMapper& mapper,
00105 TPriority prio = ePriority_Default);
00106 void RemoveMapper(const IEnvRegMapper& mapper);
00107
00108 protected:
00109 bool x_Empty(TFlags flags) const;
00110 bool x_Modified(TFlags flags) const;
00111 void x_SetModifiedFlag(bool modified, TFlags flags);
00112 const string& x_Get(const string& section, const string& name,
00113 TFlags flags) const;
00114 bool x_HasEntry(const string& section, const string& name,
00115 TFlags flags) const;
00116 const string& x_GetComment(const string& section, const string& name,
00117 TFlags flags) const;
00118 void x_Enumerate(const string& section, list<string>& entries,
00119 TFlags flags) const;
00120 void x_ChildLockAction(FLockAction action);
00121
00122 void x_Clear(TFlags flags);
00123 bool x_Set(const string& section, const string& name,
00124 const string& value, TFlags flags,
00125 const string& comment);
00126 bool x_SetComment(const string& comment, const string& section,
00127 const string& name, TFlags flags);
00128
00129 private:
00130
00131 CEnvironmentRegistry(const CEnvironmentRegistry&) {}
00132
00133 typedef multimap<TPriority, CConstRef<IEnvRegMapper> > TPriorityMap;
00134
00135 AutoPtr<CNcbiEnvironment> m_Env;
00136 TPriorityMap m_PriorityMap;
00137 bool m_Modified;
00138 TFlags m_Flags;
00139 };
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 class CSimpleEnvRegMapper : public IEnvRegMapper
00154 {
00155 public:
00156 CSimpleEnvRegMapper(const string& section, const string& prefix,
00157 const string& suffix = kEmptyStr);
00158
00159 string RegToEnv (const string& section, const string& name) const;
00160 bool EnvToReg (const string& env, string& section, string& name) const;
00161 string GetPrefix(void) const;
00162 private:
00163 string m_Section, m_Prefix, m_Suffix;
00164 };
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 class CNcbiEnvRegMapper : public IEnvRegMapper
00176 {
00177 public:
00178 string RegToEnv (const string& section, const string& name) const;
00179 bool EnvToReg (const string& env, string& section, string& name) const;
00180 string GetPrefix(void) const;
00181
00182 private:
00183 static const char* sm_Prefix;
00184 };
00185
00186
00187 END_NCBI_SCOPE
00188
00189
00190
00191
00192 #endif
00193
00194