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 
00019 class ScopedBuffer
00020 {
00021   public:
00022     typedef void (*ReleaseFunc)(ScopedBuffer *);
00023     ScopedBuffer() : bytes(0), len(0), release(0) {}
00024     ~ScopedBuffer() {
00025         if (release)
00026             (*release)(this);
00027         else
00028             delete[] bytes;
00029     }
00030     void set(char *b, size_t l, ReleaseFunc m = 0) {
00031         if (bytes || len || release) throw HotRodClientException("ScopedBuffer reuse");
00032         bytes = b; len = l; release = m;
00033     }
00034     char* getBytes() const { return bytes; }
00035     size_t getLength() const { return len; }
00036     ReleaseFunc getRelease() const { return release; }
00037     
00038   private:
00039     ScopedBuffer(const ScopedBuffer &);
00040     ScopedBuffer& operator=(ScopedBuffer const &);
00041 
00042     char* bytes;
00043     size_t len;
00044     ReleaseFunc release;
00045 };
00046 
00047 }} // namespace
00048 
00049 #endif  /* ISPN_HOTROD_SCOPEDBUFFER_H */

Generated on 26 Mar 2014 for InfinispanHotRodC++Client by  doxygen 1.4.7