IWORKStyleStack.h Source File documentation

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