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

GroupChunk.cxx

00001 /*
00002  * Copyright (C) 1991-9 Eric M. Hopper <hopper@omnifarious.mn.org>
00003  * 
00004  *     This program is free software; you can redistribute it and/or modify it
00005  *     under the terms of the GNU Lesser General Public License as published
00006  *     by the Free Software Foundation; either version 2 of the License, or
00007  *     (at your option) any later version.
00008  * 
00009  *     This program is distributed in the hope that it will be useful, but
00010  *     WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *     Lesser General Public License for more details.
00013  * 
00014  *     You should have received a copy of the GNU Lesser General Public
00015  *     License along with this program; if not, write to the Free Software
00016  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 /* $Header: /home/hopper/src/cvs/C++/StrMod/GroupChunk.cxx,v 1.8 2002/03/12 21:48:57 hopper Exp $ */
00020 
00021 // See ChangeLog for log.
00022 // Revision 1.1  1996/06/29 06:51:22  hopper
00023 // New class GroupChunk to hold a group of chunks and make them appear to
00024 // be one chunk.
00025 //
00026 
00027 #ifdef __GNUG__
00028 #  pragma implementation "GroupChunk.h"
00029 #endif
00030 
00031 #include <StrMod/GroupChunk.h>
00032 #include <StrMod/StrChunkPtr.h>
00033 #include <StrMod/StrChunk.h>
00034 #include <StrMod/LinearExtent.h>
00035 // #include <iostream>
00036 
00037 namespace strmod {
00038 namespace strmod {
00039 
00040 const STR_ClassIdent GroupChunk::identifier(20UL);
00041 
00042 // We deal with StrChunk *'s directly because it's more efficient.  We try
00043 // to hide this fact as much as possible from the outside world.
00044 
00045 GroupChunk::GroupChunk() : totalsize_(0)
00046 {
00047 }
00048 
00049 GroupChunk::~GroupChunk()
00050 {
00051    ChunkList::iterator i;
00052    ChunkList::iterator end;
00053 
00054    end = chnklist_.end();
00055    for (i = chnklist_.begin(); i != end; ++i) {
00056       StrChunk *ptr = *i;
00057 
00058       *i = 0;
00059       if (ptr) {
00060          ptr->DelReference();
00061          if (ptr->NumReferences() <= 0) {
00062             delete ptr;
00063          }
00064       }
00065    }
00066 }
00067 
00068 void GroupChunk::push_back(const StrChunkPtr &chnk)
00069 {
00070    StrChunk *ptr = chnk.GetPtr();
00071 
00072    ptr->AddReference();
00073    chnklist_.push_back(ptr);
00074    totalsize_ += ptr->Length();
00075 }
00076 
00077 void GroupChunk::push_front(const StrChunkPtr &chnk)
00078 {
00079    StrChunk *ptr = chnk.GetPtr();
00080 
00081    ptr->AddReference();
00082    chnklist_.push_front(ptr);
00083    totalsize_ += ptr->Length();
00084 }
00085 
00086 void GroupChunk::acceptVisitor(ChunkVisitor &visitor)
00087    throw(ChunkVisitor::halt_visitation)
00088 {
00089    for (ChunkList::const_iterator i = chnklist_.begin(),
00090                             listend = chnklist_.end(); i != listend; ++i)
00091    {
00092       call_visitStrChunk(visitor, *i);
00093    }
00094 }
00095 
00096 }  // End namespace strmod
00097 }  // End namespace strmod

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