/builddir/build/BUILD/infinispan-hotrod-cpp-6.2.1.Final-Source/include/infinispan/hotrod/ScopedBuffer.h

Go to the documentation of this file.
00001 #ifndef ISPN_HOTROD_SCOPEDBUFFER_H
00002 #define ISPN_HOTROD_SCOPEDBUFFER_H
00003 
00004 
00005 
00006 #include "infinispan/hotrod/exceptions.h"
00007 
00008 namespace infinispan {
00009 namespace hotrod {
00010 
00011 /*
00012  * A semi-smart pointer object to hold intermediate marshalled data in the
00013  * lifetime of a block.  For default case, the bytes are "owned" by
00014  * the scope and freed when the destructor is called on block exit.  Not for
00015  * general use.  Intended for short lived serialized bytes passed
00016  * between a marshaller and Hot Rod.
00017  */
00018 // TODO: provide small internal buffer to reduce the need of heap allocation
00019 //       when it should be filled with little data
00020 class ScopedBuffer
00021 {
00022   public:
00023     typedef void (*ReleaseFunc)(ScopedBuffer *);
00024     ScopedBuffer() : bytes(0), len(0), release(0) {}
00025     ~ScopedBuffer() {
00026         if (release)
00027             (*release)(this);
00028         else
00029             delete[] bytes;
00030     }
00031     void set(char *b, size_t l, ReleaseFunc m = 0) {
00032         if (bytes || len || release) throw HotRodClientException("ScopedBuffer reuse");
00033         bytes = b; len = l; release = m;
00034     }
00035     char* getBytes() const { return bytes; }
00036     size_t getLength() const { return len; }
00037     ReleaseFunc getRelease() const { return release; }
00038     
00039   private:
00040     ScopedBuffer(const ScopedBuffer &);
00041     ScopedBuffer& operator=(ScopedBuffer const &);
00042 
00043     char* bytes;
00044     size_t len;
00045     ReleaseFunc release;
00046 };
00047 
00048 }} // namespace
00049 
00050 #endif  /* ISPN_HOTROD_SCOPEDBUFFER_H */

Generated on 25 Mar 2015 for JBoss Data Grid HotRod C++ Client by  doxygen 1.4.7