2013-01-23 17:38:03 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
#include <boost/weak_ptr.hpp>
|
|
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
|
|
|
|
|
#include <DB/Core/Exception.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class IStorage;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StoragePtr
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
/// Содержит IStorage. В деструкторе при необходимости вызывает IStorage::dropImpl() перед уничтожением IStorage.
|
|
|
|
|
struct Wrapper
|
|
|
|
|
{
|
|
|
|
|
Wrapper();
|
|
|
|
|
Wrapper(IStorage * s);
|
|
|
|
|
|
|
|
|
|
boost::scoped_ptr<IStorage> storage;
|
|
|
|
|
|
|
|
|
|
~Wrapper();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StoragePtr(boost::weak_ptr<Wrapper> p) : ptr(p) {}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<Wrapper> ptr;
|
|
|
|
|
|
|
|
|
|
friend class IStorage;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
StoragePtr() {}
|
|
|
|
|
StoragePtr(const StoragePtr & p) : ptr(p.ptr) {}
|
|
|
|
|
|
|
|
|
|
StoragePtr& operator = (const StoragePtr & p)
|
|
|
|
|
{
|
|
|
|
|
ptr = p.ptr;
|
2013-01-23 17:40:09 +00:00
|
|
|
|
return *this;
|
2013-01-23 17:38:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-05 08:32:20 +00:00
|
|
|
|
IStorage* get() const
|
2013-01-23 17:38:03 +00:00
|
|
|
|
{
|
2013-02-05 08:32:20 +00:00
|
|
|
|
if (!ptr)
|
|
|
|
|
return NULL;
|
|
|
|
|
else
|
|
|
|
|
return ptr->storage.get();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-22 12:18:08 +00:00
|
|
|
|
size_t use_count() const
|
|
|
|
|
{
|
|
|
|
|
return ptr.use_count();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-05 08:32:20 +00:00
|
|
|
|
bool operator == (const IStorage * p) const
|
|
|
|
|
{
|
|
|
|
|
return get() == p;
|
2013-01-23 17:38:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IStorage* operator -> () const
|
|
|
|
|
{
|
2013-02-05 08:32:20 +00:00
|
|
|
|
return get();
|
2013-01-23 17:38:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IStorage& operator * () const
|
|
|
|
|
{
|
2013-02-05 08:32:20 +00:00
|
|
|
|
return *get();
|
2013-01-23 17:38:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
operator IStorage* () const
|
|
|
|
|
{
|
2013-02-05 08:32:20 +00:00
|
|
|
|
return get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
operator bool () const
|
|
|
|
|
{
|
|
|
|
|
return ptr;
|
2013-01-23 17:38:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator ! () const
|
|
|
|
|
{
|
2013-02-05 08:32:20 +00:00
|
|
|
|
return !ptr;
|
2013-01-23 17:38:03 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|