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

UseTrackingVisitor.h

00001 #ifndef _STR_UseTrackingVisitor_H_  // -*-mode: c++; c-file-style: "hopper";-*-
00002 
00003 /*
00004  * Copyright 2000-2002 by 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/UseTrackingVisitor.h,v 1.8 2002/08/29 00:58:05 hopper Exp $ */
00026 
00027 // For a log, see ../ChangeLog
00028 
00029 #include <cstddef>
00030 #include <StrMod/LinearExtent.h>
00031 #include <StrMod/StrChunkPtr.h>
00032 #include <StrMod/ChunkVisitor.h>
00033 
00034 #define _STR_UseTrackingVisitor_H_
00035 
00036 namespace strmod {
00037 namespace strmod {
00038 
00039 /** \class UseTrackingVisitor UseTrackingVisitor.h StrMod/UseTrackingVisitor.h
00040  * Simplifies the Visitor interface down so that derived classes don't have to
00041  * worry about tracking which parts of a StrChunk are actually used.
00042  */
00043 class UseTrackingVisitor : public ChunkVisitor
00044 {
00045  public:
00046    static const STR_ClassIdent identifier;
00047 
00048    /**
00049     * Constructor.
00050     */
00051    UseTrackingVisitor(bool ignorezeros = false);
00052    /**
00053     * \brief Destructor.  Doesn't do much.
00054     */
00055    virtual ~UseTrackingVisitor()                      { }
00056 
00057    virtual int AreYouA(const lcore::ClassIdent &cid) const   {
00058       return((identifier == cid) || ChunkVisitor::AreYouA(cid));
00059    }
00060 
00061  protected:
00062    virtual const lcore::ClassIdent *i_GetIdent() const  { return &identifier; }
00063 
00064 
00065    /** \name Only overload these
00066     * <strong>Only overload these functions, not the various private visit*
00067     * functions down below.</strong>
00068     */
00069    //@{
00070    /**
00071     * \brief This is the Template Method function to visit a StrChunk.  Called
00072     * by the UseTracking machinery.
00073     *
00074     * @param chunk The chunk being visited.
00075     *
00076     * @param extent Which extent of the chunk is used.
00077     */
00078    virtual void use_visitStrChunk(const StrChunkPtr &chunk,
00079                                   const LinearExtent &used)
00080       throw(halt_visitation) = 0;
00081    /**
00082     * \brief This is the Template Method function to visit an actual chunk of
00083     * data.  Called by the UseTracking machinery.
00084     *
00085     * @param start Start of the portion of the data area that's used.
00086     *
00087     * @param len Length of the used part of the data area.
00088     *
00089     * @param realstart Start of the actual data area, including the unused
00090     * portions.
00091     *
00092     * @param reallen Length of the actual data area, including the unsused
00093     * portions.
00094     */
00095    virtual void use_visitDataBlock(const void *start, size_t len,
00096                                    const void *realstart, size_t reallen)
00097       throw(halt_visitation) = 0;
00098    //@}
00099 
00100    /**
00101     * Retrieves the parent StrChunk of the currently visited chunk or piece of
00102     * data.
00103     */
00104    inline const StrChunkPtr &getParent() const;
00105    /**
00106     * Retrieves the offset of where the currently visited chunk or piece of
00107     * data is within its parent.
00108     */
00109    inline const LinearExtent::off_t parentOffset() const;
00110 
00111    /**
00112     * Start a traversal of a chunk DAG.
00113     */
00114    inline void startVisit(const StrChunkPtr &root);
00115 
00116  private:
00117    LinearExtent curext_;
00118    LinearExtent::off_t curpos_;
00119    StrChunkPtr curchnk_;
00120    const bool ignorezeros_;
00121 
00122    //! Don't overload this function in derived classes!  (Wish I had Java's
00123    //! 'final'.)
00124    virtual void visitStrChunk(const StrChunkPtr &chunk)
00125       throw(halt_visitation);
00126    //! Don't overload this function in derived classes!  (Wish I had Java's
00127    //! 'final'.)
00128    virtual void visitStrChunk(const StrChunkPtr &chunk,
00129                               const LinearExtent &used)
00130       throw(halt_visitation);
00131    //! Don't overload this function in derived classes!  (Wish I had Java's
00132    //! 'final'.)
00133    virtual void visitDataBlock(const void *start, size_t len)
00134       throw(halt_visitation);
00135 
00136    const LinearExtent computeUsed(const LinearExtent &used);
00137    void do_acceptVisitor(const StrChunkPtr &chunk, const LinearExtent &chunkext)
00138       throw(halt_visitation);
00139 };
00140 
00141 //-----------------------------inline functions--------------------------------
00142 
00143 inline const StrChunkPtr &UseTrackingVisitor::getParent() const
00144 {
00145    return(curchnk_);
00146 }
00147 
00148 inline const LinearExtent::off_t UseTrackingVisitor::parentOffset() const
00149 {
00150    return(curpos_);
00151 }
00152 
00153 /*!
00154  * @param root The root of the DAG to visit.
00155  */
00156 inline void UseTrackingVisitor::startVisit(const StrChunkPtr &root)
00157 {
00158    curpos_ = 0;
00159    curext_ = LinearExtent::full_extent;
00160    visitStrChunk(root);
00161 }
00162 
00163 }  // namespace strmod
00164 }  // namespace strmod
00165 
00166 #endif

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