NSCL DDAS  12.1-001
Support for XIA DDAS at FRIB
ReferenceCountedBuffer.h
Go to the documentation of this file.
1 /*
2  This software is Copyright by the Board of Trustees of Michigan
3  State University (c) Copyright 2017.
4 
5  You may use this software under the terms of the GNU public license
6  (GPL). The terms of this license are described at:
7 
8  http://www.gnu.org/licenses/gpl.txt
9 
10  Authors:
11  Ron Fox
12  Giordano Cerriza
13  NSCL
14  Michigan State University
15  East Lansing, MI 48824-1321
16 */
17 
23 #ifndef REFERENCECOUNTEDBUFFER_H
24 #define REFERENCECOUNTEDBUFFER_H
25 
26 #include <stddef.h>
27 #include <stdint.h>
28 
30 namespace DDASReadout {
31 
53  {
54  size_t s_size;
55  size_t s_references;
56  void* s_pData;
57 
64  ReferenceCountedBuffer(size_t initialSize = 0);
66  virtual ~ReferenceCountedBuffer();
67 
68  // Reference count management:
69 
71  void reference();
73  void dereference();
80  bool isReferenced();
81 
82  // Other:
83 
90  void resize(size_t newSize);
91 
92  // Syntactical sugar for the most common casts; still nothing to stop
93  // someone from mytyp* p = static_cast<mytyp*>(somebuffer.s_pData);
94 
95  operator uint8_t*() { return static_cast<uint8_t*>(s_pData); }
96  operator uint16_t*() { return static_cast<uint16_t*>(s_pData); }
97  operator uint32_t*() { return static_cast<uint32_t*>(s_pData); }
98  };
99 
100 } // Namespace
101 
102 #endif
Definition: BufferArena.cpp:29
A reference-counted buffer with dynamic storage.
Definition: ReferenceCountedBuffer.h:53
void * s_pData
Data pointer.
Definition: ReferenceCountedBuffer.h:56
size_t s_references
Number of references.
Definition: ReferenceCountedBuffer.h:55
void dereference()
Remove a reference to the storage.
Definition: ReferenceCountedBuffer.cpp:83
size_t s_size
Number of bytes of data.
Definition: ReferenceCountedBuffer.h:54
void resize(size_t newSize)
Resize the storage.
Definition: ReferenceCountedBuffer.cpp:104
void reference()
Add a reference to the storage.
Definition: ReferenceCountedBuffer.cpp:73
virtual ~ReferenceCountedBuffer()
Destructor.
Definition: ReferenceCountedBuffer.cpp:56
ReferenceCountedBuffer(size_t initialSize=0)
Construct the buffer.
Definition: ReferenceCountedBuffer.cpp:39
bool isReferenced()
Are there references to the object?
Definition: ReferenceCountedBuffer.cpp:89