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>
22 {
23 public:
24  IWORKValueContext(IWORKXMLParserState &state, boost::optional<Type> &value)
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)
35  , m_value()
37  , m_direct(&value)
38  , m_isSet(isSet)
39  {
40  }
41 
42 private:
43  virtual IWORKXMLContextPtr_t element(const int name)
44  {
45  if (name == Id)
46  return makeContext<NestedParser>(getState(), m_value);
47  return IWORKXMLContextPtr_t();
48  }
49 
50  virtual void endOfElement()
51  {
52  if (m_value)
53  {
54  if (m_direct)
55  {
56  *m_direct = get(m_value);
57  if (m_isSet)
58  *m_isSet |= true;
59  }
60  else
61  {
63  }
64  }
65  }
66 
67 private:
68  boost::optional<Type> m_value;
69  boost::optional<Type> &m_optional;
70  Type *const m_direct;
71  bool *const m_isSet;
72 };
73 
74 }
75 
76 #endif // IWORKVALUECONTEXT_H_INCLUDED
77 
78 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
virtual void endOfElement()
Definition: IWORKValueContext.h:50
Definition: IWORKBezierElement.cpp:18
Type *const m_direct
Definition: IWORKValueContext.h:70
boost::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition: IWORKXMLContext.h:18
boost::optional< Type > & m_optional
Definition: IWORKValueContext.h:69
State & getState()
Definition: IWORKXMLContextBase.h:43
Definition: IWORKValueContext.h:21
const char * name
Definition: IWORKToken.cpp:43
virtual IWORKXMLContextPtr_t element(const int name)
Definition: IWORKValueContext.h:43
Definition: IWORKXMLContextBase.h:27
Definition: IWORKXMLParserState.h:29
boost::optional< Type > m_value
Definition: IWORKValueContext.h:68
IWORKValueContext(IWORKXMLParserState &state, boost::optional< Type > &value)
Definition: IWORKValueContext.h:24
IWORKValueContext(IWORKXMLParserState &state, Type &value, bool *isSet=0)
Definition: IWORKValueContext.h:33
bool *const m_isSet
Definition: IWORKValueContext.h:71

Generated for libetonyek by doxygen 1.8.10