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 
58  void pop();
59 
60  void set(const IWORKStylePtr_t &style);
61 
62  template<class Property>
63  bool has(const bool lookInParent = true) const
64  {
65  for (Stack_t::const_iterator it = m_stack.begin(); m_stack.end() != it; ++it)
66  {
67  if (*it)
68  {
69  if ((*it)->getPropertyMap().has<Property>(lookInParent))
70  return true;
71  else if ((*it)->getPropertyMap().clears<Property>(lookInParent))
72  break;
73  }
74  }
75  return false;
76  }
77 
78  template<class Property>
79  const typename IWORKPropertyInfo<Property>::ValueType &get(const bool lookInParent = true) const
80  {
81  for (Stack_t::const_iterator it = m_stack.begin(); m_stack.end() != it; ++it)
82  {
83  if (*it)
84  {
85  if ((*it)->getPropertyMap().has<Property>(lookInParent))
86  return (*it)->getPropertyMap().get<Property>(lookInParent);
87  else if ((*it)->getPropertyMap().clears<Property>(lookInParent))
88  break;
89  }
90  }
92  }
93 
94 private:
95  Stack_t m_stack;
96 };
97 
98 }
99 
100 #endif // IWORKSTYLESTACK_H_INCLUDED
101 
102 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Definition: IWORKBezierElement.cpp:18
boost::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition: IWORKStyle_fwd.h:21
Representation of a dynamic inheritance of styles.
Definition: IWORKStyleStack.h:34
void set(const IWORKStylePtr_t &style)
Definition: IWORKStyleStack.cpp:40
Definition: IWORKToken.h:179
Definition: IWORKPropertyMap.h:26
Definition: IWORKPropertyInfo.h:21
void pop()
Pop a style from the active styles stack.
Definition: IWORKStyleStack.cpp:35
Stack_t m_stack
Definition: IWORKStyleStack.h:95
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
bool has(const bool lookInParent=true) const
Definition: IWORKStyleStack.h:63
~IWORKStyleStack()
Definition: IWORKStyleStack.cpp:24
IWORKStyleStack()
Construct an empty context.
Definition: IWORKStyleStack.cpp:19

Generated for libetonyek by doxygen 1.8.8