decoration.h
Go to the documentation of this file.
1 // (C) Copyright Renaud Detry 2007-2015.
2 // Distributed under the GNU General Public License and under the
3 // BSD 3-Clause License (See accompanying file LICENSE.txt).
4 
5 /** @file */
6 
7 #ifndef NUKLEI_DECORATION_H
8 #define NUKLEI_DECORATION_H
9 
10 
11 #include <boost/any.hpp>
12 #include <nuklei/simple_map.h>
13 #include <nuklei/Definitions.h>
14 
15 namespace nuklei {
16 
17  template<typename KeyType>
18  struct decoration
19  {
21 
22  template<typename ValueType>
23  void insert(const KeyType& key, const ValueType &v)
24  {
25  NUKLEI_TRACE_BEGIN();
26  decorations_.insert(key, v);
27  NUKLEI_TRACE_END();
28  }
29 
30  // This is not possible: we need to tell what goes inside the
31  // underlying boost::any.
32  //void insert(const KeyType& key)
33 
34  bool has_key(const KeyType& key) const
35  {
36  NUKLEI_TRACE_BEGIN();
37  return decorations_.has_key(key);
38  NUKLEI_TRACE_END();
39  }
40 
41  template<typename ValueType>
42  ValueType& get(const KeyType& key)
43  {
44  NUKLEI_TRACE_BEGIN();
45  return boost::any_cast<ValueType&>(decorations_[key]);
46  NUKLEI_TRACE_END();
47  }
48 
49  template<typename ValueType>
50  const ValueType& get(const KeyType& key) const
51  {
52  NUKLEI_TRACE_BEGIN();
53  return boost::any_cast<const ValueType&>(decorations_[key]);
54  NUKLEI_TRACE_END();
55  }
56 
57  void erase(const KeyType& key)
58  {
59  NUKLEI_TRACE_BEGIN();
60  decorations_.erase(key);
61  NUKLEI_TRACE_END();
62  }
63 
64  void clear()
65  {
66  decorations_.clear();
67  }
68 
69  private:
70  map_t decorations_;
71  };
72 
73 }
74 
75 #endif
76 
Public namespace.
Definition: Color.cpp:9
Definition: decoration.h:18
© Copyright 2007-2013 Renaud Detry.
Distributed under the terms of the GNU General Public License (GPL).
(See accompanying file LICENSE.txt or copy at http://www.gnu.org/copyleft/gpl.html.)
Revised Sun Sep 13 2020 19:10:06.