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
18 namespace libetonyek
19 {
20
21 template<typename Property, typename Context, int TokenId>
22 class IWORKPropertyContext : public IWORKPropertyContextBase
23 {
24 public:
25 IWORKPropertyContext(IWORKXMLParserState &state, IWORKPropertyMap &propMap);
26
27 private:
28 IWORKXMLContextPtr_t element(int name) override;
29 void endOfElement() override;
30
31 private:
32 boost::optional<typename IWORKPropertyInfo<Property>::ValueType> m_value;
33 };
34
35 template<typename Property, typename Context, int TokenId>
36 IWORKPropertyContext<Property, Context, TokenId>::IWORKPropertyContext(IWORKXMLParserState &state, IWORKPropertyMap &propMap)
37 : IWORKPropertyContextBase(state, propMap)
38 , m_value()
39 {
40 }
41
42 template<typename Property, typename Context, int TokenId>
43 IWORKXMLContextPtr_t IWORKPropertyContext<Property, Context, TokenId>::element(const int name)
44 {
45 m_default = false;
46 if (TokenId == name)
47 return makeContext<Context>(getState(), m_value);
48 return IWORKXMLContextPtr_t();
49 }
50
51 template<typename Property, typename Context, int TokenId>
52 void IWORKPropertyContext<Property, Context, TokenId>::endOfElement()
53 {
54 if (bool(m_value))
55 m_propMap.put<Property>(get(m_value));
56 else if (m_default)
57 m_propMap.clear<Property>();
58 }
59
60 }
61
62 #endif // IWORKPROPERTYCONTEXT_H_INCLUDED
63
64 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libetonyek
Definition: IWORKBezierElement.cpp:18
libetonyek::IWORKXMLContextPtr_t
std::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition: IWORKXMLContext.h:18
libetonyek::IWORKPropertyMap
Represents a (hierarchical) property map.
Definition: IWORKPropertyMap.h:24
IWORKPropertyInfo.h
libetonyek::IWORKPropertyContext::element
IWORKXMLContextPtr_t element(int name) override
Definition: IWORKPropertyContext.h:43
m_propMap
IWORKPropertyMap & m_propMap
Definition: IWORKPropertyMapElement.cpp:763
libetonyek::IWORKPropertyContext::m_value
boost::optional< typename IWORKPropertyInfo< Property >::ValueType > m_value
Definition: IWORKPropertyContext.h:32
libetonyek::IWORKPropertyContext::endOfElement
void endOfElement() override
Definition: IWORKPropertyContext.h:52
m_value
optional< string > & m_value
Definition: IWORKMetadataElement.cpp:37
libetonyek::IWORKPropertyContextBase
Definition: IWORKPropertyContextBase.h:20
name
const char * name
Definition: IWORKToken.cpp:43
libetonyek::IWORKXMLParserState
Definition: IWORKXMLParserState.h:30
libetonyek::IWORKPropertyContext::IWORKPropertyContext
IWORKPropertyContext(IWORKXMLParserState &state, IWORKPropertyMap &propMap)
Definition: IWORKPropertyContext.h:36
libetonyek::IWORKToken::element
Definition: IWORKToken.h:111
IWORKPropertyContextBase.h
libetonyek::IWORKPropertyContext
Definition: IWORKPropertyContext.h:22