#ifndef PPAPI_CPP_DEV_MAY_OWN_PTR_DEV_H_
#define PPAPI_CPP_DEV_MAY_OWN_PTR_DEV_H_
#include "ppapi/cpp/logging.h"
namespace pp {
enum NotOwned {
NOT_OWNED
};
namespace internal {
template <typename T>
class MayOwnPtr {
public:
MayOwnPtr() : value_(new T()), owned_(true) {}
MayOwnPtr(T* value, NotOwned) : value_(value), owned_(false) {
PP_DCHECK(value);
}
~MayOwnPtr() {
if (owned_)
delete value_;
}
const T* get() const { return value_; }
T* get() { return value_; }
const T& operator*() const { return *value_; }
T& operator*() { return *value_; }
const T* operator->() const { return value_; }
T* operator->() { return value_; }
private:
MayOwnPtr(const MayOwnPtr<T>&);
MayOwnPtr<T>& operator=(const MayOwnPtr<T>&);
T* value_;
bool owned_;
};
}
}
#endif