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
19namespace libetonyek
20{
21
35{
41 typedef std::deque<IWORKStylePtr_t> Stack_t;
42
43public:
47
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 }
98 }
99
100private:
102};
103
104}
105
106#endif // IWORKSTYLESTACK_H_INCLUDED
107
108/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Definition IWORKPropertyMap.h:27
Representation of a dynamic inheritance of styles.
Definition IWORKStyleStack.h:35
void push()
Push a style onto the active styles stack.
Definition IWORKStyleStack.cpp:30
void pop()
Pop a style from the active styles stack.
Definition IWORKStyleStack.cpp:40
bool has(const bool lookInParent=true) const
Definition IWORKStyleStack.h:69
~IWORKStyleStack()
Definition IWORKStyleStack.cpp:24
std::deque< IWORKStylePtr_t > Stack_t
The internal type of style stack.
Definition IWORKStyleStack.h:41
const IWORKPropertyInfo< Property >::ValueType & get(const bool lookInParent=true) const
Definition IWORKStyleStack.h:85
Stack_t m_stack
Definition IWORKStyleStack.h:101
void set(const IWORKStylePtr_t &style)
Definition IWORKStyleStack.cpp:45
IWORKStyleStack()
Construct an empty context.
Definition IWORKStyleStack.cpp:19
@ style
Definition IWORKToken.h:421
Definition IWORKBezierElement.cpp:21
std::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition IWORKStyle_fwd.h:23
Definition IWORKPropertyInfo.h:22

Generated for libetonyek by doxygen 1.12.0