IWORKPropertyMap.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  * This file is part of the libetonyek project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #ifndef IWORKPROPERTYMAP_H_INCLUDED
11 #define IWORKPROPERTYMAP_H_INCLUDED
12 
13 #include <boost/any.hpp>
14 #include <boost/unordered_map.hpp>
15 
16 #include "IWORKPropertyInfo.h"
17 
18 namespace libetonyek
19 {
20 
24 {
25 public:
27 
28 private:
29  typedef boost::unordered_map<IWORKPropertyID_t, boost::any> Map_t;
30 
31 public:
35 
40  explicit IWORKPropertyMap(const IWORKPropertyMap *parent);
41 
46  IWORKPropertyMap(const IWORKPropertyMap &other);
47 
54 
59  void swap(IWORKPropertyMap &other);
60 
65  void setParent(const IWORKPropertyMap *parent);
66 
76  template<class Property>
77  bool has(bool lookInParent = false) const
78  {
79  const Map_t::const_iterator it = m_map.find(IWORKPropertyInfo<Property>::id);
80  if (m_map.end() != it)
81  return true;
82 
83  if (lookInParent && m_parent)
84  return m_parent->has<Property>(lookInParent);
85 
86  return false;
87  }
88 
98  template<class Property>
99  const typename IWORKPropertyInfo<Property>::ValueType &get(bool lookInParent = false) const
100  {
101  const Map_t::const_iterator it = m_map.find(IWORKPropertyInfo<Property>::id);
102  if (m_map.end() != it)
103  return boost::any_cast<const typename IWORKPropertyInfo<Property>::ValueType &>(it->second);
104 
105  if (lookInParent && m_parent)
106  return m_parent->get<Property>(lookInParent);
107 
108  throw NotFoundException();
109  }
110 
115  template<class Property>
116  void put(const typename IWORKPropertyInfo<Property>::ValueType &value)
117  {
119  }
120 
121 private:
122  Map_t m_map;
124 };
125 
126 }
127 
128 #endif // IWORKPROPERTYMAP_H_INCLUDED
129 
130 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Definition: IWORKColorElement.cpp:19
const IWORKPropertyMap * m_parent
Definition: IWORKPropertyMap.h:123
void setParent(const IWORKPropertyMap *parent)
Set a new parent for this map.
Definition: IWORKPropertyMap.cpp:47
Represents a (hierarchical) property map.
Definition: IWORKPropertyMap.h:23
void swap(IWORKPropertyMap &other)
Swap the content with another map.
Definition: IWORKPropertyMap.cpp:40
Definition: IWORKPropertyMap.h:26
boost::unordered_map< IWORKPropertyID_t, boost::any > Map_t
Definition: IWORKPropertyMap.h:29
Definition: IWORKPropertyInfo.h:21
IWORKPropertyMap()
Construct an empty map.
Definition: IWORKPropertyMap.cpp:15
Map_t m_map
Definition: IWORKPropertyMap.h:122
IWORKPropertyMap & operator=(const IWORKPropertyMap &other)
Assign the content from another map.
Definition: IWORKPropertyMap.cpp:33
bool has(bool lookInParent=false) const
Check for the presence of a property.
Definition: IWORKPropertyMap.h:77
void put(const typename IWORKPropertyInfo< Property >::ValueType &value)
Insert a new value for key .
Definition: IWORKPropertyMap.h:116
const IWORKPropertyInfo< Property >::ValueType & get(bool lookInParent=false) const
Retrieve the value of a property.
Definition: IWORKPropertyMap.h:99

Generated for libetonyek by doxygen 1.8.8