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

Modified Files:
        AdbDialogs.cpp AdbExport.cpp ExportPalm.cpp ExportText.cpp 
        ExportVCard.cpp ProvBbdb.cpp ProvDummy.cpp ProvFC.cpp 
        ProvLine.cpp ProvPalm.cpp ProvPasswd.cpp 
Log Message:
Resolved cyclic ref counting in LineBook and brought WeakRef to usable state

Index: AdbDialogs.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/AdbDialogs.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -b -u -2 -r1.28 -r1.29
--- AdbDialogs.cpp      3 Oct 2003 21:58:30 -0000       1.28
+++ AdbDialogs.cpp      16 Oct 2003 10:29:23 -0000      1.29
@@ -637,5 +637,5 @@
 }
 
-bool AdbShowExportDialog(const AdbEntryGroup& group)
+bool AdbShowExportDialog(AdbEntryGroup& group)
 {
    wxArrayString names, descs;

Index: AdbExport.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/AdbExport.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -b -u -2 -r1.5 -r1.6
--- AdbExport.cpp       18 Sep 2003 16:30:46 -0000      1.5
+++ AdbExport.cpp       16 Oct 2003 10:29:23 -0000      1.6
@@ -40,5 +40,5 @@
 // ----------------------------------------------------------------------------
 
-bool AdbExport(const AdbEntryGroup& group,
+bool AdbExport(AdbEntryGroup& group,
                AdbExporter& exporter)
 {

Index: ExportPalm.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ExportPalm.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -b -u -2 -r1.15 -r1.16
--- ExportPalm.cpp      12 Oct 2003 22:03:37 -0000      1.15
+++ ExportPalm.cpp      16 Oct 2003 10:29:23 -0000      1.16
@@ -48,5 +48,5 @@
 {
 public:
-   virtual bool Export(const AdbEntryGroup& group, const String& dest);
+   virtual bool Export(AdbEntryGroup& group, const String& dest);
    virtual bool Export(const AdbEntry& entry, const String& dest);
 
@@ -59,5 +59,5 @@
                              bool includeEmpty, bool includeComments);
 
-   static bool DoExportGroup(const AdbEntryGroup& group,
+   static bool DoExportGroup(AdbEntryGroup& group,
                              wxFFile& file, wxString const &category,
                              bool includeEmpty, bool includeComments);
@@ -255,5 +255,5 @@
 #undef ADDP
 
-bool AdbPalmExporter::DoExportGroup(const AdbEntryGroup& group,
+bool AdbPalmExporter::DoExportGroup(AdbEntryGroup& group,
                                     wxFFile& file, const wxString &
                                     category, bool includeEmpty,
@@ -297,5 +297,5 @@
 }
 
-bool AdbPalmExporter::Export(const AdbEntryGroup& group, const String& dest)
+bool AdbPalmExporter::Export(AdbEntryGroup& group, const String& dest)
 {
    // try to guess a reasonable default name for the file to create

Index: ExportText.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ExportText.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -b -u -2 -r1.12 -r1.13
--- ExportText.cpp      12 Oct 2003 22:03:37 -0000      1.12
+++ ExportText.cpp      16 Oct 2003 10:29:23 -0000      1.13
@@ -52,5 +52,5 @@
 {
 public:
-   virtual bool Export(const AdbEntryGroup& group, const String& dest);
+   virtual bool Export(AdbEntryGroup& group, const String& dest);
    virtual bool Export(const AdbEntry& entry, const String& dest);
 
@@ -69,5 +69,5 @@
                              const wxString& delimiter);
 
-   static bool DoExportGroup(const AdbEntryGroup& group,
+   static bool DoExportGroup(AdbEntryGroup& group,
                              wxFFile& file,
                              const wxString& delimiter);
@@ -201,5 +201,5 @@
 }
 
-bool AdbTextExporter::DoExportGroup(const AdbEntryGroup& group,
+bool AdbTextExporter::DoExportGroup(AdbEntryGroup& group,
                                     wxFFile& file,
                                     const wxString& delimiter)
@@ -240,5 +240,5 @@
 }
 
-bool AdbTextExporter::Export(const AdbEntryGroup& group, const String& dest)
+bool AdbTextExporter::Export(AdbEntryGroup& group, const String& dest)
 {
    // try to guess a reasonable default name for the file to create

Index: ExportVCard.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ExportVCard.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -b -u -2 -r1.3 -r1.4
--- ExportVCard.cpp     12 Oct 2003 22:03:37 -0000      1.3
+++ ExportVCard.cpp     16 Oct 2003 10:29:23 -0000      1.4
@@ -46,5 +46,5 @@
 {
 public:
-   virtual bool Export(const AdbEntryGroup& group, const String& dest);
+   virtual bool Export(AdbEntryGroup& group, const String& dest);
    virtual bool Export(const AdbEntry& entry, const String& dest);
 
@@ -54,5 +54,5 @@
                              const wxString& filename);
 
-   static bool DoExportGroup(const AdbEntryGroup& group,
+   static bool DoExportGroup(AdbEntryGroup& group,
                              const wxString& dirname);
 
@@ -225,5 +225,5 @@
 }
 
-bool AdbVCardExporter::DoExportGroup(const AdbEntryGroup& group,
+bool AdbVCardExporter::DoExportGroup(AdbEntryGroup& group,
                                      const wxString& dirname)
 {
@@ -281,5 +281,5 @@
 // ----------------------------------------------------------------------------
 
-bool AdbVCardExporter::Export(const AdbEntryGroup& group, const String& dest)
+bool AdbVCardExporter::Export(AdbEntryGroup& group, const String& dest)
 {
    wxString dirname = dest;

Index: ProvBbdb.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvBbdb.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -b -u -2 -r1.36 -r1.37
--- ProvBbdb.cpp        19 Sep 2003 13:31:20 -0000      1.36
+++ ProvBbdb.cpp        16 Oct 2003 10:29:23 -0000      1.37
@@ -180,8 +180,8 @@
    virtual size_t GetGroupNames(wxArrayString& aNames) const;
 
-   virtual AdbEntry *GetEntry(const String& name) const;
+   virtual AdbEntry *GetEntry(const String& name);
    virtual AdbEntryGroup *GetGroup(const String& name) const;
 
-   virtual bool Exists(const String& path) const;
+   virtual bool Exists(const String& path);
 
    virtual AdbEntry *CreateEntry(const String& strName);
@@ -191,5 +191,5 @@
    virtual void DeleteGroup(const String& strName);
 
-   virtual AdbEntry *FindEntry(const wxChar *szName) const;
+   virtual AdbEntry *FindEntry(const wxChar *szName);
 
 private:
@@ -213,8 +213,8 @@
 
    // AdbEntryGroup
-   virtual AdbEntry *GetEntry(const String& name) const
+   virtual AdbEntry *GetEntry(const String& name)
       { return m_pRootGroup->GetEntry(name); }
 
-   virtual bool Exists(const String& path) const
+   virtual bool Exists(const String& path)
       { return m_pRootGroup->Exists(path); }
 
@@ -237,5 +237,5 @@
       { m_pRootGroup->DeleteGroup(strName); }
 
-   virtual AdbEntry *FindEntry(const wxChar *szName) const
+   virtual AdbEntry *FindEntry(const wxChar *szName)
       { return m_pRootGroup->FindEntry(szName); }
 
@@ -878,5 +878,5 @@
 
 AdbEntry *
-BbdbEntryGroup::GetEntry(const String& name) const
+BbdbEntryGroup::GetEntry(const String& name)
 {
    MOcheck();
@@ -898,5 +898,5 @@
 
 bool
-BbdbEntryGroup::Exists(const String& path) const
+BbdbEntryGroup::Exists(const String& path)
 {
    MOcheck();
@@ -949,5 +949,5 @@
 
 AdbEntry *
-BbdbEntryGroup::FindEntry(const wxChar *szName) const
+BbdbEntryGroup::FindEntry(const wxChar *szName)
 {
    MOcheck();

Index: ProvDummy.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvDummy.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -b -u -2 -r1.26 -r1.27
--- ProvDummy.cpp       18 Sep 2003 16:30:47 -0000      1.26
+++ ProvDummy.cpp       16 Oct 2003 10:29:23 -0000      1.27
@@ -106,8 +106,8 @@
   virtual size_t GetGroupNames(wxArrayString& aNames) const;
 
-  virtual AdbEntry *GetEntry(const String& name) const;
+  virtual AdbEntry *GetEntry(const String& name);
   virtual AdbEntryGroup *GetGroup(const String& name) const;
 
-  virtual bool Exists(const String& path) const;
+  virtual bool Exists(const String& path);
 
   virtual AdbEntry *CreateEntry(const String& strName);
@@ -117,5 +117,5 @@
   virtual void DeleteGroup(const String& strName);
 
-  virtual AdbEntry *FindEntry(const wxChar *szName) const;
+  virtual AdbEntry *FindEntry(const wxChar *szName);
 
   // get the full path to our group (not '/' terminated)
@@ -142,8 +142,8 @@
 
     // AdbEntryGroup
-  virtual AdbEntry *GetEntry(const String& name) const
+  virtual AdbEntry *GetEntry(const String& name)
     { return m_pRootGroup->GetEntry(name); }
 
-  virtual bool Exists(const String& path) const
+  virtual bool Exists(const String& path)
     { return m_pRootGroup->Exists(path); }
 
@@ -166,5 +166,5 @@
     { m_pRootGroup->DeleteGroup(strName); }
 
-  virtual AdbEntry *FindEntry(const wxChar *szName) const
+  virtual AdbEntry *FindEntry(const wxChar *szName)
     { return m_pRootGroup->FindEntry(szName); }
 
@@ -299,10 +299,10 @@
 }
 
-AdbEntry *DummyEntryGroup::GetEntry(const String& /* name */) const
+AdbEntry *DummyEntryGroup::GetEntry(const String& /* name */)
 {
   return new DummyEntry((DummyEntryGroup *)this, _T("Dummy entry"));
 }
 
-bool DummyEntryGroup::Exists(const String& path) const
+bool DummyEntryGroup::Exists(const String& path)
 {
   return path == _T("Dummy entry");
@@ -334,5 +334,5 @@
 }
 
-AdbEntry *DummyEntryGroup::FindEntry(const wxChar * /* szName */) const
+AdbEntry *DummyEntryGroup::FindEntry(const wxChar * /* szName */)
 {
   return NULL;

Index: ProvFC.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvFC.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -b -u -2 -r1.44 -r1.45
--- ProvFC.cpp  2 Oct 2003 16:48:53 -0000       1.44
+++ ProvFC.cpp  16 Oct 2003 10:29:23 -0000      1.45
@@ -141,8 +141,8 @@
   virtual size_t GetGroupNames(wxArrayString& aNames) const;
 
-  virtual AdbEntry *GetEntry(const String& name) const;
+  virtual AdbEntry *GetEntry(const String& name);
   virtual AdbEntryGroup *GetGroup(const String& name) const;
 
-  virtual bool Exists(const String& path) const;
+  virtual bool Exists(const String& path);
 
   virtual AdbEntry *CreateEntry(const String& strName);
@@ -152,5 +152,5 @@
   virtual void DeleteGroup(const String& strName);
 
-  virtual AdbEntry *FindEntry(const wxChar *szName) const;
+  virtual AdbEntry *FindEntry(const wxChar *szName);
 
   // gte the config object
@@ -222,8 +222,8 @@
 
     // AdbEntryGroup
-  virtual AdbEntry *GetEntry(const String& name) const
+  virtual AdbEntry *GetEntry(const String& name)
     { return m_pRootGroup->GetEntry(name); }
 
-  virtual bool Exists(const String& path) const
+  virtual bool Exists(const String& path)
     { return m_pRootGroup->Exists(path); }
 
@@ -246,5 +246,5 @@
     { m_pRootGroup->DeleteGroup(strName); }
 
-  virtual AdbEntry *FindEntry(const wxChar *szName) const
+  virtual AdbEntry *FindEntry(const wxChar *szName)
     { return m_pRootGroup->FindEntry(szName); }
 
@@ -594,5 +594,5 @@
 }
 
-AdbEntry *FCEntryGroup::GetEntry(const String& name) const
+AdbEntry *FCEntryGroup::GetEntry(const String& name)
 {
   FCEntry *pEntry = new FCEntry((FCEntryGroup *)this, name);
@@ -605,5 +605,5 @@
 }
 
-bool FCEntryGroup::Exists(const String& path) const
+bool FCEntryGroup::Exists(const String& path)
 {
   SetOurPath();
@@ -658,5 +658,5 @@
 }
 
-AdbEntry *FCEntryGroup::FindEntry(const wxChar * /* szName */) const
+AdbEntry *FCEntryGroup::FindEntry(const wxChar * /* szName */)
 {
   return NULL;

Index: ProvLine.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvLine.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -b -u -2 -r1.7 -r1.8
--- ProvLine.cpp        4 Oct 2003 13:52:41 -0000       1.7
+++ ProvLine.cpp        16 Oct 2003 10:29:23 -0000      1.8
@@ -30,4 +30,5 @@
 
 #include <wx/file.h>
+#include <wx/hashmap.h>
 
 #include "adb/AdbEntry.h"
@@ -41,6 +42,7 @@
 // fwd decl
 class LineEntry;
+class LineEntryData;
 
-WX_DEFINE_SORTED_ARRAY(LineEntry *,LineEntryArray);
+WX_DECLARE_STRING_HASH_MAP(RefCounter<LineEntryData>,LineEntryArray);
 
 class LineBook : public AdbBook
@@ -60,7 +62,7 @@
 
    // AdbEntryGroup
-   virtual AdbEntry *GetEntry(const String& name) const;
+   virtual AdbEntry *GetEntry(const String& name);
 
-   virtual bool Exists(const String& path) const;
+   virtual bool Exists(const String& path);
 
    virtual size_t GetEntryNames(wxArrayString& names) const;
@@ -83,5 +85,5 @@
       { FAIL_MSG( _T("LineBook::DeleteGroup was called.") ); }
 
-   virtual AdbEntry *FindEntry(const wxChar *name) const;
+   virtual AdbEntry *FindEntry(const wxChar *name);
 
    // AdbBook
@@ -103,5 +105,5 @@
    virtual String GetDescription() const { return m_file; }
 
-   virtual size_t GetNumberOfEntries() const { return m_entries.GetCount(); }
+   virtual size_t GetNumberOfEntries() const { return m_entries.size(); }
 
    virtual bool IsLocal() const { return true; }
@@ -110,7 +112,4 @@
    virtual bool Flush();
    
-   int IndexByName(const String &name) const;
-   LineEntry *FindLineEntry(const String& name) const;
-   
    bool IsBad() const { return m_bad; }
    
@@ -131,4 +130,28 @@
 };
 
+// Separated from LineEntry to avoid cyclic links with LineBook
+class LineEntryData : public MObjectRC
+{
+public:
+   LineEntryData() : m_dirty(false) {}
+   
+   void GetField(size_t n, String *pstr) const;
+
+   void ClearDirty() { m_dirty = false; }
+   bool IsDirty() const { return m_dirty; }
+
+   void SetField(size_t n, const String& strValue);
+
+   int Matches(const wxChar *str, int where, int how) const;
+
+   WeakRef<LineEntry> m_handle;
+
+private:
+   String m_address;
+   bool m_dirty;
+};
+
+ostream& operator << (ostream& out, const LineEntryData& entry);
+
 // our AdbEntryData implementation
 class LineEntry : public AdbEntry
@@ -136,14 +159,17 @@
 public:
    // ctor
-   LineEntry(LineBook *parent,const String& name);
+   LineEntry(RefCounter<LineBook> parent,RefCounter<LineEntryData> data);
 
    // implement interface methods
 
    // AdbEntry
-   virtual AdbEntryGroup *GetGroup() const { return m_book; }
+   
+   // Don't call IncRef
+   virtual AdbEntryGroup *GetGroup() const { return m_book.Get(); }
 
    virtual void GetFieldInternal(size_t n, String *pstr) const
       { GetField(n, pstr); }
-   virtual void GetField(size_t n, String *pstr) const;
+   virtual void GetField(size_t n, String *pstr) const
+      { m_data->GetField(n, pstr); }
 
    virtual size_t GetEMailCount() const { return 0; }
@@ -151,8 +177,10 @@
       { FAIL_MSG( _T("LineEntry::GetEMail was called.") ); }
 
-   virtual void ClearDirty() { m_dirty = false; }
-   virtual bool IsDirty() const { return m_dirty; }
+   virtual void ClearDirty() { m_data->ClearDirty(); }
+   virtual bool IsDirty() const { return m_data->IsDirty(); }
+
+   virtual void SetField(size_t n, const String& strValue)
+      { m_data->SetField(n, strValue); }
 
-   virtual void SetField(size_t n, const String& strValue);
    virtual void AddEMail(const String&)
    {
@@ -161,20 +189,14 @@
    virtual void ClearExtraEMails() { }
 
-   virtual int Matches(const wxChar *str, int where, int how) const;
-
-   int Compare(LineEntry *right) { return m_name.compare(right->m_name); }
-   const String& GetName() const { return m_name; }
+   virtual int Matches(const wxChar *str, int where, int how) const
+      { return m_data->Matches(str, where, how); }
    
    static String StripSpace(const String &address);
 
 private:
-   LineBook *m_book;
-   String m_name;
-   String m_address;
-   bool m_dirty;
+   RefCounter<LineBook> m_book;
+   RefCounter<LineEntryData> m_data;
 };
 
-ostream& operator << (ostream& out, const LineEntry& entry);
-
 // our AdbDataProvider implementation
 class LineDataProvider : public AdbDataProvider
@@ -201,9 +223,4 @@
 // ----------------------------------------------------------------------------
 
-static int LineEntryCompare(LineEntry *left, LineEntry *right)
-{
-   return left->Compare(right);
-}
-
 // Duplicate of FCBook::GetFullAdbPath. It should be shared somehow.
 String LineBook::GetFullAdbPath(const String& filename)
@@ -221,5 +238,5 @@
 
 LineBook::LineBook(const String& file)
-   : m_file(GetFullAdbPath(file)), m_entries(LineEntryCompare)
+   : m_file(GetFullAdbPath(file))
 {
    m_bad = false;
@@ -251,25 +268,16 @@
 {
    Flush();
-   
-   for ( size_t eachEntry = m_entries.GetCount(); eachEntry > 0;
-      --eachEntry )
-   {
-      LineEntry *deleted = m_entries.Item(eachEntry-1);
-      m_entries.RemoveAt(eachEntry-1);
-      deleted->DecRef();
-   }
 }
 
-AdbEntry *LineBook::GetEntry(const String& name) const
+AdbEntry *LineBook::GetEntry(const String& name)
 {
-   LineEntry *found = FindLineEntry(name);
+   AdbEntry *found = FindEntry(name.c_str());
    CHECK( found != NULL, NULL, _T("Asked for non-existent entry.") );
-   
    return found;
 }
 
-bool LineBook::Exists(const String& path) const
+bool LineBook::Exists(const String& path)
 {
-   return IndexByName(path) != wxNOT_FOUND;
+   return m_entries.find(path) != m_entries.end();
 }
 
@@ -278,8 +286,8 @@
    names.Empty();
    
-   for ( size_t eachEntry = 0; eachEntry < m_entries.GetCount();
-      ++eachEntry )
+   for( LineEntryArray::const_iterator each = m_entries.begin();
+      each != m_entries.end(); ++each )
    {
-      names.Add(m_entries.Item(eachEntry)->GetName());
+      names.Add(each->first);
    }
    
@@ -289,32 +297,43 @@
 AdbEntry *LineBook::CreateEntry(const String& name)
 {
-   CHECK( IndexByName(name) == wxNOT_FOUND, GetEntry(name),
+   CHECK( !Exists(name), GetEntry(name),
       _T("Create entry with duplicate name.") );
    
-   LineEntry *newEntry = new LineEntry(this,name);
+   RefCounter<LineEntryData> data(new LineEntryData);
+   RefCounter<LineEntry> entry(new LineEntry(
+      RefCounter<LineBook>::Convert(this),data));
+   
+   LineEntryArray::value_type pair(name,data);
+   m_entries.insert(pair);
    
-   m_entries.Add(newEntry);
    m_dirty = true;
    
-   newEntry->IncRef();
-   return newEntry;
+   return entry.Release();
 }
 
 void LineBook::DeleteEntry(const String& name)
 {
-   int index = IndexByName(name);
-   ASSERT( index != wxNOT_FOUND );
+   LineEntryArray::iterator index = m_entries.find(name);
+   CHECK_RET( index != m_entries.end(), _T("Deleted non-existent entry") );
    
-   LineEntry *reference = m_entries.Item(index);
+   m_entries.erase(index);
    
-   m_entries.RemoveAt(index);
    m_dirty = true;
-   
-   reference->DecRef();
 }
 
-AdbEntry *LineBook::FindEntry(const wxChar *name) const
+AdbEntry *LineBook::FindEntry(const wxChar *name)
 {
-   return FindLineEntry(name);
+   LineEntryArray::iterator found = m_entries.find(name);
+   if( found == m_entries.end() )
+      return NULL;
+      
+   RefCounter<LineEntry> entry(found->second->m_handle);
+   if( !entry )
+   {
+      entry.Attach(new LineEntry(
+            RefCounter<LineBook>::Convert(this),found->second));
+   }
+
+   return entry.Release();
 }
 
@@ -348,8 +367,8 @@
          goto FileError;
       
-      for ( size_t eachEntry = 0; eachEntry < m_entries.GetCount();
-         ++eachEntry )
+      for( LineEntryArray::iterator each = m_entries.begin();
+         each != m_entries.end(); ++each )
       {
-         stream << *m_entries.Item(eachEntry);
+         stream << *each->second;
          if ( !stream.good() )
             goto FileError;
@@ -372,58 +391,11 @@
 }
 
-int LineBook::IndexByName(const String& name) const
-{
-   LineEntry *key = new LineEntry(NULL,name);
-
-#if wxCHECK_VERSION(2,5,0) // Bug in wxWindows 2.4 version of Index()
-   int index = m_entries.Index(key);
-#else
-   int low = 0; // Key is at position greater or equal to "low"
-   int high = m_entries.GetCount(); // Key is below "high"
-   while ( low < high - 1 ) // There are items to compare
-   {
-      int middle = (low + high) / 2; // Candidate key match
-      int compare = LineEntryCompare(key,m_entries.Item(middle));
-      if ( compare < 0 ) // Key is below "middle"
-         high = middle; // "high" changes
-      else if ( compare > 0 ) // Key is above "middle"
-         low = middle + 1; // "low" changes
-      else // Key is at "middle", we can set "low" and "high" exactly
-      {
-         low = middle;
-         high = middle + 1;
-      }
-   }
-   
-   int index;
-   if ( low < high && LineEntryCompare(key,m_entries.Item(low)) == 0 )
-      index = low;
-   else
-      index = wxNOT_FOUND;
-#endif
-   key->DecRef();
-   
-   return index;
-}
-
-LineEntry *LineBook::FindLineEntry(const String& name) const
-{
-   int index = IndexByName(name);
-   if ( index == wxNOT_FOUND )
-      return NULL;
-   
-   LineEntry *found = m_entries.Item(index);
-   found->IncRef();
-   
-   return found;
-}
-
 bool LineBook::IsDirty() const
 {
    bool anythingDirty = m_dirty;
-   for ( size_t eachEntry = 0; eachEntry < m_entries.GetCount();
-      ++eachEntry )
+   for( LineEntryArray::const_iterator each = m_entries.begin();
+      each != m_entries.end(); ++each )
    {
-      anythingDirty = anythingDirty || m_entries.Item(eachEntry)->IsDirty();
+      anythingDirty = anythingDirty || each->second->IsDirty();
    }
    return anythingDirty;
@@ -433,8 +405,8 @@
 {
    m_dirty = false;
-   for ( size_t eachEntry = 0; eachEntry < m_entries.GetCount();
-      ++eachEntry )
+   for( LineEntryArray::iterator each = m_entries.begin();
+      each != m_entries.end(); ++each )
    {
-      m_entries.Item(eachEntry)->ClearDirty();
+      each->second->ClearDirty();
    }
 }
@@ -455,8 +427,7 @@
       if ( nonspace.size() > 0 && !Exists(nonspace) )
       {
-         AdbEntry *add = CreateEntry(nonspace);
+         RefCounter<AdbEntry> add(CreateEntry(nonspace));
          add->SetField(AdbField_EMail, nonspace);
          add->ClearDirty();
-         add->DecRef();
       }
    }
@@ -471,12 +442,29 @@
 // ----------------------------------------------------------------------------
 
-LineEntry::LineEntry(LineBook *parent,const String& name)
+LineEntry::LineEntry(RefCounter<LineBook> parent,
+   RefCounter<LineEntryData> data)
+   : m_book(parent), m_data(data)
 {
-   m_book = parent;
-   m_name = name;
-   m_dirty = false;
+   m_data->m_handle = RefCounter<LineEntry>::Convert(this);
 }
 
-void LineEntry::GetField(size_t n, String *pstr) const
+String LineEntry::StripSpace(const String &address)
+{
+   String nonspace;
+   
+   for ( size_t character = 0; character < address.size(); ++character )
+   {
+      if ( !isspace(address[character]) )
+         nonspace.append(1, address[character]);
+   }
+
+   return nonspace;
+}
+
+// ----------------------------------------------------------------------------
+// LineEntryData
+// ----------------------------------------------------------------------------
+
+void LineEntryData::GetField(size_t n, String *pstr) const
 {
    switch ( n )
@@ -491,5 +479,5 @@
 }
 
-void LineEntry::SetField(size_t n, const String& strValue)
+void LineEntryData::SetField(size_t n, const String& strValue)
 {
    switch ( n )
@@ -507,5 +495,5 @@
 }
 
-int LineEntry::Matches(const wxChar *what, int /* where */, int how) const
+int LineEntryData::Matches(const wxChar *what, int /*where*/, int how) const
 {
    wxString whatCopy(what);
@@ -536,5 +524,5 @@
 }
 
-ostream& operator << (ostream& out, const LineEntry& entry)
+ostream& operator << (ostream& out, const LineEntryData& entry)
 {
    String address;
@@ -549,17 +537,4 @@
 }
 
-String LineEntry::StripSpace(const String &address)
-{
-   String nonspace;
-   
-   for ( size_t character = 0; character < address.size(); ++character )
-   {
-      if ( !isspace(address[character]) )
-         nonspace.append(1, address[character]);
-   }
-
-   return nonspace;
-}
-
 // ----------------------------------------------------------------------------
 // LineDataProvider
@@ -568,11 +543,7 @@
 AdbBook *LineDataProvider::CreateBook(const String& name)
 {
-   LineBook *book = new LineBook(name);
-   if ( book->IsBad() )
-   {
-      book->DecRef();
-      return NULL;
-   }
-   return book;
+   RefCounter<LineBook> book(new LineBook(name));
+   CHECK ( !book->IsBad(), NULL, _T("Cannot create LineBook") )
+   return book.Release();
 }
 

Index: ProvPalm.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvPalm.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -b -u -2 -r1.22 -r1.23
--- ProvPalm.cpp        18 Sep 2003 16:30:47 -0000      1.22
+++ ProvPalm.cpp        16 Oct 2003 10:29:23 -0000      1.23
@@ -188,5 +188,5 @@
 }
 
-AdbEntry *PalmEntryGroup::GetEntry(const String& name) const
+AdbEntry *PalmEntryGroup::GetEntry(const String& name)
 {
   PalmEntryList::iterator i;
@@ -202,5 +202,5 @@
 } 
 
-bool PalmEntryGroup::Exists(const String& path) const
+bool PalmEntryGroup::Exists(const String& path)
 {
    // TODO
@@ -263,5 +263,5 @@
 }
 
-AdbEntry *PalmEntryGroup::FindEntry(const wxChar * /* szName */) const
+AdbEntry *PalmEntryGroup::FindEntry(const wxChar * /* szName */)
 {
   // currently not supported

Index: ProvPasswd.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvPasswd.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -b -u -2 -r1.15 -r1.16
--- ProvPasswd.cpp      18 Sep 2003 16:30:47 -0000      1.15
+++ ProvPasswd.cpp      16 Oct 2003 10:29:23 -0000      1.16
@@ -113,8 +113,8 @@
    virtual size_t GetGroupNames(wxArrayString& aNames) const;
 
-   virtual AdbEntry *GetEntry(const String& name) const;
+   virtual AdbEntry *GetEntry(const String& name);
    virtual AdbEntryGroup *GetGroup(const String& name) const;
 
-   virtual bool Exists(const String& path) const;
+   virtual bool Exists(const String& path);
 
    virtual AdbEntry *CreateEntry(const String& strName);
@@ -124,5 +124,5 @@
    virtual void DeleteGroup(const String& strName);
 
-   virtual AdbEntry *FindEntry(const wxChar *szName) const;
+   virtual AdbEntry *FindEntry(const wxChar *szName);
 
 private:
@@ -154,8 +154,8 @@
 
    // AdbEntryGroup
-   virtual AdbEntry *GetEntry(const String& name) const
+   virtual AdbEntry *GetEntry(const String& name)
       { return m_pRootGroup->GetEntry(name); }
 
-   virtual bool Exists(const String& path) const
+   virtual bool Exists(const String& path)
       { return m_pRootGroup->Exists(path); }
 
@@ -178,5 +178,5 @@
       { m_pRootGroup->DeleteGroup(strName); }
 
-   virtual AdbEntry *FindEntry(const wxChar *szName) const
+   virtual AdbEntry *FindEntry(const wxChar *szName)
       { return m_pRootGroup->FindEntry(szName); }
 
@@ -342,5 +342,5 @@
 }
 
-AdbEntry *PasswdEntryGroup::GetEntry(const String& name) const
+AdbEntry *PasswdEntryGroup::GetEntry(const String& name)
 {
    int n = m_names.Index(name);
@@ -353,5 +353,5 @@
 }
 
-bool PasswdEntryGroup::Exists(const String& name) const
+bool PasswdEntryGroup::Exists(const String& name)
 {
    return m_names.Index(name) != wxNOT_FOUND;
@@ -385,5 +385,5 @@
 }
 
-AdbEntry *PasswdEntryGroup::FindEntry(const wxChar *szName) const
+AdbEntry *PasswdEntryGroup::FindEntry(const wxChar *szName)
 {
    // TODO



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to