https://github.com/wilkeraziz/mosesdecoder
Tip revision: 2ec5207db1493a3580a4c2dc3aab4fc65ed528d5 authored by Hieu Hoang on 16 September 2015, 12:31:36 UTC
int warnings
int warnings
Tip revision: 2ec5207
UniqueObject.h
/* ---------------------------------------------------------------- */
/* Copyright 2004 (c) by RWTH Aachen - Lehrstuhl fuer Informatik VI */
/* Richard Zens */
/* ---------------------------------------------------------------- */
#ifndef moses_UniqueObject_h
#define moses_UniqueObject_h
#include <iostream>
#include <set>
template<class T> T const* uniqueObject(const T& x,int mode=0)
{
typedef std::set<T> Pool;
static Pool pool;
static size_t Size=0;
if(mode==0) {
std::pair<typename Pool::iterator,bool> p=pool.insert(x);
if(p.second && (++Size%100000==0))
std::cerr<<"uniqueObjects -- size: "<<Size<<" object size: "<<sizeof(T)<<"\n";
return &(*(p.first));
} else {
pool.clear();
Size=0;
return 0;
}
}
//! @todo what is this?
template<class T> class UniqueObjectManager
{
public:
typedef T Object;
private:
typedef std::set<T> Pool;
Pool pool;
public:
UniqueObjectManager() {}
void clear() {
pool.clear();
}
size_t size() const {
return pool.size();
}
Object const * operator()(const Object& x) {
#ifdef DEBUG
std::pair<typename Pool::iterator,bool> p=pool.insert(x);
if(p.second && (size()%100000==0))
std::cerr<<"uniqueObjects -- size: "<<size()<<" object size: "<<sizeof(Object)<<"\n";
return &(*(p.first));
#else
return &(*(pool.insert(x).first));
#endif
}
};
#endif