IWORKStyleStack.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 IWORKSTYLESTACK_H_INCLUDED
11 #define IWORKSTYLESTACK_H_INCLUDED
12
13 #include <deque>
14
15 #include <boost/any.hpp>
16
17 #include "IWORKStyle.h"
18
19 namespace libetonyek
20 {
21
34 class IWORKStyleStack
35 {
41 typedef std::deque<IWORKStylePtr_t> Stack_t;
42
43 public:
46 IWORKStyleStack();
47
48 ~IWORKStyleStack();
49
54 void push();
55
60 void push(const IWORKStylePtr_t &style);
61
64 void pop();
65
66 void set(const IWORKStylePtr_t &style);
67
68 template<class Property>
69 bool has(const bool lookInParent = true) const
70 {
71 for (auto it = m_stack.begin(); m_stack.end() != it; ++it)
72 {
73 if (*it)
74 {
75 if ((*it)->getPropertyMap().has<Property>(lookInParent))
76 return true;
77 else if ((*it)->getPropertyMap().clears<Property>(lookInParent))
78 break;
79 }
80 }
81 return false;
82 }
83
84 template<class Property>
85 const typename IWORKPropertyInfo<Property>::ValueType &get(const bool lookInParent = true) const
86 {
87 for (auto it = m_stack.begin(); m_stack.end() != it; ++it)
88 {
89 if (*it)
90 {
91 if ((*it)->getPropertyMap().has<Property>(lookInParent))
92 return (*it)->getPropertyMap().get<Property>(lookInParent);
93 else if ((*it)->getPropertyMap().clears<Property>(lookInParent))
94 break;
95 }
96 }
97 throw IWORKPropertyMap::NotFoundException();
98 }
99
100 private:
101 Stack_t m_stack;
102 };
103
104 }
105
106 #endif // IWORKSTYLESTACK_H_INCLUDED
107
108 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libetonyek
Definition: IWORKBezierElement.cpp:20
libetonyek::IWORKStyleStack
Representation of a dynamic inheritance of styles.
Definition: IWORKStyleStack.h:34
libetonyek::IWORKStylePtr_t
std::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition: IWORKStyle_fwd.h:21
libetonyek::IWORKPropertyMap::NotFoundException
Definition: IWORKPropertyMap.h:27
libetonyek::IWORKToken::style
Definition: IWORKToken.h:414
IWORKStyle.h
libetonyek::IWORKPropertyInfo
Definition: IWORKPropertyInfo.h:21
libetonyek::IWORKStyleStack::has
bool has(const bool lookInParent=true) const
Definition: IWORKStyleStack.h:69
libetonyek::IWORKStyleStack::pop
void pop()
Pop a style from the active styles stack.
Definition: IWORKStyleStack.cpp:40
libetonyek::IWORKStyleStack::m_stack
Stack_t m_stack
Definition: IWORKStyleStack.h:101
libetonyek::IWORKStyleStack::Stack_t
std::deque< IWORKStylePtr_t > Stack_t
The internal type of style stack.
Definition: IWORKStyleStack.h:41
libetonyek::IWORKStyleStack::push
void push()
Push a style onto the active styles stack.
Definition: IWORKStyleStack.cpp:30
libetonyek::IWORKStyleStack::~IWORKStyleStack
~IWORKStyleStack()
Definition: IWORKStyleStack.cpp:24
libetonyek::IWORKStyleStack::IWORKStyleStack
IWORKStyleStack()
Construct an empty context.
Definition: IWORKStyleStack.cpp:19