IWORKPropertyContext.h Source File documentation

IWORKPropertyContext.h
Go to the documentation of this file.
1/* -*- Mode: Context++; 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 IWORKPROPERTYCONTEXT_H_INCLUDED
11#define IWORKPROPERTYCONTEXT_H_INCLUDED
12
13#include <boost/optional.hpp>
14
15#include "IWORKPropertyContextBase.h"
16#include "IWORKPropertyInfo.h"
17#include "IWORKToken.h"
18
19namespace libetonyek
20{
21
22template<typename Property, typename Context, int TokenId, int TokenId2=0>
23 class IWORKPropertyContext : public IWORKPropertyContextBase
24{
25public:
26 IWORKPropertyContext(IWORKXMLParserState &state, IWORKPropertyMap &propMap);
27
28private:
29 IWORKXMLContextPtr_t element(int name) override;
30 void endOfElement() override;
31
32private:
33 boost::optional<typename IWORKPropertyInfo<Property>::ValueType> m_value;
34};
35
36template<typename Property, typename Context, int TokenId, int TokenId2>
37IWORKPropertyContext<Property, Context, TokenId, TokenId2>::IWORKPropertyContext(IWORKXMLParserState &state, IWORKPropertyMap &propMap)
38 : IWORKPropertyContextBase(state, propMap)
39 , m_value()
40{
41}
42
43template<typename Property, typename Context, int TokenId, int TokenId2>
44 IWORKXMLContextPtr_t IWORKPropertyContext<Property, Context, TokenId, TokenId2>::element(const int name)
45{
46 m_default = false;
47 if (TokenId == name || (TokenId2 != 0 && TokenId2 == name))
48 return std::make_shared<Context>(getState(), m_value);
49 else if (name != (IWORKToken::NS_URI_SF | IWORKToken::null))
50 {
51 ETONYEK_DEBUG_MSG(("IWORKPropertyContext<...>::element: found unexpected element %d\n", name));
52 }
53 return IWORKXMLContextPtr_t();
54}
55
56template<typename Property, typename Context, int TokenId, int TokenId2>
57 void IWORKPropertyContext<Property, Context, TokenId, TokenId2>::endOfElement()
58{
59 if (bool(m_value))
60 m_propMap.put<Property>(get(m_value));
61 else if (m_default)
62 m_propMap.clear<Property>();
63}
64
65}
66
67#endif // IWORKPROPERTYCONTEXT_H_INCLUDED
68
69/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
m_value
boost::optional< IWORKGradient > & m_value
Definition: IWORKFillElement.cpp:131
IWORKPropertyContextBase.h
IWORKPropertyInfo.h
m_propMap
IWORKPropertyMap & m_propMap
Definition: IWORKPropertyMapElement.cpp:756
IWORKToken.h
libetonyek::IWORKPropertyContextBase
Definition: IWORKPropertyContextBase.h:21
libetonyek::IWORKPropertyContext
Definition: IWORKPropertyContext.h:24
libetonyek::IWORKPropertyContext::endOfElement
void endOfElement() override
Definition: IWORKPropertyContext.h:57
libetonyek::IWORKPropertyContext::IWORKPropertyContext
IWORKPropertyContext(IWORKXMLParserState &state, IWORKPropertyMap &propMap)
Definition: IWORKPropertyContext.h:37
libetonyek::IWORKPropertyContext::m_value
boost::optional< typename IWORKPropertyInfo< Property >::ValueType > m_value
Definition: IWORKPropertyContext.h:33
libetonyek::IWORKPropertyContext::element
IWORKXMLContextPtr_t element(int name) override
Definition: IWORKPropertyContext.h:44
libetonyek::IWORKPropertyMap
Represents a (hierarchical) property map.
Definition: IWORKPropertyMap.h:25
libetonyek::IWORKPropertyMap::put
void put(const typename IWORKPropertyInfo< Property >::ValueType &value)
Insert a new value for key key.
Definition: IWORKPropertyMap.h:134
libetonyek::IWORKPropertyMap::clear
void clear()
Clear property.
Definition: IWORKPropertyMap.h:145
libetonyek::IWORKXMLParserState
Definition: IWORKXMLParserState.h:32
ETONYEK_DEBUG_MSG
#define ETONYEK_DEBUG_MSG(M)
Definition: libetonyek_utils.h:54
libetonyek::IWORKToken::null
@ null
Definition: IWORKToken.h:335
libetonyek::IWORKToken::name
@ name
Definition: IWORKToken.h:585
libetonyek::IWORKToken::NS_URI_SF
@ NS_URI_SF
Definition: IWORKToken.h:696
libetonyek
Definition: IWORKBezierElement.cpp:21
libetonyek::IWORKXMLContextPtr_t
std::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition: IWORKXMLContext.h:18
libetonyek::get
const ValueT & get(const detail::IWAFieldImpl< TagV, ValueT, Reader > &field)
Definition: IWAField.h:190