Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

StaticBuffer.h

00001 #ifndef _STR_StaticBuffer_H_  // -*- mode: c++; c-file-style: "hopper" -*-
00002 
00003 /*
00004  * Copyright 1991-2002 Eric M. Hopper <hopper@omnifarious.org>
00005  * 
00006  *     This program is free software; you can redistribute it and/or modify it
00007  *     under the terms of the GNU Lesser General Public License as published
00008  *     by the Free Software Foundation; either version 2 of the License, or
00009  *     (at your option) any later version.
00010  * 
00011  *     This program is distributed in the hope that it will be useful, but
00012  *     WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *     Lesser General Public License for more details.
00015  * 
00016  *     You should have received a copy of the GNU Lesser General Public
00017  *     License along with this program; if not, write to the Free Software
00018  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifdef __GNUG__
00022 #  pragma interface
00023 #endif
00024 
00025 /* $Header: /home/hopper/src/cvs/C++/StrMod/StrMod/StaticBuffer.h,v 1.3 2002/08/29 00:58:04 hopper Exp $ */
00026 
00027 // For a log, see ../ChangeLog
00028 
00029 #include <StrMod/StrChunk.h>
00030 #include <cstddef>
00031 
00032 #define _STR_StaticBuffer_H_
00033 
00034 namespace strmod {
00035 namespace strmod {
00036 
00037 /** \class StaticBuffer StaticBuffer.h StrMod/StaticBuffer.h
00038  * This class is for pointing at a bunch of data already in memory that will
00039  * not change or move for the lifetime of the StaticBuffer.  Oftentimes, these
00040  * will be things like string constants and such.
00041  */
00042 class StaticBuffer : public StrChunk
00043 {
00044  private:
00045    typedef lcore::U1Byte U1Byte;
00046  public:
00047    static const STR_ClassIdent identifier;
00048 
00049    /** Construct a StaticBuffer pointing at the given buffer area.
00050     *
00051     * @param buf The area to point at.
00052     *
00053     * @param buflen The size of the area to point at.
00054     */
00055    inline StaticBuffer(const void *buf, size_t buflen);
00056    /** Doesn't do a thing because it doesn't own the storage it's pointing
00057     * at.
00058     */
00059    virtual ~StaticBuffer()                              { }
00060 
00061    virtual int AreYouA(const lcore::ClassIdent &cid) const {
00062       return (identifier == cid) || StrChunk::AreYouA(cid);
00063    }
00064 
00065    virtual unsigned int Length() const                  { return buflen_; }
00066 
00067    //! Get a void pointer to the memory pointed at by this chunk.
00068    const void *getVoidP()                               { return(buf_); }
00069    //! Get a possibly more convenient character pointer instead.
00070    inline const U1Byte *getCharP();
00071 
00072  protected:
00073    virtual const lcore::ClassIdent *i_GetIdent() const  { return &identifier; }
00074 
00075    inline virtual void acceptVisitor(ChunkVisitor &visitor)
00076       throw(ChunkVisitor::halt_visitation);
00077 
00078  private:
00079    const void * const buf_;
00080    const size_t buflen_;
00081 };
00082 
00083 //-----------------------------inline functions--------------------------------
00084 
00085 inline StaticBuffer::StaticBuffer(const void *buf, size_t buflen)
00086      : buf_(buf), buflen_(buflen)
00087 {
00088 }
00089 
00090 inline const lcore::U1Byte *StaticBuffer::getCharP()
00091 {
00092    return(static_cast<const U1Byte *>(buf_));
00093 }
00094 
00095 inline void StaticBuffer::acceptVisitor(ChunkVisitor &visitor)
00096    throw(ChunkVisitor::halt_visitation)
00097 {
00098    call_visitDataBlock(visitor, const_cast<void *>(buf_), buflen_);
00099 }
00100 
00101 };  // namespace strmod
00102 };  // namespace strmod
00103 
00104 #endif

Generated on Wed Jan 29 00:32:44 2003 for libNet by doxygen1.3-rc1