JBoss Data Grid HotRod C++ Client  6.6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ScopedBuffer.h
Go to the documentation of this file.
1 #ifndef ISPN_HOTROD_SCOPEDBUFFER_H
2 #define ISPN_HOTROD_SCOPEDBUFFER_H
3 
4 
5 
7 
8 namespace infinispan {
9 namespace hotrod {
10 
11 /*
12  * A semi-smart pointer object to hold intermediate marshalled data in the
13  * lifetime of a block. For default case, the bytes are "owned" by
14  * the scope and freed when the destructor is called on block exit. Not for
15  * general use. Intended for short lived serialized bytes passed
16  * between a marshaller and Hot Rod.
17  */
18 // TODO: provide small internal buffer to reduce the need of heap allocation
19 // when it should be filled with little data
21 {
22  public:
23  typedef void (*ReleaseFunc)(ScopedBuffer *);
24  ScopedBuffer() : bytes(0), len(0), release(0) {}
26  if (release)
27  (*release)(this);
28  else
29  delete[] bytes;
30  }
31  void set(char *b, size_t l, ReleaseFunc m = 0) {
32  if (bytes || len || release) throw HotRodClientException("ScopedBuffer reuse");
33  bytes = b; len = l; release = m;
34  }
35  char* getBytes() const { return bytes; }
36  size_t getLength() const { return len; }
37  ReleaseFunc getRelease() const { return release; }
38 
39  private:
40  ScopedBuffer(const ScopedBuffer &);
41  ScopedBuffer& operator=(ScopedBuffer const &);
42 
43  char* bytes;
44  size_t len;
45  ReleaseFunc release;
46 };
47 
48 }} // namespace
49 
50 #endif /* ISPN_HOTROD_SCOPEDBUFFER_H */
size_t getLength() const
Definition: ScopedBuffer.h:36
ScopedBuffer()
Definition: ScopedBuffer.h:24
ReleaseFunc getRelease() const
Definition: ScopedBuffer.h:37
char * getBytes() const
Definition: ScopedBuffer.h:35
Definition: ScopedBuffer.h:20
void(* ReleaseFunc)(ScopedBuffer *)
Definition: ScopedBuffer.h:23
void set(char *b, size_t l, ReleaseFunc m=0)
Definition: ScopedBuffer.h:31
~ScopedBuffer()
Definition: ScopedBuffer.h:25