basic wrapping of Annotations
[mussa.git] / alg / annotations.hpp
index 203456b19da3b3f49465b80a3d211736e5872cc5..132b865346b2862c6d975cc25779a38ac1517a66 100644 (file)
@@ -22,16 +22,22 @@ protected:
   static const std::string name_str;
 
 public:
-  typedef std::map<std::string, std::string> metadata_map;
+  typedef std::string key_type;
+  typedef std::string mapped_type;
+  typedef std::map<key_type, mapped_type> metadata_map;
+  typedef metadata_map::iterator iterator;
+  typedef metadata_map::const_iterator const_iterator;
   typedef metadata_map::size_type size_type;
   
   Annotations();
-  Annotations(const std::string& n);
+  Annotations(const std::string n);
   Annotations(const Annotations&);
   Annotations(const AnnotationsRef);
 
   //! make a shared pointer copy of our object
   AnnotationsRef copy() const;
+
+  mapped_type& operator[](const key_type& k) { return metadata[k]; }
     
   //! provide a special case for accessing a name
   std::string name() const { return metadata.find(name_str)->second; }
@@ -40,16 +46,28 @@ public:
   
   //! Generic metadata handling
   //@{
+  //! begin iterator
+  iterator begin() { return metadata.begin(); }
+  //! const begin iterator
+  const_iterator begin() const { return metadata.begin(); }
+  //! end iterator
+  iterator end() { return metadata.end(); }
+  //! const end iterator
+  const_iterator end() const { return metadata.end(); }
   //! remove some key from our "dictionary"
   void erase(const std::string& key);  
+  //! find an element in the map
+  iterator find( const key_type& key) { return metadata.find(key); }
+  const_iterator find( const key_type& key) const { return metadata.find(key); }
   //! set a metadata element 
-  void set(const std::string& key, const std::string &value );
+  void set(const std::string key, const std::string value );
   //! look for a key, \throws annotation_key_error if it doesn't find it
-  std::string get(const std::string& key) const;
+  std::string get(const std::string key) const;
+  //! look for a key, if not found return default
+  std::string getdefault(const std::string key, std::string default_value) const;
   //! check for a key
-  bool has_key(const std::string& key) const;
-  //! return all the keys of our metadata map
-  //std::list<std::string> keys() const;
+  bool has_key(const std::string key) const;
+  //! return number of items in the map
   size_type size() const { return metadata.size(); }
   //@}
 protected: