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#include <memory>
16
17#include <boost/optional.hpp>
18
19#include "IWORKXMLContext.h"
20
21namespace libetonyek
22{
23
24template<typename Type, class Container = std::deque<Type> >
25 class IWORKPushCollector
26{
27public:
28 explicit IWORKPushCollector(Container &collection)
29 : m_collection(collection)
30 , m_value()
31 {
32 }
33
34 template<class Context, class State>
35 IWORKXMLContextPtr_t makeContext(State &state)
36 {
37 return std::make_shared<Context>(state, m_value);
38 }
39
40 bool pending() const
41 {
42 return bool(m_value);
43 }
44
45 void push()
46 {
47 assert(m_value);
48 m_collection.push_back(get(m_value));
49 m_value.reset();
50 }
51
52private:
53 Container &m_collection;
54 boost::optional<Type> m_value;
55};
56
57}
58
59#endif // IWORKPUSHCOLLECTOR_H_INCLUDED
60
61/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
IWORKXMLContext.h
libetonyek::IWORKPushCollector
Definition IWORKPushCollector.h:26
libetonyek::IWORKPushCollector::makeContext
IWORKXMLContextPtr_t makeContext(State &state)
Definition IWORKPushCollector.h:35
libetonyek::IWORKPushCollector::m_value
boost::optional< Type > m_value
Definition IWORKPushCollector.h:54
libetonyek::IWORKPushCollector::pending
bool pending() const
Definition IWORKPushCollector.h:40
libetonyek::IWORKPushCollector::m_collection
Container & m_collection
Definition IWORKPushCollector.h:53
libetonyek::IWORKPushCollector::push
void push()
Definition IWORKPushCollector.h:45
libetonyek::IWORKPushCollector::IWORKPushCollector
IWORKPushCollector(Container &collection)
Definition IWORKPushCollector.h:28
libetonyek
Definition IWORKBezierElement.cpp:21
libetonyek::IWORKXMLContextPtr_t
std::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition IWORKXMLContext.h:20
libetonyek::get
const ValueT & get(const detail::IWAFieldImpl< TagV, ValueT, Reader > &field)
Definition IWAField.h:190