create a metadata holding class
[mussa.git] / alg / annotations.cpp
1 #include "annotations.hpp"
2
3 const std::string Annotations::name_str("name");
4
5 Annotations::Annotations()
6 {
7   metadata[name_str] = ""; 
8 }
9
10 Annotations::Annotations(const std::string &n)
11
12   metadata[name_str] = n; 
13 }
14
15 Annotations::Annotations(const Annotations& a) :
16  metadata(a.metadata) 
17 {
18 }
19
20 Annotations::Annotations(const AnnotationsRef a) :
21   metadata(a->metadata)
22 {
23
24
25 AnnotationsRef Annotations::copy() const
26 {
27   AnnotationsRef a(new Annotations(*this));
28   return a;
29 }
30
31 void Annotations::erase(const std::string& key)
32 {
33   if (key == name_str) {
34     // we must always have a name
35     metadata[key] = "";
36   } else {
37     metadata.erase(key);
38   }
39 }
40   
41 void Annotations::set(const std::string& key, const std::string &value )
42 {
43   metadata[key] = value;
44 }
45
46 std::string Annotations::get(const std::string& key) const
47 {
48   metadata_map::const_iterator map_i(metadata.find(key));
49   if (map_i == metadata.end()) {
50     throw annotations_key_error(key + " was not found");
51   } else {
52     return map_i->second;
53   }  
54 }
55
56 bool Annotations::has_key(const std::string& key) const
57 {
58   metadata_map::const_iterator map_i(metadata.find(key));
59   return map_i != metadata.end();
60 }