1#ifndef PROTON_INTERNAL_OBJECT_HPP
2#define PROTON_INTERNAL_OBJECT_HPP
25#include "./export.hpp"
26#include "./comparable.hpp"
33template <
class T>
class returned;
39 PN_CPP_EXTERN
static void incref(
void* p);
40 PN_CPP_EXTERN
static void decref(
void* p);
41 PN_CPP_EXTERN
static std::string inspect(
void* p);
44template <
class T>
class pn_ptr :
private pn_ptr_base,
private comparable<pn_ptr<T> > {
47 pn_ptr(T* p) : ptr_(p) { incref(ptr_); }
48 pn_ptr(
const pn_ptr& o) : ptr_(o.ptr_) { incref(ptr_); }
49 pn_ptr(pn_ptr&& o) : ptr_(0) { std::swap(ptr_, o.ptr_); }
51 ~pn_ptr() { decref(ptr_); }
53 pn_ptr& operator=(pn_ptr o) { std::swap(ptr_, o.ptr_);
return *
this; }
55 T*
get()
const {
return ptr_; }
56 T* release() { T *p = ptr_; ptr_ = 0;
return p; }
58 bool operator!()
const {
return !ptr_; }
59 explicit operator bool()
const {
return !!ptr_; }
61 std::string inspect()
const {
return pn_ptr_base::inspect(ptr_); }
63 static pn_ptr take_ownership(T* p) {
return pn_ptr<T>(p,
true); }
70 pn_ptr(T* p,
bool) : ptr_(p) {}
72 friend bool operator==(
const pn_ptr& a,
const pn_ptr& b) {
return a.ptr_ == b.ptr_; }
73 friend bool operator<(
const pn_ptr& a,
const pn_ptr& b) {
return a.ptr_ < b.ptr_; }
76template <
class T> pn_ptr<T> take_ownership(T* p) {
return pn_ptr<T>::take_ownership(p); }
79template <
class T>
class object :
private comparable<object<T> > {
81 bool operator!()
const {
return !object_; }
82 explicit operator bool()
const {
return object_.get(); }
86 object(pn_ptr<T> o) : object_(o) {}
87 T* pn_object()
const {
return object_.get(); }
92 friend bool operator==(
const object& a,
const object& b) {
return a.object_ == b.object_; }
93 friend bool operator<(
const object& a,
const object& b) {
return a.object_ < b.object_; }
94 friend std::ostream&
operator<<(std::ostream& o,
const object& a) { o << a.object_.inspect();
return o; }
100template <
class T>
class factory;
A return type for container methods.
Definition returned.hpp:51
The main Proton namespace.
Definition annotation_key.hpp:33
T get(const scalar &s)
Get a contained value of type T.
Definition scalar.hpp:60
std::ostream & operator<<(std::ostream &, const binary &)
Print a binary value.