13#ifndef CLASSDESC_REF_H
14#define CLASSDESC_REF_H
29 struct Payload:
public T
32 Payload(): count(1) {}
33 Payload(
const T& x):
T(x), count(1) {}
36 void refdec() {
if (item){item->count--;
if (item->count==0)
delete item;}}
37 void asg(
const ref& x)
40 {item=x.item; item->count++;}
44 void newitem() {item=
new Payload;}
45 void newitem(
const T& x) {item=
new Payload(x);}
46 template <
class U>
bool operator==(
const U&)
const;
49 ref(
const ref& x) {asg(x);}
50 ref(
const T& x) {newitem(x);}
51 ref& operator=(
const ref& x) {
if (x.item!=item) {refdec(); asg(x);}
return *
this;}
52 ref& operator=(
const T& x) {refdec(); newitem(x);
return *
this;}
61 functional::bound_method<T,M> operator->*(M& m)
const {
62 return functional::bound_method<T,M>(**
this, m);
73 bool nullref()
const {
return item==NULL;}
75 operator bool ()
const {
return !
nullref();}
77 int refCount()
const {
if (item) {
return item->count;}
else return 0;}
78 bool operator==(
const ref& x)
const {
return x.item==item;}
79 bool operator==(
const T* x)
const {
return x==item;}
80 bool operator==(
const T& x)
const {
return x==*item;}
82 bool operator!=(
const U& x)
const {
return !operator==(x);}
84 bool operator<(
const ref& x)
const {
return item<x.item;}
85 void swap(ref& x) {Payload*tmp=x.item; x.item=item; item=tmp;}
103#pragma omit pack classdesc::ref
104#pragma omit unpack classdesc::ref
105#pragma omit isa classdesc::ref
Definition pack_base.h:138
const T & operator*() const
dereference - throws in debug mode if null
Definition ref.h:69
T & operator*()
dereference - creates default object if null
Definition ref.h:65
T * operator->()
dereference - creates default object if null
Definition ref.h:55
int refCount() const
return the payloads reference count
Definition ref.h:77
void nullify()
make reference null
Definition ref.h:71
const T * operator->() const
dereference - throws in debug mode if null
Definition ref.h:67
bool nullref() const
true if reference is null
Definition ref.h:73
Metaprogramming support for processing functions of multiple arguments.
Contains access_* structs, and nothing else. These structs are used to gain access to private members...
Definition classdesc_access.h:20
Contains definitions related to classdesc functionality.
serialisation for dynamic structures (graphs/trees and so on)
Definition pack_graph.h:73
class to allow access to private members
Definition classdesc_access.h:21
class to allow access to private members
Definition classdesc_access.h:22