Update of /cvsroot/mahogany/M/include
In directory sc8-pr-cvs1:/tmp/cvs-serv24321/include
Modified Files:
ConfigSource.h
Log Message:
added ConfigSource and related classes and ConfigSourceLocal implementation
Index: ConfigSource.h
===================================================================
RCS file: /cvsroot/mahogany/M/include/ConfigSource.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -b -u -2 -r1.4 -r1.5
--- ConfigSource.h 25 Aug 2003 23:34:36 -0000 1.4
+++ ConfigSource.h 29 Aug 2003 00:06:41 -0000 1.5
@@ -45,4 +45,7 @@
class WXDLLEXPORT wxConfigBase;
+/// The name of the config section containing the config sources info
+#define M_CONFIGSRC_CONFIG_SECTION _T("/M/Configs")
+
/**
ConfigSource is a source of configuration information.
@@ -56,4 +59,26 @@
public:
/**
+ This class is used with GetFirst/NextEntry/Group().
+ */
+ class EnumData
+ {
+ public:
+ EnumData() { }
+
+ // for internal use only
+ String& Key() { return m_key; }
+ long& Cookie() { return m_cookie; }
+
+ private:
+ String m_key;
+ long m_cookie;
+
+ // we can't be copied
+ EnumData(const EnumData&);
+ EnumData& operator=(const EnumData&);
+ };
+
+
+ /**
@name Creating config sources.
@@ -155,6 +180,6 @@
As above, onlky strings and longs are directly supported.
- All methods below return true if ok and false on error -- this should be
- checked for and handled!
+ All Write() methods below return true if ok and false on error -- this
+ should be checked for and handled!
*/
//@{
@@ -166,4 +191,14 @@
virtual bool Write(const String& name, long value) = 0;
+ /**
+ Flush, i.e. permanently save, the data written to this config source.
+
+ This may do nothing at all or take a long time to complete depending on
+ the implementation.
+
+ @return true if the data was successfully flushed, false on error
+ */
+ virtual bool Flush() = 0;
+
//@}
@@ -180,14 +215,38 @@
/// Get the first subgroup of the given key
- virtual bool GetFirstGroup(String& group, long& cookie) const = 0;
+ virtual bool GetFirstGroup(const String& key,
+ String& group, EnumData& cookie) const = 0;
/// Get the next subgroup of the given key
- virtual bool GetNextGroup(String& group, long& cookie) const = 0;
+ virtual bool GetNextGroup(String& group, EnumData& cookie) const = 0;
/// Get the first entry of the given key
- virtual bool GetFirstEntry(String& entry, long& cookie) const = 0;
+ virtual bool GetFirstEntry(const String& key,
+ String& entry, EnumData& cookie) const = 0;
/// Get the next entry of the given key
- virtual bool GetNextEntry(String& entry, long& cookie) const = 0;
+ virtual bool GetNextEntry(String& entry, EnumData& cookie) const = 0;
+
+ /**
+ Checks whether the given group exists.
+
+ Note to implementors: the path may contain slashes, so this function
+ should recurse for each path component, not just enumerate all immediate
+ subgroups!
+
+ @param path the group to check existence of
+ @return true if the group exists (even if it is empty), false otherwise
+ */
+ virtual bool HasGroup(const String& path) const = 0;
+
+ /**
+ Checks whether the given entry exists.
+
+ @sa HasGroup
+
+ @param path the entry to check existence of (may contain slashes)
+ @return true if the entry exists
+ */
+ virtual bool HasEntry(const String& path) const = 0;
//@}
@@ -195,9 +254,9 @@
/**
- @name Deleting entries and groups.
+ @name Other operations on entries and groups.
*/
//@{
- /// Delete the given entry
+ /// Delete the given entry (it must exist).
virtual bool DeleteEntry(const String& name) = 0;
@@ -205,4 +264,18 @@
virtual bool DeleteGroup(const String& name) = 0;
+ /**
+ Copy the given entry (maybe to another group).
+ */
+ virtual bool CopyEntry(const String& nameSrc, const String& nameDst) = 0;
+
+ /**
+ Rename a group.
+
+ We don't provide a method for entry renaming first because we don't need
+ it right now and second because doing it is already possible using
+ CopyEntry() and DeleteEntry().
+ */
+ virtual bool RenameGroup(const String& nameOld, const String& nameNew) = 0;
+
//@}
@@ -243,4 +316,5 @@
*/
ConfigSourceLocal(const String& filename, const String& name = _T(""));
+ virtual ~ConfigSourceLocal();
// implement base class pure virtuals
@@ -251,12 +325,23 @@
virtual bool Write(const String& name, const String& value);
virtual bool Write(const String& name, long value);
- virtual bool GetFirstGroup(String& group, long& cookie) const;
- virtual bool GetNextGroup(String& group, long& cookie) const;
- virtual bool GetFirstEntry(String& entry, long& cookie) const;
- virtual bool GetNextEntry(String& entry, long& cookie) const;
+ virtual bool Flush();
+ virtual bool GetFirstGroup(const String& key,
+ String& group, EnumData& cookie) const;
+ virtual bool GetNextGroup(String& group, EnumData& cookie) const;
+ virtual bool GetFirstEntry(const String& key,
+ String& entry, EnumData& cookie) const;
+ virtual bool GetNextEntry(String& entry, EnumData& cookie) const;
+ virtual bool HasGroup(const String& path) const;
+ virtual bool HasEntry(const String& path) const;
virtual bool DeleteEntry(const String& name);
virtual bool DeleteGroup(const String& name);
+ virtual bool CopyEntry(const String& nameSrc, const String& nameDst);
+ virtual bool RenameGroup(const String& nameOld, const String& nameNew);
+
+ // for internal use by ProfileImpl only, don't use elsewhere
+ wxConfigBase *GetConfig() const { return m_config; }
private:
+ // the config object we use
wxConfigBase *m_config;
};
@@ -442,12 +527,5 @@
const String& name) \
{ \
- cname *configNew = new cname(config, name); \
- if ( !configNew->IsOk() ) \
- { \
- configNew->DecRef(); \
- configNew = NULL; \
- } \
- \
- return configNew; \
+ return new cname(config, name); \
} \
\
-------------------------------------------------------
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