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

ChunkVisitor.h

00001 #ifndef _STR_ChunkVisitor_H_  // -*-c++-*-
00002 
00003 /*
00004  * Copyright 2000 by 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/ChunkVisitor.h,v 1.9 2002/11/25 05:40:05 hopper Exp $ */
00026 
00027 // For a log, see ../ChangeLog
00028 
00029 #include <cstddef>
00030 #include <stdexcept>
00031 #include <LCore/Protocol.h>
00032 #include <StrMod/STR_ClassIdent.h>
00033 #include <StrMod/LinearExtent.h>
00034 
00035 #define _STR_ChunkVisitor_H_
00036 
00037 namespace strmod {
00038 namespace strmod {
00039 
00040 class StrChunkPtr;
00041 class StrChunk;
00042 
00043 /** \class ChunkVisitor ChunkVisitor.h StrMod/ChunkVisitor.h
00044  * The interface for a StrChunk visitor.
00045  *
00046  * Part of an implementation of the <A HREF="http://exciton.cs.oberlin.edu/javaresources/DesignPatterns/VisitorPattern.htm">Visitor  pattern</A>
00047  * for traversing StrChunk DAGs.
00048  *
00049  * A StrChunk may be visited many times because the StrChunk containment
00050  * hierarchy is a DAG.  This means that a given StrChunk can be contained
00051  * through more than one path, though it can never contain itself.  Because a
00052  * StrChunk can contain 'substrings' of other StrChunks, each time a StrChunk
00053  * is visited, it may have different constraints stating which part of the
00054  * data or StrChunks it contains are visible to the parent.
00055  *
00056  * Derived classes should provide some sort of 'visit' method that takes at
00057  * least the top level chunk to be visited as an argument.  It isn't provided
00058  * here because many visitor classes will have build up and tear down
00059  * operations to perform before visiting.
00060  */
00061 class ChunkVisitor : public lcore::Protocol {
00062    friend class StrChunk;
00063  public:
00064    //! An exception to allow the visitor to halt the traversal.
00065    class halt_visitation : public std::exception {
00066    };
00067    static const STR_ClassIdent identifier;
00068 
00069    //! Do nothing constructor for interface class.
00070    ChunkVisitor()                                   { }
00071    //! Do nothing virtual destructor for interface class.
00072    virtual ~ChunkVisitor()                          { }
00073 
00074    virtual int AreYouA(const lcore::ClassIdent &cid) const {
00075       return((identifier == cid) || Protocol::AreYouA(cid));
00076    }
00077 
00078  protected:
00079    virtual const lcore::ClassIdent *i_GetIdent() const { return(&identifier); }
00080 
00081    /** \name StrChunk visit functions
00082     */
00083    //@{
00084    /**
00085     * Visit a StrChunk, with no extent constraints imposed by parent.
00086     */
00087    virtual void visitStrChunk(const StrChunkPtr &chunk)
00088       throw(halt_visitation) = 0;
00089    /**
00090     * Visit a StrChunk, with extent constraints imposed by parent.
00091     */
00092    virtual void visitStrChunk(const StrChunkPtr &chunk,
00093                               const LinearExtent &used)
00094       throw(halt_visitation) = 0;
00095    //@}
00096    //! Visit some raw data in a StrChunk.
00097    virtual void visitDataBlock(const void *start, size_t len)
00098       throw(halt_visitation) = 0;
00099 
00100    /**
00101     * Call the StrChunk's 'acceptVisitor' method to visit a StrChunk's
00102     * children.
00103     *
00104     * This exists so derived classes will have very limited and controlled
00105     * access to a protected member function of StrChunk.  It always provides
00106     * <code>this</code> as the visitor argument of StrChunk::acceptVisitor.
00107     *
00108     * @param chnk The StrChunk to call acceptVisitor on.
00109     */
00110    void call_acceptVisitor(const StrChunkPtr &chnk)
00111       throw(halt_visitation);
00112 };
00113 
00114 }  // namespace strmod
00115 }  // namespace strmod
00116 
00117 #endif

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