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 
35 {
41  typedef std::deque<IWORKStylePtr_t> Stack_t;
42 
43 public:
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 (Stack_t::const_iterator 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 (Stack_t::const_iterator 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 
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: */
Definition: IWORKBezierElement.cpp:18
Representation of a dynamic inheritance of styles.
Definition: IWORKStyleStack.h:34
std::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition: IWORKStyle_fwd.h:21
Definition: IWORKPropertyMap.h:27
Definition: IWORKToken.h:268
Definition: IWORKPropertyInfo.h:21
bool has(const bool lookInParent=true) const
Definition: IWORKStyleStack.h:69
void pop()
Pop a style from the active styles stack.
Definition: IWORKStyleStack.cpp:40
Stack_t m_stack
Definition: IWORKStyleStack.h:101
std::deque< IWORKStylePtr_t > Stack_t
The internal type of style stack.
Definition: IWORKStyleStack.h:41
void push()
Push a style onto the active styles stack.
Definition: IWORKStyleStack.cpp:30
~IWORKStyleStack()
Definition: IWORKStyleStack.cpp:24
IWORKStyleStack()
Construct an empty context.
Definition: IWORKStyleStack.cpp:19

Generated for libetonyek by doxygen 1.8.13