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 
21 namespace libetonyek
22 {
23 
24 template<typename Type, class Container = std::deque<Type> >
26 {
27 public:
28  explicit IWORKPushCollector(Container &collection)
29  : m_collection(collection)
30  , m_value()
31  {
32  }
33 
34  template<class Context, class 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 
52 private:
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: */
std::shared_ptr< IWORKXMLContext > IWORKXMLContextPtr_t
Definition: IWORKXMLContext.h:18
IWORKXMLContextPtr_t makeContext(State &state)
Definition: IWORKPushCollector.h:35
boost::optional< Type > m_value
Definition: IWORKPushCollector.h:54
bool pending() const
Definition: IWORKPushCollector.h:40
Container & m_collection
Definition: IWORKPushCollector.h:53
Definition: IWORKPushCollector.h:25
void push()
Definition: IWORKPushCollector.h:45
IWORKPushCollector(Container &collection)
Definition: IWORKPushCollector.h:28

Generated for libetonyek by doxygen 1.8.6