IWORKPushCollector.h Source File documentation

IWORKPushCollector.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 IWORKPUSHCOLLECTOR_H_INCLUDED
11 #define IWORKPUSHCOLLECTOR_H_INCLUDED
12
13 #include <cassert>
14 #include <deque>
15
16 #include <boost/optional.hpp>
17
18 #include "IWORKXMLContext.h"
19
20 namespace libetonyek
21 {
22
23 template<typename Type, class Container = std::deque<Type> >
24 class IWORKPushCollector
25 {
26 public:
27 IWORKPushCollector(Container &collection)
28 : m_collection(collection)
29 , m_value()
30 {
31 }
32
33 template<class Context, class State>
34 IWORKXMLContextPtr_t makeContext(State &state)
35 {
36 return libetonyek::makeContext<Context>(state, m_value);
37 }
38
39 bool pending() const
40 {
41 return bool(m_value);
42 }
43
44 void push()
45 {
46 assert(m_value);
47 m_collection.push_back(get(m_value));
48 }
49
50 private:
51 Container &m_collection;
52 boost::optional<Type> m_value;
53 };
54
55 }
56
57 #endif // IWORKPUSHCOLLECTOR_H_INCLUDED
58
59 /* 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::IWORKPushCollector::makeContext
IWORKXMLContextPtr_t makeContext(State &state)
Definition: IWORKPushCollector.h:34
libetonyek::IWORKPushCollector::m_value
boost::optional< Type > m_value
Definition: IWORKPushCollector.h:52
libetonyek::IWORKPushCollector::m_collection
Container & m_collection
Definition: IWORKPushCollector.h:51
libetonyek::IWORKPushCollector
Definition: IWORKPushCollector.h:24
libetonyek::IWORKPushCollector::push
void push()
Definition: IWORKPushCollector.h:44
libetonyek::IWORKPushCollector::pending
bool pending() const
Definition: IWORKPushCollector.h:39
libetonyek::IWORKPushCollector::IWORKPushCollector
IWORKPushCollector(Container &collection)
Definition: IWORKPushCollector.h:27
IWORKXMLContext.h