IWORKStyleContainer.h Source File documentation

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>
29 class IWORKStyleContainer : public IWORKXMLElementContextBase
30{
31public:
32 IWORKStyleContainer(IWORKXMLParserState &state, IWORKStylePtr_t &style, IWORKStyleMap_t &styleMap);
33 IWORKStyleContainer(IWORKXMLParserState &state, IWORKStylePtr_t &style, IWORKStyleMap_t &styleMap, IWORKStyleMap_t &styleMap2);
34
35protected:
36 IWORKXMLContextPtr_t element(int name) override;
37 void endOfElement() override;
38
39private:
40 IWORKStyleContainer(IWORKStyleContainer const &);
41 IWORKStyleContainer &operator=(IWORKStyleContainer const &);
42
43 IWORKStylePtr_t &m_style;
44 IWORKStyleMap_t &m_styleMap;
45 std::shared_ptr<IWORKStyleContext> m_context;
46 boost::optional<ID_t> m_ref;
47 IWORKStyleMap_t *m_styleMap2;
48 boost::optional<ID_t> m_ref2;
49};
50
51template<int TokenId, int RefTokenId, int TokenId2, int RefTokenId2>
52IWORKStyleContainer<TokenId, RefTokenId, TokenId2, RefTokenId2>::IWORKStyleContainer(IWORKXMLParserState &state, IWORKStylePtr_t &style, IWORKStyleMap_t &styleMap)
53 : IWORKXMLElementContextBase(state)
54 , m_style(style)
55 , m_styleMap(styleMap)
56 , m_context()
57 , m_ref()
58 , m_styleMap2(nullptr)
59 , m_ref2()
60{
61}
62
63template<int TokenId, int RefTokenId, int TokenId2, int RefTokenId2>
64 IWORKStyleContainer<TokenId, RefTokenId, TokenId2, RefTokenId2>::IWORKStyleContainer(IWORKXMLParserState &state, IWORKStylePtr_t &style, IWORKStyleMap_t &styleMap, IWORKStyleMap_t &styleMap2)
65 : IWORKXMLElementContextBase(state)
66 , m_style(style)
67 , m_styleMap(styleMap)
68 , m_context()
69 , m_ref()
70 , m_styleMap2(&styleMap2)
71 , m_ref2()
72{
73}
74
75template<int TokenId, int RefTokenId, int TokenId2, int RefTokenId2>
76 IWORKXMLContextPtr_t IWORKStyleContainer<TokenId, RefTokenId, TokenId2, RefTokenId2>::element(const int name)
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);
85 case IWORKToken::NS_URI_SF | IWORKToken::null:
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>
105 void IWORKStyleContainer<TokenId, RefTokenId, TokenId2, RefTokenId2>::endOfElement()
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: */
m_ref
boost::optional< ID_t > m_ref
Definition: IWORKPathElement.cpp:285
m_style
IWORKStylePtr_t m_style
Definition: IWORKPropertyMapElement.cpp:172
m_context
std::shared_ptr< IWORKXMLContext > m_context
Definition: IWORKPropertyMapElement.cpp:90
IWORKStyleContext.h
IWORKStyle_fwd.h
IWORKToken.h
IWORKXMLContextBase.h
IWORKXMLParserState.h
libetonyek::IWORKStyleContainer
Definition: IWORKStyleContainer.h:30
libetonyek::IWORKStyleContainer::IWORKStyleContainer
IWORKStyleContainer(IWORKStyleContainer const &)
libetonyek::IWORKStyleContainer::m_ref2
boost::optional< ID_t > m_ref2
Definition: IWORKStyleContainer.h:48
libetonyek::IWORKStyleContainer::IWORKStyleContainer
IWORKStyleContainer(IWORKXMLParserState &state, IWORKStylePtr_t &style, IWORKStyleMap_t &styleMap)
Definition: IWORKStyleContainer.h:52
libetonyek::IWORKStyleContainer::endOfElement
void endOfElement() override
Definition: IWORKStyleContainer.h:105
libetonyek::IWORKStyleContainer::m_ref
boost::optional< ID_t > m_ref
Definition: IWORKStyleContainer.h:46
libetonyek::IWORKStyleContainer::m_styleMap
IWORKStyleMap_t & m_styleMap
Definition: IWORKStyleContainer.h:44
libetonyek::IWORKStyleContainer::element
IWORKXMLContextPtr_t element(int name) override
Definition: IWORKStyleContainer.h:76
libetonyek::IWORKStyleContainer::m_context
std::shared_ptr< IWORKStyleContext > m_context
Definition: IWORKStyleContainer.h:45
libetonyek::IWORKStyleContainer::m_styleMap2
IWORKStyleMap_t * m_styleMap2
Definition: IWORKStyleContainer.h:47
libetonyek::IWORKStyleContainer::operator=
IWORKStyleContainer & operator=(IWORKStyleContainer const &)
libetonyek::IWORKStyleContainer::m_style
IWORKStylePtr_t & m_style
Definition: IWORKStyleContainer.h:43
libetonyek::IWORKXMLContextBase
Definition: IWORKXMLContextBase.h:28
libetonyek::IWORKXMLParserState
Definition: IWORKXMLParserState.h:32
ETONYEK_DEBUG_MSG
#define ETONYEK_DEBUG_MSG(M)
Definition: libetonyek_utils.h:54
libetonyek::IWORKToken::INVALID_TOKEN
@ INVALID_TOKEN
Definition: IWORKToken.h:27
libetonyek::IWORKToken::null
@ null
Definition: IWORKToken.h:335
libetonyek::IWORKToken::NS_URI_SF
@ NS_URI_SF
Definition: IWORKToken.h:696
libetonyek
Definition: IWORKBezierElement.cpp:21
libetonyek::IWORKStyleMap_t
std::unordered_map< ID_t, IWORKStylePtr_t > IWORKStyleMap_t
Definition: IWORKStyle_fwd.h:24
libetonyek::IWORKXMLContextPtr_t
std::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition: IWORKXMLContext.h:20
libetonyek::get
const ValueT & get(const detail::IWAFieldImpl< TagV, ValueT, Reader > &field)
Definition: IWAField.h:190
libetonyek::IWORKStylePtr_t
std::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition: IWORKStyle_fwd.h:23