Update of /cvsroot/mahogany/M/src/classes
In directory sc8-pr-cvs1:/tmp/cvs-serv24321/src/classes

Modified Files:
        ConfigSource.cpp 
Log Message:
added ConfigSource and related classes and ConfigSourceLocal implementation

Index: ConfigSource.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/ConfigSource.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -u -2 -r1.2 -r1.3
--- ConfigSource.cpp    25 Aug 2003 22:49:20 -0000      1.2
+++ ConfigSource.cpp    29 Aug 2003 00:06:41 -0000      1.3
@@ -47,4 +47,6 @@
 #endif //Unix
 
+#include <errno.h>
+
 #include "ConfigSource.h"
 
@@ -111,5 +113,13 @@
    }
 
-   return factory->Create(config, name);
+   ConfigSource *configNew = factory->Create(config, name);
+   if ( configNew && !configNew->IsOk() )
+   {
+      // creation failed, don't return an invalid object
+      configNew->DecRef();
+      configNew = NULL;
+   }
+
+   return configNew;
 }
 
@@ -238,4 +248,7 @@
 ConfigSourceLocal::ConfigSourceLocal(const String& filename, const String& name)
                  : ConfigSource(name), m_config(NULL)
+#ifdef OS_WIN
+                   , m_usingRegConfig(false)
+#endif // OS_WIN
 {
    String localFilePath, globalFilePath;
@@ -414,4 +427,6 @@
                      );
 
+      m_usingRegConfig = true;
+
       // skip wxFileConfig creation below
       return;
@@ -439,4 +454,10 @@
 }
 
+ConfigSourceLocal::~ConfigSourceLocal()
+{
+   // don't try to recreate us
+   wxConfig::Set(NULL);
+}
+
 // ----------------------------------------------------------------------------
 // ConfigSourceLocal simple accessors
@@ -477,22 +498,55 @@
 }
 
-bool ConfigSourceLocal::GetFirstGroup(String& group, long& cookie) const
+bool ConfigSourceLocal::Flush()
+{
+   return m_config->Flush();
+}
+
+bool
+ConfigSourceLocal::GetFirstGroup(const String& key,
+                                 String& group,
+                                 EnumData& cookie) const
 {
-   return m_config->GetFirstGroup(group, cookie);
+   cookie.Key() = key;
+
+   m_config->SetPath(key);
+
+   return m_config->GetFirstGroup(group, cookie.Cookie());
+}
+
+bool ConfigSourceLocal::GetNextGroup(String& group, EnumData& cookie) const
+{
+   m_config->SetPath(cookie.Key());
+
+   return m_config->GetNextGroup(group, cookie.Cookie());
+}
+
+bool
+ConfigSourceLocal::GetFirstEntry(const String& key,
+                                 String& entry,
+                                 EnumData& cookie) const
+{
+   cookie.Key() = key;
+
+   m_config->SetPath(key);
+
+   return m_config->GetFirstEntry(entry, cookie.Cookie());
 }
 
-bool ConfigSourceLocal::GetNextGroup(String& group, long& cookie) const
+bool ConfigSourceLocal::GetNextEntry(String& entry, EnumData& cookie) const
 {
-   return m_config->GetNextGroup(group, cookie);
+   m_config->SetPath(cookie.Key());
+
+   return m_config->GetNextEntry(entry, cookie.Cookie());
 }
 
-bool ConfigSourceLocal::GetFirstEntry(String& entry, long& cookie) const
+bool ConfigSourceLocal::HasGroup(const String& path) const
 {
-   return m_config->GetFirstEntry(entry, cookie);
+   return m_config->HasGroup(path);
 }
 
-bool ConfigSourceLocal::GetNextEntry(String& entry, long& cookie) const
+bool ConfigSourceLocal::HasEntry(const String& path) const
 {
-   return m_config->GetNextEntry(entry, cookie);
+   return m_config->HasEntry(path);
 }
 
@@ -505,4 +559,52 @@
 {
    return DeleteGroup(name);
+}
+
+bool ConfigSourceLocal::CopyEntry(const String& nameSrc, const String& nameDst)
+{
+   bool rc = true;
+
+   if ( m_config->HasEntry(nameSrc) )
+   {
+      switch ( m_config->GetEntryType(nameSrc) )
+      {
+         case wxConfigBase::Type_Unknown:
+         case wxConfigBase::Type_Float:
+         case wxConfigBase::Type_Boolean:
+            wxFAIL_MSG(_T("unexpected entry type"));
+            // fall through
+
+         case wxConfigBase::Type_String:
+            // GetEntryType() returns string for all wxFileConfig entries, so
+            // try to correct it here
+            {
+               wxString val;
+               if ( m_config->Read(nameSrc, &val) )
+               {
+                  long l;
+                  if ( val.ToLong(&l) )
+                     rc = m_config->Write(nameDst, l);
+                  else
+                     rc = m_config->Write(nameDst, val);
+               }
+            }
+            break;
+
+         case wxConfigBase::Type_Integer:
+            {
+               long l;
+               rc = m_config->Read(nameSrc, &l) && m_config->Write(nameDst, l);
+            }
+            break;
+      }
+   }
+
+   return rc;
+}
+
+bool
+ConfigSourceLocal::RenameGroup(const String& nameOld, const String& nameNew)
+{
+   return m_config->RenameGroup(nameOld, nameNew);
 }
 



-------------------------------------------------------
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

Reply via email to