18 #ifndef LIBCWD_SMART_PTR_H
19 #define LIBCWD_SMART_PTR_H
21 #ifndef LIBCWD_PRIVATE_STRUCT_TSD_H
28 class refcnt_charptr_ct {
30 int M_reference_count;
33 refcnt_charptr_ct(
char* ptr) : M_reference_count(1), M_ptr(ptr) { }
34 void increment() { ++M_reference_count; }
37 if (M_ptr && --M_reference_count == 0)
45 char* get()
const {
return M_ptr; }
46 int reference_count()
const {
return M_reference_count; }
52 bool M_string_literal;
56 smart_ptr() : M_ptr(NULL), M_string_literal(true) { }
57 ~smart_ptr() {
if (!M_string_literal)
reinterpret_cast<refcnt_charptr_ct*
>(M_ptr)->decrement(); }
60 smart_ptr(smart_ptr
const& ptr) : M_ptr(NULL), M_string_literal(true) { copy_from(ptr); }
63 smart_ptr(
char const* ptr) : M_string_literal(true) { copy_from(ptr); }
64 smart_ptr(
char* ptr) : M_string_literal(true) { copy_from(ptr); }
68 smart_ptr& operator=(smart_ptr
const& ptr) { copy_from(ptr);
return *
this; }
69 smart_ptr& operator=(
char const* ptr) { copy_from(ptr);
return *
this; }
70 smart_ptr& operator=(
char* ptr) { copy_from(ptr);
return *
this; }
74 operator char const* ()
const {
return get(); }
77 bool operator==(smart_ptr
const& ptr)
const {
return get() == ptr.get(); }
78 bool operator==(
char const* ptr)
const {
return get() == ptr; }
79 bool operator!=(smart_ptr
const& ptr)
const {
return get() != ptr.get(); }
80 bool operator!=(
char const* ptr)
const {
return get() != ptr; }
83 bool is_null()
const {
return M_ptr == NULL; }
84 char const* get()
const {
return M_string_literal ?
reinterpret_cast<char*
>(M_ptr) :
reinterpret_cast<refcnt_charptr_ct*
>(M_ptr)->get(); }
88 void copy_from(smart_ptr
const& ptr);
89 void copy_from(
char const* ptr);
90 void copy_from(
char* ptr);
94 void increment() {
if (!M_string_literal)
reinterpret_cast<refcnt_charptr_ct*
>(M_ptr)->increment(); }
95 void decrement(LIBCWD_TSD_PARAM);
namespace for libcwd.
Definition: debug.cc:87