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 default:
88 // TokenId2 and RefTokenId2 are optional, INVALID_TOKEN when not given
89 if (TokenId2 != IWORKToken::INVALID_TOKEN && name==TokenId2)
90 {
91 m_context = std::make_shared<IWORKStyleContext>(getState(), m_styleMap2);
92 return m_context;
93 }
94 if (RefTokenId2 != IWORKToken::INVALID_TOKEN && name==RefTokenId2)
95 return std::make_shared<IWORKRefContext>(getState(), m_ref2);
96 break;
97 }
98 ETONYEK_DEBUG_MSG(("IWORKStyleContainer<...>::element: unknown element %d\n", name));
99 return IWORKXMLContextPtr_t();
100}
101
102template<int TokenId, int RefTokenId, int TokenId2, int RefTokenId2>
104{
105 if (m_ref)
106 m_style = getState().getStyleByName(get(m_ref).c_str(), m_styleMap);
107 else if (m_ref2 && m_styleMap2)
108 m_style = getState().getStyleByName(get(m_ref2).c_str(), *m_styleMap2);
109 else if (m_context)
110 m_style=m_context->getStyle();
111}
112
113}
114
115#endif // IWORKSTYLECONTAINER_H_INCLUDED
116
117/* 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:103
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
@ NS_URI_SF
Definition IWORKToken.h:696
@ INVALID_TOKEN
Definition IWORKToken.h:27
@ null
Definition IWORKToken.h:335
@ style
Definition IWORKToken.h:421
@ name
Definition IWORKToken.h:585
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.18.0