IWORKPushCollector.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libetonyek project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  */
00009 
00010 #ifndef IWORKPUSHCOLLECTOR_H_INCLUDED
00011 #define IWORKPUSHCOLLECTOR_H_INCLUDED
00012 
00013 #include <cassert>
00014 #include <deque>
00015 
00016 #include <boost/optional.hpp>
00017 
00018 #include "IWORKXMLContext.h"
00019 
00020 namespace libetonyek
00021 {
00022 
00023 template<typename Type, class Container = std::deque<Type> >
00024 class IWORKPushCollector
00025 {
00026 public:
00027   IWORKPushCollector(Container &collection)
00028     : m_collection(collection)
00029     , m_value()
00030   {
00031   }
00032 
00033   template<class Context, class State>
00034   IWORKXMLContextPtr_t makeContext(State &state)
00035   {
00036     return libetonyek::makeContext<Context>(state, m_value);
00037   }
00038 
00039   bool pending() const
00040   {
00041     return bool(m_value);
00042   }
00043 
00044   void push()
00045   {
00046     assert(m_value);
00047     m_collection.push_back(get(m_value));
00048   }
00049 
00050 private:
00051   Container &m_collection;
00052   boost::optional<Type> m_value;
00053 };
00054 
00055 }
00056 
00057 #endif // IWORKPUSHCOLLECTOR_H_INCLUDED
00058 
00059 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */