IWORKStyleContainer.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 IWORKSTYLECONTAINER_H_INCLUDED
11 #define IWORKSTYLECONTAINER_H_INCLUDED
12 
13 #include <memory>
14 #include <string>
15 
16 #include <boost/optional.hpp>
17 
18 #include "IWORKStyle_fwd.h"
19 #include "IWORKStyleContext.h"
20 #include "IWORKToken.h"
21 #include "IWORKXMLParserState.h"
22 
23 #include "IWORKXMLContextBase.h"
24 
25 namespace libetonyek
26 {
27 
28 template<int TokenId, int RefTokenId, int TokenId2=0, int RefTokenId2=0>
30 {
31 public:
34 
35 protected:
36  IWORKXMLContextPtr_t element(int name) override;
37  void endOfElement() override;
38 
39 private:
42 
45  std::shared_ptr<IWORKStyleContext> m_context;
46  boost::optional<ID_t> m_ref;
48  boost::optional<ID_t> m_ref2;
49 };
50 
51 template<int TokenId, int RefTokenId, int TokenId2, int RefTokenId2>
54  , m_style(style)
55  , m_styleMap(styleMap)
56  , m_context()
57  , m_ref()
58  , m_styleMap2(nullptr)
59  , m_ref2()
60 {
61 }
62 
63 template<int TokenId, int RefTokenId, int TokenId2, int RefTokenId2>
66  , m_style(style)
67  , m_styleMap(styleMap)
68  , m_context()
69  , m_ref()
70  , m_styleMap2(&styleMap2)
71  , m_ref2()
72 {
73 }
74 
75 template<int TokenId, int RefTokenId, int TokenId2, int RefTokenId2>
77 {
78  switch (name)
79  {
80  case TokenId :
81  m_context = std::make_shared<IWORKStyleContext>(getState(), &m_styleMap);
82  return m_context;
83  case RefTokenId :
84  return std::make_shared<IWORKRefContext>(getState(), m_ref);
86  return IWORKXMLContextPtr_t();
87  case IWORKToken::INVALID_TOKEN: // TokenId2 and RefTokenId2 are optional, so avoid unintentional match
88  break;
89  default:
90  if (!name) break;
91  if (name==TokenId2)
92  {
93  m_context = std::make_shared<IWORKStyleContext>(getState(), m_styleMap2);
94  return m_context;
95  }
96  if (name==RefTokenId2)
97  return std::make_shared<IWORKRefContext>(getState(), m_ref2);
98  break;
99  }
100  ETONYEK_DEBUG_MSG(("IWORKStyleContainer<...>::element: unknown element %d\n", name));
101  return IWORKXMLContextPtr_t();
102 }
103 
104 template<int TokenId, int RefTokenId, int TokenId2, int RefTokenId2>
106 {
107  if (m_ref)
108  m_style = getState().getStyleByName(get(m_ref).c_str(), m_styleMap);
109  else if (m_ref2 && m_styleMap2)
110  m_style = getState().getStyleByName(get(m_ref2).c_str(), *m_styleMap2);
111  else if (m_context)
112  m_style=m_context->getStyle();
113 }
114 
115 }
116 
117 #endif // IWORKSTYLECONTAINER_H_INCLUDED
118 
119 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
#define ETONYEK_DEBUG_MSG(M)
Definition: libetonyek_utils.h:54
std::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition: IWORKXMLContext.h:18
IWORKStyleContainer(IWORKXMLParserState &state, IWORKStylePtr_t &style, IWORKStyleMap_t &styleMap)
Definition: IWORKStyleContainer.h:52
void endOfElement() override
Definition: IWORKStyleContainer.h:105
Definition: IWORKToken.h:335
std::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition: IWORKStyle_fwd.h:21
boost::optional< ID_t > m_ref
Definition: IWORKPathElement.cpp:285
IWORKStylePtr_t & m_style
Definition: IWORKStyleContainer.h:43
boost::optional< ID_t > m_ref
Definition: IWORKStyleContainer.h:46
IWORKStyleMap_t * m_styleMap2
Definition: IWORKStyleContainer.h:47
Definition: IWORKToken.h:421
std::shared_ptr< IWORKXMLContext > m_context
Definition: IWORKPropertyMapElement.cpp:90
Definition: IWORKToken.h:696
const char * name
Definition: IWORKToken.cpp:43
Definition: IWORKToken.h:27
Definition: IWORKXMLContextBase.h:27
Definition: IWORKXMLParserState.h:31
Definition: IWORKStyleContainer.h:29
IWORKStyleContainer & operator=(IWORKStyleContainer const &)
std::shared_ptr< IWORKStyleContext > m_context
Definition: IWORKStyleContainer.h:45
IWORKXMLContextPtr_t element(int name) override
Definition: IWORKStyleContainer.h:76
boost::optional< ID_t > m_ref2
Definition: IWORKStyleContainer.h:48
IWORKStyleMap_t & m_styleMap
Definition: IWORKStyleContainer.h:44
std::unordered_map< ID_t, IWORKStylePtr_t > IWORKStyleMap_t
Definition: IWORKStyle_fwd.h:24
IWORKStylePtr_t m_style
Definition: IWORKPropertyMapElement.cpp:172

Generated for libetonyek by doxygen 1.8.6