Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
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