|
From: Kakhkhor A. <kab...@gm...> - 2010-09-02 07:50:02
|
I could run several examples but the test suite crashes instantly with
memory access violation error. Can someone try the test suite with the
singleton attached below?
////////////////////////////////////////////////////////////////////
#ifndef quantlib_singleton_hpp
#define quantlib_singleton_hpp
#include <ql/types.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <map>
namespace QuantLib {
#if defined(QL_ENABLE_SESSIONS)
Integer sessionId();
#endif
template <class T>
class Singleton : private boost::noncopyable {
public:
static T& instance() {
#if defined(QL_ENABLE_SESSIONS)
Integer id = sessionId();
#else
Integer id = 0;
#endif
boost::shared_ptr<T>& p = instances_[id];
if (!p)
p.reset(new T);
return *p;
}
protected:
Singleton() {}
private:
typedef std::map<Integer, boost::shared_ptr<T> > map_type;
static map_type instances_;
};
template <typename T>
typename Singleton<T>::map_type Singleton<T>::instances_;
}
#endif
|