1 #ifndef ANNOTATIONS_HPP_
2 #define ANNOTATIONS_HPP_
7 #include <boost/shared_ptr.hpp>
9 #include "mussa_exceptions.hpp"
12 typedef boost::shared_ptr<Annotations> AnnotationsRef;
15 * \brief Annotations provides a simple "dictionary" of name value pairs
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.
22 static const std::string name_str;
25 typedef std::string key_type;
26 typedef std::string mapped_type;
27 typedef std::map<key_type, mapped_type> metadata_map;
28 typedef metadata_map::iterator iterator;
29 typedef metadata_map::const_iterator const_iterator;
30 typedef metadata_map::size_type size_type;
33 Annotations(const std::string n);
34 Annotations(const Annotations&);
35 Annotations(const AnnotationsRef);
37 //! make a shared pointer copy of our object
38 AnnotationsRef copy() const;
40 mapped_type& operator[](const key_type& k) { return metadata[k]; }
42 //! provide a special case for accessing a name
43 std::string name() const { return metadata.find(name_str)->second; }
44 //! special case for setting name
45 void setName(const std::string& n) { metadata[name_str] = n; }
47 //! Generic metadata handling
50 iterator begin() { return metadata.begin(); }
51 //! const begin iterator
52 const_iterator begin() const { return metadata.begin(); }
54 iterator end() { return metadata.end(); }
55 //! const end iterator
56 const_iterator end() const { return metadata.end(); }
57 //! remove some key from our "dictionary"
58 void erase(const std::string& key);
59 //! find an element in the map
60 iterator find( const key_type& key) { return metadata.find(key); }
61 const_iterator find( const key_type& key) const { return metadata.find(key); }
62 //! set a metadata element
63 void set(const std::string key, const std::string value );
64 //! look for a key, \throws annotation_key_error if it doesn't find it
65 std::string get(const std::string key) const;
66 //! look for a key, if not found return default
67 std::string getdefault(const std::string key, std::string default_value) const;
69 bool has_key(const std::string key) const;
70 //! return number of items in the map
71 size_type size() const { return metadata.size(); }
74 metadata_map metadata;
76 #endif /*ANNOTATIONS_HPP_*/