Update of /cvsroot/mahogany/M/include
In directory sc8-pr-cvs1:/tmp/cvs-serv24483/include
Modified Files:
Profile.h
Log Message:
rewrote Profile to use ConfigSource
Index: Profile.h
===================================================================
RCS file: /cvsroot/mahogany/M/include/Profile.h,v
retrieving revision 1.79
retrieving revision 1.80
diff -b -u -2 -r1.79 -r1.80
--- Profile.h 30 Apr 2003 00:17:15 -0000 1.79
+++ Profile.h 29 Aug 2003 00:08:07 -0000 1.80
@@ -26,5 +26,5 @@
#include "MObject.h"
-class kbStringList;
+class ConfigSource;
// ----------------------------------------------------------------------------
@@ -39,11 +39,9 @@
profiles (without trailing '/')
*/
-#ifndef M_PROFILE_CONFIG_SECTION
- #define M_PROFILE_CONFIG_SECTION _T("/M/Profiles")
- #define M_IDENTITY_CONFIG_SECTION _T("/M/Ids")
- #define M_FILTERS_CONFIG_SECTION _T("/M/Filters")
- #define M_FRAMES_CONFIG_SECTION _T("/M/Frames")
- #define M_TEMPLATES_CONFIG_SECTION _T("/M/Templates")
-#endif
+#define M_PROFILE_CONFIG_SECTION _T("/Profiles")
+#define M_IDENTITY_CONFIG_SECTION _T("/Ids")
+#define M_FILTERS_CONFIG_SECTION _T("/Filters")
+#define M_FRAMES_CONFIG_SECTION _T("/Frames")
+#define M_TEMPLATES_CONFIG_SECTION _T("/Templates")
/**
@@ -167,7 +165,12 @@
/// Write back the character value.
- virtual bool writeEntry(const String & key, const String & Value) = 0;
+ virtual bool writeEntry(const String& key,
+ const String& value,
+ ConfigSource *config = NULL) = 0;
+
/// Write back the int value.
- virtual bool writeEntry(const String & key, long Value) = 0;
+ virtual bool writeEntry(const String& key,
+ long value,
+ ConfigSource *config = NULL) = 0;
/**
@@ -185,5 +188,6 @@
virtual bool writeEntryIfNeeded(const String& key,
long value,
- long defvalue) = 0;
+ long defvalue,
+ ConfigSource *config = NULL) = 0;
//@}
@@ -191,6 +195,4 @@
/// return true if the entry is defined
virtual bool HasEntry(const String & key) const = 0;
- /// return the type of entry (Type_String, Type_Integer or Type_Unknown
- virtual wxConfigBase::EntryType GetEntryType(const String & key) const = 0;
/// return true if the group exists
virtual bool HasGroup(const String & name) const = 0;
@@ -202,43 +204,87 @@
virtual bool Rename(const String& oldName, const String& newName) = 0;
/// return the name of the profile
- virtual const String GetName(void) const = 0;
+ virtual const String& GetName(void) const = 0;
- /** @name Enumerating groups/entries
- again, this is just directly forwarded to wxConfig
+ /**
+ Returns a pointer to the parent profile.
+
+ @return pointer to Profile to be DecRef()'d by the caller or NULL
*/
- /// see wxConfig docs
- virtual bool GetFirstGroup(String& s, long& l) const = 0;
- /// see wxConfig docs
- virtual bool GetNextGroup(String& s, long& l) const = 0;
- /// see wxConfig docs
- virtual bool GetFirstEntry(String& s, long& l) const = 0;
- /// see wxConfig docs
- virtual bool GetNextEntry(String& s, long& l) const = 0;
+ virtual Profile *GetParent(void) const = 0;
- /// Returns a unique, not yet existing sub-group name: //MT!!
- virtual String GetUniqueGroupName(void) const = 0;
- /// Returns a pointer to the parent profile.
- virtual Profile *GetParent(void) const = 0;
- /** @name Managing environment variables
- just expose wxConfig methods (we do need them to be able to read the
- real config values, i.e. to disable expansion, sometimes)
+ /**
+ @name Enumerating groups/entries
+
+ The enumeration is done over all config sources, i.e. the groups/entries
+ of all of them are returned but no name is returned twice even if it
+ appears in more than one config source.
+
+ All methods below return true if a group/entry is returned in s and
+ false if there are no more of them. For both groups and entries, the
+ cookie passed to GetNextXXX() must be the same as passed to
+ GetFirstXXX().
+ */
+ //@{
+
+ /// Class used with the enumeration methods
+ class EnumData
+ {
+ public:
+ EnumData();
+ ~EnumData();
+
+ private:
+ class ProfileEnumDataImpl *m_impl;
+
+ EnumData(const EnumData&);
+ EnumData& operator=(const EnumData&);
+
+ friend class Profile;
+ };
+
+
+ /// Get the first subgroup under this profile
+ virtual bool GetFirstGroup(String& s, EnumData& cookie) const = 0;
+
+ /// Get the next subgroup of this profile
+ virtual bool GetNextGroup(String& s, EnumData& cookie) const = 0;
+
+ /// Get the first entry in this profile
+ virtual bool GetFirstEntry(String& s, EnumData& cookie) const = 0;
+
+ /// Get the next entry
+ virtual bool GetNextEntry(String& s, EnumData& cookie) const = 0;
+
+ //@}
+
+
+ /**
+ @name Expanding environment variables
+
+ We can (and do, by default) expand the env variables in the values we
+ read from config. Sometimes, however, we need to disable this because,
+ for example, we want to allow the user to edit the real value form
+ profile and not its expansion.
+
+ @sa ProfileEnvVarSave
*/
+ //@{
+
/// are we automatically expanding env vars?
- bool IsExpandingEnvVars() const;
+ bool IsExpandingEnvVars() const { return m_expandEnvVars; }
+
/// set the flag which tells if we should auto expand env vars
- void SetExpandEnvVars(bool bDoIt = TRUE);
+ void SetExpandEnvVars(bool expand = true) { m_expandEnvVars = expand; }
- // for internal use by wxWindows related code only: get the pointer to the
- // underlying wxConfig object. Profile readEntry() functions should be
- // used for reading/writing the entries!
- virtual wxConfigBase *GetConfig() const = 0;
+ //@}
- // for internal use only: get the path corresponding to this profile in
- // config
- virtual String GetConfigPath() const = 0;
- virtual void SetPath(const String &path) = 0;
- virtual void ResetPath(void) = 0;
+ // for internal use by wxWindows related code only: get the pointer to the
+ // underlying wxConfig object.
+ //
+ // this is DEPRECATED now as it doesn't make sense with multiple config
+ // sources, do not use it!
+ virtual wxConfigBase *GetConfig() const = 0;
/// Set temporary/suspended operation.
@@ -307,6 +353,10 @@
static String GetSectionPath(const String& section);
- /// global wxConfig object, shared by all profiles
- static wxConfigBase *ms_GlobalConfig;
+ /// provide access to ProfileEnumDataImpl for the derived classes
+ ProfileEnumDataImpl& GetEnumData(EnumData& cookie) const
+ { return *cookie.m_impl; }
+
+ /// expand env vars if necessary
+ String ExpandEnvVarsIfNeeded(const String& val) const;
private:
@@ -314,7 +364,9 @@
static wxArrayString GetAllGroupsUnder(const String& path);
- /// forbid copy construction
+ /// should we expand the environment variables in string values?
+ bool m_expandEnvVars;
+
+ /// forbid copying
Profile(const Profile &);
- /// forbid assignments
Profile& operator=(const Profile & );
};
@@ -378,32 +430,4 @@
Profile *m_profile;
bool m_wasExpanding;
-};
-
-
-// ----------------------------------------------------------------------------
-// a tiny utility class which is used to temporary change the config path, for
-// example:
-// {
-// ProfilePathChanger ppc(profile->GetConfig(), "/M/Frames");
-// profile->WriteEntry("x", 400);
-// ...
-// // path automatically restored here
-// }
-// ----------------------------------------------------------------------------
-
-class ProfilePathChanger
-{
-public:
- ProfilePathChanger(const Profile *config, const String& path)
- {
- // we don't really change it, just temporarily change the path
- m_config = (Profile *)config;
- m_config->SetPath(path);
- }
-
- ~ProfilePathChanger() { m_config->ResetPath(); }
-
-private:
- Profile *m_config;
};
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates