• Main Page
  • Classes
  • Files
  • File List
  • File Members

Beesnest/Interfaces/BufferHolder.h

Go to the documentation of this file.
00001 /*
00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net)
00003 This file is part of Beesnest.
00004 Beesnest is released under the GNU General Public License.
00005 But this file is in the public domain, you can do whatever you want with it.
00006 */
00007 
00008 #ifndef __BUFFER_HOLDER
00009 #define __BUFFER_HOLDER
00010 
00011 #include <string.h>
00012 
00013 /**
00014  * I use this very simple class to pass buffers between libraries and the main
00015  * program. it is just an easy way to transfer buffer that doesn't necessarily
00016  * end with NULL. The recipient cannot (should not) change the buffer!!! Never!!!
00017  * Everything is public here.
00018  * <p>
00019  * Note that this class may "point" to NULL, but you will never get a
00020  * BufferHolder that holds NULL, from Beesnest!
00021  * <p>
00022  * This is the only "implemented" class I use in adapters/engines. Beesnest
00023  * and the adapters/engines has to use exactly the same base class. However
00024  * you can inherit from this class if you wish.
00025  */
00026 class BufferHolder
00027 {
00028 public:
00029 
00030     /** Pointer to the buffer we need to hold. */
00031     const char* pointer;
00032     /** The size of the buffer. */
00033     int size;
00034 
00035     /**
00036      * Default constructor. Set an empty Buffer Holder.
00037      */
00038     BufferHolder () : pointer (NULL), size (0) {}
00039 
00040     /**
00041      * Constructor - Just call Set.
00042      * @param pstr Pointer to the buffer to hold.
00043      * @param str_size Optional, the buffer size. If missing, the size will be
00044      *  the size until the first NULL.
00045      */
00046     BufferHolder (const char* pstr, int str_size = 0)
00047     { set (pstr, str_size); }
00048 
00049     /**
00050      * Set - initialize the Buffer Holder with a buffer or a "C" style string.
00051      * <p>
00052      * @param pstr Pointer to the buffer to hold.
00053      * @param str_size Optional, the buffer size. If missing, the size will be
00054      *  the size until the first NULL.
00055      */
00056     void set (const char* pstr, int str_size = 0)
00057     {
00058         pointer = pstr; size = str_size;
00059         if (pointer && !size) size = strlen (pointer);
00060     }
00061 
00062     /**
00063      * Returns True if BufferHoldr is empty.
00064      */
00065     bool empty () { return !pointer || !size; }
00066 };
00067 
00068 #endif  /*__BUFFER_HOLDER */
00069 
00070 

Generated on Mon Oct 11 2010 16:23:25 for Beesnest by  doxygen 1.7.2