mosesdecoder/contrib/other-builds/moses2/Recycler.h
2015-12-30 14:02:02 +00:00

69 lines
887 B
C++

/*
* Recycler.h
*
* Created on: 5 Nov 2015
* Author: hieu
*/
#ifndef RECYCLER_H_
#define RECYCLER_H_
#include <deque>
namespace Moses2
{
template<typename T>
class Recycler {
typedef std::deque<T> Coll;
public:
typedef typename Coll::iterator iterator;
typedef typename Coll::const_iterator const_iterator;
//! iterators
const_iterator begin() const {
return m_coll.begin();
}
const_iterator end() const {
return m_coll.end();
}
iterator begin() {
return m_coll.begin();
}
iterator end() {
return m_coll.end();
}
Recycler()
{
}
virtual ~Recycler()
{}
bool IsEmpty() const
{ return m_coll.empty(); }
T &Get()
{ return m_coll.back(); }
void Pop()
{
m_coll.pop_back();
}
void Add(T &obj)
{ m_coll.push_back(obj); }
void Reset()
{ m_coll.clear(); }
protected:
Coll m_coll;
};
}
#endif /* RECYCLER_H_ */