[gnote] don't put shared_ptr in the Trie. Use weak_ptr<> instead.



commit 505171b0ab9b94701861b93ad6ac399ef13fc3fa
Author: Hubert Figuiere <hub figuiere net>
Date:   Wed May 13 13:25:13 2009 -0400

    don't put shared_ptr in the Trie. Use weak_ptr<> instead.
---
 src/note.hpp        |    1 +
 src/notemanager.cpp |    8 ++++----
 src/notemanager.hpp |    2 +-
 src/notewindow.cpp  |    2 +-
 src/watchers.cpp    |   12 ++++++------
 src/watchers.hpp    |    2 +-
 6 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/note.hpp b/src/note.hpp
index b9d10d5..3357cd0 100644
--- a/src/note.hpp
+++ b/src/note.hpp
@@ -113,6 +113,7 @@ class Note
 {
 public:
   typedef std::tr1::shared_ptr<Note> Ptr;
+  typedef std::tr1::weak_ptr<Note> WeakPtr;
   typedef std::list<Ptr> List;
 
   typedef sigc::signal<void, const Note::Ptr&, const std::string& > RenamedHandler;
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index c2d8d6c..ae18526 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -54,7 +54,7 @@ namespace gnote {
     ~TrieController();
 
     void update();
-    TrieTree<Note::Ptr> *title_trie() const
+    TrieTree<Note::WeakPtr> *title_trie() const
       {
         return m_title_trie;
       }
@@ -64,7 +64,7 @@ namespace gnote {
     void on_note_renamed (const Note::Ptr & renamed, const std::string & old_title);
       
     NoteManager & m_manager;
-    TrieTree<Note::Ptr> *    m_title_trie;
+    TrieTree<Note::WeakPtr> *    m_title_trie;
   };
 
   bool compare_dates(const Note::Ptr & a, const Note::Ptr & b)
@@ -584,7 +584,7 @@ namespace gnote {
   }
 
 
-  TrieHit<Note::Ptr>::ListPtr NoteManager::find_trie_matches(const std::string & match)
+  TrieHit<Note::WeakPtr>::ListPtr NoteManager::find_trie_matches(const std::string & match)
   {
     return m_trie_controller->title_trie()->find_matches(match);
   }
@@ -649,7 +649,7 @@ namespace gnote {
     if(m_title_trie) {
       delete m_title_trie;
     }
-    m_title_trie = new TrieTree<Note::Ptr>(false /* !case_sensitive */);
+    m_title_trie = new TrieTree<Note::WeakPtr>(false /* !case_sensitive */);
 
     for(Note::List::const_iterator iter =  m_manager.get_notes().begin();
         iter !=  m_manager.get_notes().end(); ++iter) {
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index 069c91f..124d2be 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -57,7 +57,7 @@ namespace gnote {
 
     // the trie for the note names
     size_t trie_max_length();
-    TrieHit<Note::Ptr>::ListPtr find_trie_matches(const std::string &);
+    TrieHit<Note::WeakPtr>::ListPtr find_trie_matches(const std::string &);
 
     AddinManager & get_addin_manager()
       {
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 53e79f6..f7598e1 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -1088,7 +1088,7 @@ namespace gnote {
     , m_normal(m_fontsize_group, _("_Normal"), true)
     , m_huge(m_fontsize_group, Glib::ustring("<span size=\"x-large\">")
              + _("Hu_ge") + "</span>", true)
-  , m_large(m_fontsize_group, Glib::ustring("<span size=\"large\">")
+    , m_large(m_fontsize_group, Glib::ustring("<span size=\"large\">")
             + _("_Large") + "</span>", true)
        ,  m_small(m_fontsize_group, Glib::ustring("<span size=\"small\">")
                   + _("S_mall") + "</span>", true)
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 93df652..660fca7 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -774,13 +774,13 @@ namespace gnote {
   }
 
   
-  void NoteLinkWatcher::do_highlight(const TrieHit<Note::Ptr> & hit, 
+  void NoteLinkWatcher::do_highlight(const TrieHit<Note::WeakPtr> & hit,
                                      const Gtk::TextIter & start,
                                      const Gtk::TextIter &)
   {
     // Some of these checks should be replaced with fixes to
     // TitleTrie.FindMatches, probably.
-    if (!hit.value) {
+    if (hit.value.expired()) {
       DBG_OUT("DoHighlight: null pointer error for '%s'." , hit.key.c_str());
       return;
     }
@@ -790,7 +790,7 @@ namespace gnote {
       return;
     }
       
-    Note::Ptr hit_note = hit.value;
+    Note::Ptr hit_note(hit.value);
 
     if (sharp::string_to_lower(hit.key) != sharp::string_to_lower(hit_note->get_title())) { // == 0 if same string  
       DBG_OUT ("DoHighlight: '%s' links wrongly to note '%s'." , hit.key.c_str(), 
@@ -838,7 +838,7 @@ namespace gnote {
       if (idx < 0)
         break;
 
-      TrieHit<Note::Ptr> hit(idx, idx + find_title_lower.length(),
+      TrieHit<Note::WeakPtr> hit(idx, idx + find_title_lower.length(),
                              find_title_lower, find_note);
       do_highlight (hit, start, end);
 
@@ -851,8 +851,8 @@ namespace gnote {
   void NoteLinkWatcher::highlight_in_block(const Gtk::TextIter & start,
                                            const Gtk::TextIter & end)
   {
-    TrieHit<Note::Ptr>::ListPtr hits = manager().find_trie_matches (start.get_slice (end));
-    for(TrieHit<Note::Ptr>::List::const_iterator iter = hits->begin();
+    TrieHit<Note::WeakPtr>::ListPtr hits = manager().find_trie_matches (start.get_slice (end));
+    for(TrieHit<Note::WeakPtr>::List::const_iterator iter = hits->begin();
         iter != hits->end(); ++iter) {
       do_highlight (**iter, start, end);
     }
diff --git a/src/watchers.hpp b/src/watchers.hpp
index be03b24..2be76b6 100644
--- a/src/watchers.hpp
+++ b/src/watchers.hpp
@@ -175,7 +175,7 @@ namespace gnote {
     void on_note_added(const Note::Ptr &);
     void on_note_deleted(const Note::Ptr &);
     void on_note_renamed(const Note::Ptr&, const std::string&);
-    void do_highlight(const TrieHit<Note::Ptr> & , const Gtk::TextIter &,const Gtk::TextIter &);
+    void do_highlight(const TrieHit<Note::WeakPtr> & , const Gtk::TextIter &,const Gtk::TextIter &);
     void highlight_note_in_block (const Note::Ptr &, const Gtk::TextIter &,
                                   const Gtk::TextIter &);
     void highlight_in_block(const Gtk::TextIter &,const Gtk::TextIter &);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]