IWORKPtrPropertyContext.h Source File documentation

IWORKPtrPropertyContext.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 IWORKPTRPROPERTYCONTEXT_H_INCLUDED
11#define IWORKPTRPROPERTYCONTEXT_H_INCLUDED
12
13#include "IWORKPropertyContextBase.h"
14#include "IWORKPropertyInfo.h"
15
16namespace libetonyek
17{
18
19template<typename Property, typename Context, int TokenId>
20 class IWORKPtrPropertyContext : public IWORKPropertyContextBase
21{
22public:
23 IWORKPtrPropertyContext(IWORKXMLParserState &state, IWORKPropertyMap &propMap);
24
25private:
26 IWORKXMLContextPtr_t element(int name) override;
27 void endOfElement() override;
28
29private:
30 typename IWORKPropertyInfo<Property>::ValueType m_value;
31};
32
33template<typename Property, typename Context, int TokenId>
34IWORKPtrPropertyContext<Property, Context, TokenId>::IWORKPtrPropertyContext(IWORKXMLParserState &state, IWORKPropertyMap &propMap)
35 : IWORKPropertyContextBase(state, propMap)
36 , m_value()
37{
38}
39
40template<typename Property, typename Context, int TokenId>
41 IWORKXMLContextPtr_t IWORKPtrPropertyContext<Property, Context, TokenId>::element(const int name)
42{
43 m_default = false;
44 if (TokenId == name)
45 return std::make_shared<Context>(getState(), m_value);
46 return IWORKXMLContextPtr_t();
47}
48
49template<typename Property, typename Context, int TokenId>
50 void IWORKPtrPropertyContext<Property, Context, TokenId>::endOfElement()
51{
52 if (bool(m_value))
53 m_propMap.put<Property>(m_value);
54 else if (m_default)
55 m_propMap.clear<Property>();
56}
57
58}
59
60#endif // IWORKPTRPROPERTYCONTEXT_H_INCLUDED
61
62/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
IWORKPropertyContextBase.h
IWORKPropertyInfo.h
libetonyek::IWORKPropertyContextBase::IWORKPropertyContextBase
IWORKPropertyContextBase(IWORKXMLParserState &state, IWORKPropertyMap &propMap)
Definition IWORKPropertyContextBase.cpp:15
libetonyek::IWORKPropertyContextBase::m_propMap
IWORKPropertyMap & m_propMap
Definition IWORKPropertyContextBase.h:26
libetonyek::IWORKPropertyContextBase::m_default
bool m_default
Definition IWORKPropertyContextBase.h:27
libetonyek::IWORKPropertyMap
Represents a (hierarchical) property map.
Definition IWORKPropertyMap.h:25
libetonyek::IWORKPtrPropertyContext::m_value
IWORKPropertyInfo< Property >::ValueType m_value
Definition IWORKPtrPropertyContext.h:30
libetonyek::IWORKPtrPropertyContext::endOfElement
void endOfElement() override
Signalize the end of an element.
Definition IWORKPtrPropertyContext.h:50
libetonyek::IWORKPtrPropertyContext::element
IWORKXMLContextPtr_t element(int name) override
Create a context for parsing a child element.
Definition IWORKPtrPropertyContext.h:41
libetonyek::IWORKPtrPropertyContext::IWORKPtrPropertyContext
IWORKPtrPropertyContext(IWORKXMLParserState &state, IWORKPropertyMap &propMap)
Definition IWORKPtrPropertyContext.h:34
libetonyek::IWORKXMLContextBase< IWORKXMLContextElement, IWORKXMLParserState >::getState
IWORKXMLParserState & getState()
Definition IWORKXMLContextBase.h:43
libetonyek::IWORKXMLParserState
Definition IWORKXMLParserState.h:32
libetonyek::IWORKToken::element
@ element
Definition IWORKToken.h:192
libetonyek::IWORKToken::name
@ name
Definition IWORKToken.h:585
libetonyek
Definition IWORKBezierElement.cpp:21
libetonyek::IWORKXMLContextPtr_t
std::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition IWORKXMLContext.h:20
libetonyek::IWORKPropertyInfo
Definition IWORKPropertyInfo.h:22