Xpace
sharedvoid.h
Go to the documentation of this file.
1 
2 /**********************************************************//**
3  **
4  ** @file base/sharedvoid.h
5  **
6  ** Copyright (C) 2012 Xpace, LLC. All rights reserved
7  **
8  ** www.xpace.net
9  **
10  **************************************************************/
11 
12 
13 #if !defined XPACE_SHAREDVOID_H
14 #define XPACE_SHAREDVOID_H
15 
16 #include "base/types.h"
17 
18 namespace Xpace
19 {
20  /// an anonymous pointer, used only in conjunction with SharedImplPointer
22  {
23  public :
24  /// @param p the pointer to wrap
25  explicit SharedVoidPointer
26  (void* p);
28  ();
30  (const SharedVoidPointer &rhs);
31  SharedVoidPointer& operator=
32  (const SharedVoidPointer &rhs);
34  ();
35 
36  SharedVoidPointer& operator=
37  (void* p);
38 
39  /// @return true if null
40  bool operator!
41  ()
42  const;
43 
44  /// @return a writable pointer
45  void* data
46  (bool cached);
47 
48  /// @return a non-writable pointer
49  const void* data
50  ()
51  const;
52 
53  /// @return a non-writable pointer (even if object is non-const)
54  const void* constData
55  ()
56  const;
57 
58  #ifndef NDEBUG
59  int getRefCount
60  ()
61  const;
62  #endif
63 
64  private:
65  void* d;
66 
67  template <typename T>
68  void* to_data
69  (T* p);
70 
71  void _trace
72  (const char*)
73  #ifndef TRACE_SHARE
74  {
75  }
76  #endif
77  ;
78 
79  static void _trace
80  (const char*,
81  const void*)
82  #ifndef TRACE_SHARE
83  {
84  }
85  #endif
86  ;
87  };
88 
89  // ==========================================================
90  // ==========================================================
91  // ==========================================================
92 
93  inline
95  () :
96  d(0)
97  {
98  }
99 
100  inline
101  bool SharedVoidPointer::operator!
102  ()
103  const
104  {
105  return !d;
106  }
107 
108  inline
109  const void* SharedVoidPointer::data
110  ()
111  const
112  {
113  return d;
114  }
115 
116  inline
117  const void* SharedVoidPointer::constData
118  ()
119  const
120  {
121  return d;
122  }
123 };
124 
125 #endif
A low-level data holder.
Definition: types_c.h:82
const void * constData() const
Definition: sharedvoid.h:118
const void * data() const
Definition: sharedvoid.h:110
uint const Xpace_Char8 * data
Definition: table_c.h:180
Xpace project main namespace
Definition: datetime.h:18
an anonymous pointer, used only in conjunction with SharedImplPointer
Definition: sharedvoid.h:21

current as of Wed Jun 10 2026 12:00:05