IWORKValueContext.h Source File documentation

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

IWORKValueContext.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 IWORKVALUECONTEXT_H_INCLUDED
11 #define IWORKVALUECONTEXT_H_INCLUDED
12
13 #include <boost/optional.hpp>
14
15 #include "IWORKXMLContextBase.h"
16
17 namespace libetonyek
18 {
19
20 template<typename Type, class NestedParser, unsigned Id>
21 class IWORKValueContext : public IWORKXMLElementContextBase
22 {
23 public:
24 IWORKValueContext(IWORKXMLParserState &state, boost::optional<Type> &value)
25 : IWORKXMLElementContextBase(state)
26 , m_value()
27 , m_optional(value)
28 , m_direct(0)
29 , m_isSet(0)
30 {
31 }
32
33 IWORKValueContext(IWORKXMLParserState &state, Type &value, bool *isSet = 0)
34 : IWORKXMLElementContextBase(state)
35 , m_value()
36 , m_optional(m_value)
37 , m_direct(&value)
38 , m_isSet(isSet)
39 {
40 }
41
42 protected:
43 void set(const Type &value)
44 {
45 m_value = value;
46 }
47
48 virtual IWORKXMLContextPtr_t element(const int name)
49 {
50 if (name == Id)
51 return makeContext<NestedParser>(getState(), m_value);
52 return IWORKXMLContextPtr_t();
53 }
54
55 virtual void endOfElement()
56 {
57 if (m_value)
58 {
59 if (m_direct)
60 {
61 *m_direct = get(m_value);
62 if (m_isSet)
63 *m_isSet |= true;
64 }
65 else
66 {
67 m_optional = m_value;
68 }
69 }
70 }
71
72 private:
73 boost::optional<Type> m_value;
74 boost::optional<Type> &m_optional;
75 Type *const m_direct;
76 bool *const m_isSet;
77 };
78
79 }
80
81 #endif // IWORKVALUECONTEXT_H_INCLUDED
82
83 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libetonyek::IWORKValueContext::endOfElement
virtual void endOfElement()
Definition: IWORKValueContext.h:55
libetonyek
Definition: IWORKBezierElement.cpp:18
libetonyek::IWORKValueContext::m_direct
Type *const m_direct
Definition: IWORKValueContext.h:75
IWORKXMLContextBase.h
libetonyek::IWORKXMLContextPtr_t
boost::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition: IWORKXMLContext.h:18
libetonyek::IWORKValueContext::m_optional
boost::optional< Type > & m_optional
Definition: IWORKValueContext.h:74
libetonyek::IWORKXMLContextBase::getState
State & getState()
Definition: IWORKXMLContextBase.h:43
libetonyek::IWORKValueContext
Definition: IWORKValueContext.h:21
name
const char * name
Definition: IWORKToken.cpp:43
libetonyek::IWORKValueContext::element
virtual IWORKXMLContextPtr_t element(const int name)
Definition: IWORKValueContext.h:48
libetonyek::IWORKXMLContextBase
Definition: IWORKXMLContextBase.h:27
libetonyek::IWORKXMLParserState
Definition: IWORKXMLParserState.h:30
libetonyek::IWORKValueContext::m_value
boost::optional< Type > m_value
Definition: IWORKValueContext.h:73
libetonyek::IWORKValueContext::IWORKValueContext
IWORKValueContext(IWORKXMLParserState &state, boost::optional< Type > &value)
Definition: IWORKValueContext.h:24
libetonyek::IWORKValueContext::IWORKValueContext
IWORKValueContext(IWORKXMLParserState &state, Type &value, bool *isSet=0)
Definition: IWORKValueContext.h:33
libetonyek::IWORKValueContext::m_isSet
bool *const m_isSet
Definition: IWORKValueContext.h:76