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
25namespace libetonyek
26{
27
28template<int TokenId, int RefTokenId, int TokenId2=0, int RefTokenId2=0>
30{
31public:
34
35protected:
36 IWORKXMLContextPtr_t element(int name) override;
37 void endOfElement() override;
38
39private:
42
45 std::shared_ptr<IWORKStyleContext> m_context;
46 boost::optional<ID_t> m_ref;
48 boost::optional<ID_t> m_ref2;
49};
50
51template<int TokenId, int RefTokenId, int TokenId2, int RefTokenId2>
62
63template<int TokenId, int RefTokenId, int TokenId2, int RefTokenId2>
74
75template<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
104template<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: */
IWORKStyleContainer(IWORKStyleContainer const &)
boost::optional< ID_t > m_ref2
Definition IWORKStyleContainer.h:48
IWORKStyleContainer(IWORKXMLParserState &state, IWORKStylePtr_t &style, IWORKStyleMap_t &styleMap)
Definition IWORKStyleContainer.h:52
void endOfElement() override
Signalize the end of an element.
Definition IWORKStyleContainer.h:105
boost::optional< ID_t > m_ref
Definition IWORKStyleContainer.h:46
IWORKStyleMap_t & m_styleMap
Definition IWORKStyleContainer.h:44
IWORKXMLContextPtr_t element(int name) override
Create a context for parsing a child element.
Definition IWORKStyleContainer.h:76
std::shared_ptr< IWORKStyleContext > m_context
Definition IWORKStyleContainer.h:45
IWORKStyleMap_t * m_styleMap2
Definition IWORKStyleContainer.h:47
IWORKStyleContainer & operator=(IWORKStyleContainer const &)
IWORKStylePtr_t & m_style
Definition IWORKStyleContainer.h:43
IWORKXMLParserState & getState()
Definition IWORKXMLContextBase.h:43
Definition IWORKXMLParserState.h:32
#define ETONYEK_DEBUG_MSG(M)
Definition libetonyek_utils.h:54
@ INVALID_TOKEN
Definition IWORKToken.h:27
@ element
Definition IWORKToken.h:192
@ null
Definition IWORKToken.h:335
@ style
Definition IWORKToken.h:421
@ name
Definition IWORKToken.h:585
@ NS_URI_SF
Definition IWORKToken.h:696
Definition IWORKBezierElement.cpp:21
std::unordered_map< ID_t, IWORKStylePtr_t > IWORKStyleMap_t
Definition IWORKStyle_fwd.h:24
std::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition IWORKXMLContext.h:20
IWORKXMLContextBase< IWORKXMLContextElement, IWORKXMLParserState > IWORKXMLElementContextBase
Definition IWORKXMLContextBase.h:124
const ValueT & get(const detail::IWAFieldImpl< TagV, ValueT, Reader > &field)
Definition IWAField.h:190
std::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition IWORKStyle_fwd.h:23

Generated for libetonyek by doxygen 1.13.2