00001 #ifndef _STR_GroupChunk_H_ // -*-c++-*- 00002 00003 /* 00004 * Copyright (C) 1991-9 Eric M. Hopper <hopper@omnifarious.mn.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/GroupChunk.h,v 1.9 2002/08/29 00:58:04 hopper Exp $ */ 00026 00027 // See ../ChangeLog for log. 00028 // Revision 1.1 1996/06/29 06:51:30 hopper 00029 // New class GroupChunk to hold a group of chunks and make them appear to 00030 // be one chunk. 00031 // 00032 00033 #include <StrMod/StrChunk.h> 00034 #include <deque> 00035 00036 #define _STR_GroupChunk_H_ 00037 00038 namespace strmod { 00039 namespace strmod { 00040 00041 class StrChunkPtr; 00042 00043 /** \class GroupChunk GroupChunk.h StrMod/GroupChunk.h 00044 * \brief A StrChunk that consists of a concatentation of other StrChunks. 00045 * 00046 * GroupChunks are used to concatenate together a bunch of StrChunks without 00047 * having to move any of their memory. To the outside, a GroupChunk appears as 00048 * a single, contiguous StrChunk, but internally it is composed of a list of 00049 * pointers to it's subsidiary StrChunks. 00050 * 00051 * This class plays the role of Composite in the <a href="http://exciton.cs.oberlin.edu/javaresources/DesignPatterns/composite.htm">Composite</a> 00052 * pattern. 00053 */ 00054 class GroupChunk : public StrChunk 00055 { 00056 typedef std::deque<StrChunk *> ChunkList; 00057 public: 00058 static const STR_ClassIdent identifier; 00059 00060 //! Construct an empty GroupChunk 00061 GroupChunk(); 00062 //! Dereferences all direct children. 00063 virtual ~GroupChunk(); 00064 00065 inline virtual int AreYouA(const lcore::ClassIdent &cid) const; 00066 00067 virtual unsigned int Length() const { return(totalsize_); } 00068 00069 //! Concatenate a StrChunk to the end of the GroupChunk 00070 void push_back(const StrChunkPtr &chnk); 00071 //! Prepend a StrChunk to this GroupChunk 00072 void push_front(const StrChunkPtr &chnk); 00073 00074 protected: 00075 virtual const lcore::ClassIdent *i_GetIdent() const { return &identifier; } 00076 00077 //: Accept a ChunkVisitor, and maybe lead it through your children. 00078 virtual void acceptVisitor(ChunkVisitor &visitor) 00079 throw(ChunkVisitor::halt_visitation); 00080 00081 private: 00082 ChunkList chnklist_; 00083 unsigned int totalsize_; 00084 00085 GroupChunk(const GroupChunk &); 00086 void operator =(const GroupChunk &); 00087 }; 00088 00089 //-----------------------------inline functions-------------------------------- 00090 00091 inline int GroupChunk::AreYouA(const lcore::ClassIdent &cid) const 00092 { 00093 return((identifier == cid) || StrChunk::AreYouA(cid)); 00094 } 00095 00096 } // namespace strmod 00097 } // namespace strmod 00098 00099 #endif
1.3-rc1