torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Annotated.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Header for the Annotated class.
18 
19 #ifndef TORC_COMMON_ANNOTATED_HPP
20 #define TORC_COMMON_ANNOTATED_HPP
21 
22 #include <boost/unordered_map.hpp>
23 #include <boost/any.hpp>
24 
25 namespace torc {
26 namespace common {
27 
28  /// \brief Concept for any object that can be annotated.
29  class Annotated {
30  typedef boost::uint32_t uint32;
31  protected:
32  // members
33  /// \brief Map containing any annotations.
34  boost::unordered_map<boost::uint32_t, boost::any> mAnnotations;
35 
36  public:
37  // constructors
38  /// \brief Default constructor containing no annotations.
39  Annotated() {}
40  /// \brief Destructor.
42  // accessors
43  /// \brief Get an annotation.
44  /// \detail Returns an empty annotation if the index doesn't exist.
45  boost::any getAnnotation(uint32 inKey) { return mAnnotations[inKey]; }
46  /// \brief Set an annotation.
47  void setAnnotation(uint32 inKey, boost::any inValue) { mAnnotations[inKey] = inValue; }
48  /// \brief Remove an annotation.
49  void removeAnnotation(uint32 inKey) { mAnnotations.erase(inKey); }
50  /// \brief Check if an annotation exists.
51  bool hasAnnotation(uint32 inKey) {
52  return (mAnnotations.find(inKey) != mAnnotations.end());
53  }
54 
55  // enums
56  /// \brief Enumeration for all types of annotations.
70  };
71  };
72 
73 } // namespace common
74 } // namespace torc
75 
76 #endif // TORC_COMMON_ANNOTATED_HPP
EAnnotationType
Enumeration for all types of annotations.
Definition: Annotated.hpp:57
Annotated()
Default constructor containing no annotations.
Definition: Annotated.hpp:39
void setAnnotation(uint32 inKey, boost::any inValue)
Set an annotation.
Definition: Annotated.hpp:47
boost::any getAnnotation(uint32 inKey)
Get an annotation. Returns an empty annotation if the index doesn't exist.
Definition: Annotated.hpp:45
boost::uint32_t uint32
Definition: Annotated.hpp:30
bool hasAnnotation(uint32 inKey)
Check if an annotation exists.
Definition: Annotated.hpp:51
void removeAnnotation(uint32 inKey)
Remove an annotation.
Definition: Annotated.hpp:49
boost::unordered_map< boost::uint32_t, boost::any > mAnnotations
Map containing any annotations.
Definition: Annotated.hpp:34
~Annotated()
Destructor.
Definition: Annotated.hpp:41
Concept for any object that can be annotated.
Definition: Annotated.hpp:29