607d6cb46d9ad81417f350fe9c950f11a21e8c24
[mussa.git] / alg / annotations.hpp
1 #ifndef ANNOTATIONS_HPP_
2 #define ANNOTATIONS_HPP_
3
4 #include <string>
5 #include <map>
6
7 #include <boost/shared_ptr.hpp>
8
9 #include "mussa_exceptions.hpp"
10
11 class Annotations;
12 typedef boost::shared_ptr<Annotations> AnnotationsRef;
13
14 /**
15  * \brief Annotations provides a simple "dictionary" of name value pairs
16  * 
17  * The intent is that this is to be used as a mix-in class to add
18  * a uniform way of storing annotation metadata.
19  */
20 class Annotations {
21 protected:
22   static const std::string name_str;
23
24 public:
25   typedef std::map<std::string, std::string> metadata_map;
26   typedef metadata_map::size_type size_type;
27   
28   Annotations();
29   Annotations(const std::string n);
30   Annotations(const Annotations&);
31   Annotations(const AnnotationsRef);
32
33   //! make a shared pointer copy of our object
34   AnnotationsRef copy() const;
35     
36   //! provide a special case for accessing a name
37   std::string name() const { return metadata.find(name_str)->second; }
38   //! special case for setting name
39   void setName(const std::string& n) { metadata[name_str] = n; }
40   
41   //! Generic metadata handling
42   //@{
43   //! remove some key from our "dictionary"
44   void erase(const std::string& key);  
45   //! set a metadata element 
46   void set(const std::string key, const std::string value );
47   //! look for a key, \throws annotation_key_error if it doesn't find it
48   std::string get(const std::string key) const;
49   //! look for a key, if not found return default
50   std::string getdefault(const std::string key, std::string default_value) const;
51   //! check for a key
52   bool has_key(const std::string key) const;
53   //! return all the keys of our metadata map
54   //std::list<std::string> keys() const;
55   size_type size() const { return metadata.size(); }
56   //@}
57 protected:
58   metadata_map metadata;
59 };
60 #endif /*ANNOTATIONS_HPP_*/