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 <unordered_map>
14#include <vector>
15
16#include <boost/any.hpp>
17
18#include "IWORKPropertyInfo.h"
19#include "IWORKStyle_fwd.h"
20
21namespace libetonyek
22{
23
27{
28public:
30
31private:
32 typedef std::unordered_map<IWORKPropertyID_t, boost::any> Map_t;
33
34public:
38
43 explicit IWORKPropertyMap(const IWORKPropertyMap *parent);
44
50
57
62 void swap(IWORKPropertyMap &other);
63
68 void setParent(const IWORKPropertyMap *parent);
69
74 void collectStyles(std::vector<const IWORKStyle *> &styles) const;
75
85 template<class Property>
86 bool has(bool lookInParent = false) const
87 {
88 for (const IWORKPropertyMap *map = this; map; map = lookInParent ? map->m_parent : nullptr)
89 {
90 const auto it = map->m_map.find(IWORKPropertyInfo<Property>::id);
91 if (map->m_map.end() != it)
92 return !it->second.empty();
93 }
94 return false;
95 }
96
97 template<class Property>
98 bool clears(bool lookInParent = false) const
99 {
100 for (const IWORKPropertyMap *map = this; map; map = lookInParent ? map->m_parent : nullptr)
101 {
102 const auto it = map->m_map.find(IWORKPropertyInfo<Property>::id);
103 if (map->m_map.end() != it)
104 return it->second.empty();
105 }
106 return false;
107 }
108
118 template<class Property>
119 const typename IWORKPropertyInfo<Property>::ValueType &get(bool lookInParent = false) const
120 {
121 for (const IWORKPropertyMap *map = this; map; map = lookInParent ? map->m_parent : nullptr)
122 {
123 const auto it = map->m_map.find(IWORKPropertyInfo<Property>::id);
124 if (map->m_map.end() != it)
125 {
126 if (!it->second.empty())
127 return boost::any_cast<const typename IWORKPropertyInfo<Property>::ValueType &>(it->second);
128 break;
129 }
130 }
131 throw NotFoundException();
132 }
133
138 template<class Property>
143
149 template<class Property>
150 void clear()
151 {
153 }
154
155private:
158};
159
160}
161
162#endif // IWORKPROPERTYMAP_H_INCLUDED
163
164/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Definition IWORKPropertyMap.h:29
std::unordered_map< IWORKPropertyID_t, boost::any > Map_t
Definition IWORKPropertyMap.h:32
void collectStyles(std::vector< const IWORKStyle * > &styles) const
Add the styles that the properties of this map hold, not looking in the parent map.
Definition IWORKPropertyMap.cpp:55
bool has(bool lookInParent=false) const
Check for the presence of a property.
Definition IWORKPropertyMap.h:86
Map_t m_map
Definition IWORKPropertyMap.h:156
IWORKPropertyMap & operator=(const IWORKPropertyMap &other)
Assign the content from another map.
Definition IWORKPropertyMap.cpp:36
void put(const typename IWORKPropertyInfo< Property >::ValueType &value)
Insert a new value for key key.
Definition IWORKPropertyMap.h:139
const IWORKPropertyMap * m_parent
Definition IWORKPropertyMap.h:157
void setParent(const IWORKPropertyMap *parent)
Set a new parent for this map.
Definition IWORKPropertyMap.cpp:50
IWORKPropertyMap()
Construct an empty map.
Definition IWORKPropertyMap.cpp:18
void clear()
Clear property.
Definition IWORKPropertyMap.h:150
const IWORKPropertyInfo< Property >::ValueType & get(bool lookInParent=false) const
Retrieve the value of a property.
Definition IWORKPropertyMap.h:119
bool clears(bool lookInParent=false) const
Definition IWORKPropertyMap.h:98
void swap(IWORKPropertyMap &other)
Swap the content with another map.
Definition IWORKPropertyMap.cpp:43
@ value
Definition IWORKToken.h:631
@ styles
Definition IWORKToken.h:423
Definition IWORKBezierElement.cpp:21
Definition IWORKPropertyInfo.h:22

Generated for libetonyek by doxygen 1.16.1