[gnote] Do not use dynamic map in Tag.



commit a0c7d0a16b644244091c6133fa0494de46317147
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Fri Feb 7 23:25:25 2014 +0200

    Do not use dynamic map in Tag.

 src/tag.cpp |   25 +++++++------------------
 src/tag.hpp |    8 ++++----
 2 files changed, 11 insertions(+), 22 deletions(-)
---
diff --git a/src/tag.cpp b/src/tag.cpp
index 014ec69..46e6a4d 100644
--- a/src/tag.cpp
+++ b/src/tag.cpp
@@ -34,37 +34,26 @@ namespace gnote {
 
   const char * Tag::SYSTEM_TAG_PREFIX = "system:";
 
-  class Tag::NoteMap
-    : public std::map<std::string, Note *>
-  {
-  };
-
   Tag::Tag(const std::string & _name)
     : m_issystem(false)
     , m_isproperty(false)
-    , m_notes(new NoteMap)
   {
     set_name(_name);
   }
 
-  Tag::~Tag()
-  {
-    delete m_notes;
-  }
-
   void Tag::add_note(Note & note)
   {
-    if(m_notes->find(note.uri()) == m_notes->end()) {
-      (*m_notes)[note.uri()] = &note;
+    if(m_notes.find(note.uri()) == m_notes.end()) {
+      m_notes[note.uri()] = &note;
     }
   }
 
 
   void Tag::remove_note(const Note & note)
   {
-    NoteMap::iterator iter = m_notes->find(note.uri());
-    if(iter != m_notes->end()) {
-      m_notes->erase(iter);
+    NoteMap::iterator iter = m_notes.find(note.uri());
+    if(iter != m_notes.end()) {
+      m_notes.erase(iter);
     }
   }
 
@@ -89,13 +78,13 @@ namespace gnote {
 
   void Tag::get_notes(std::list<Note *> & l) const
   {
-    sharp::map_get_values(*m_notes, l);
+    sharp::map_get_values(m_notes, l);
   }
 
 
   int Tag::popularity() const
   {
-    return m_notes->size();
+    return m_notes.size();
   }
 
 }
diff --git a/src/tag.hpp b/src/tag.hpp
index 82acb4f..98b7ba7 100644
--- a/src/tag.hpp
+++ b/src/tag.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (C) 2013-2014 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -25,6 +25,7 @@
 #define __TAG_HPP_
 
 #include <list>
+#include <map>
 #include <string>
 
 #include "base/macros.hpp"
@@ -40,7 +41,6 @@ namespace gnote {
     static const char * SYSTEM_TAG_PREFIX;
 
     Tag(const std::string & name);
-    ~Tag();
 
     // <summary>
     // Associates the specified note with this tag.
@@ -92,7 +92,6 @@ namespace gnote {
 /////
 
   private:
-    class NoteMap;
     std::string m_name;
     std::string m_normalized_name;
     bool        m_issystem;
@@ -101,7 +100,8 @@ namespace gnote {
     // Used to track which notes are currently tagged by this tag.  The
     // dictionary key is the Note.Uri.
     // </summary>
-    NoteMap *   m_notes;
+    typedef std::map<std::string, Note*> NoteMap;
+    NoteMap m_notes;
   };
 
 


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