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

InfiniteModule.h

00001 #ifndef _STR_InfiniteModule_H_  // -*-c++-*-
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/InfiniteModule.h,v 1.5 2002/08/29 00:58:04 hopper Exp $ */
00026 
00027 // For a log, see ../ChangeLog
00028 
00029 #include <StrMod/StreamModule.h>
00030 #include <StrMod/StrChunkPtr.h>
00031 
00032 #define _STR_InfiniteModule_H_
00033 
00034 namespace strmod {
00035 namespace strmod {
00036 
00037 /** \class InfiniteModule InfiniteModule.h StrMod/InfiniteModule.h
00038  * \brief Sends a particular chunk repeatedly forever.  Eats any chunk sent to
00039  * it.
00040  *
00041  * This strongly resembles a /dev/zero where you decide what comes out instead
00042  * of an infinite string of zeros.
00043  */
00044 class InfiniteModule : public StreamModule
00045 {
00046    class IPlug;
00047    friend class IPlug;
00048 
00049  public:
00050    static const STR_ClassIdent identifier;
00051 
00052    /** Construct given a chunk to repeatedly send.
00053     * @param chnk The chunk to repeatedly send.
00054    */
00055    InfiniteModule(const StrChunkPtr &chnk);
00056    //! Destroy an InfiniteModule
00057    InfiniteModule();
00058    virtual ~InfiniteModule();
00059 
00060    inline virtual int AreYouA(const lcore::ClassIdent &cid) const;
00061 
00062    inline virtual bool canCreate(int side = 0) const;
00063    inline Plug *makePlug(int side = 0);
00064    inline virtual bool ownsPlug(const Plug *plug) const;
00065    virtual bool deletePlug(Plug *plug);
00066 
00067  protected:
00068    virtual const lcore::ClassIdent *i_GetIdent() const  { return &identifier; }
00069 
00070    virtual Plug *i_MakePlug(int side);
00071 
00072  private:
00073    class IPlug : public Plug {
00074     public:
00075       friend class InfiniteModule;
00076 
00077       static const STR_ClassIdent identifier;
00078 
00079       IPlug(InfiniteModule &parent) : Plug(parent)      { }
00080       ~IPlug()                                          { }
00081 
00082       inline virtual int AreYouA(const lcore::ClassIdent &cid) const;
00083 
00084       inline InfiniteModule &getParent() const;
00085       virtual int side() const                          { return(0); }
00086 
00087     protected:
00088       virtual const lcore::ClassIdent *i_GetIdent() const {
00089          return &identifier;
00090       }
00091 
00092       inline virtual const StrChunkPtr i_Read();
00093       inline virtual void i_Write(const StrChunkPtr &tr);
00094    };
00095 
00096    StrChunkPtr feed_;
00097    bool plug_created_;
00098    IPlug plug_;
00099 };
00100 
00101 //-----------------------------inline functions--------------------------------
00102 
00103 inline int InfiniteModule::AreYouA(const lcore::ClassIdent &cid) const
00104 {
00105    return((identifier == cid) || StreamModule::AreYouA(cid));
00106 }
00107 
00108 inline bool InfiniteModule::canCreate(int side) const
00109 {
00110    return((side == 0) && !plug_created_);
00111 }
00112 
00113 inline StreamModule::Plug *InfiniteModule::makePlug(int side)
00114 {
00115    return(StreamModule::makePlug(side));
00116 }
00117 
00118 inline bool InfiniteModule::ownsPlug(const Plug *plug) const
00119 {
00120    return((&plug_ == plug) && plug_created_);
00121 }
00122 
00123 //--
00124 
00125 inline int InfiniteModule::IPlug::AreYouA(const lcore::ClassIdent &cid) const
00126 {
00127    return((identifier == cid) || Plug::AreYouA(cid));
00128 }
00129 
00130 inline InfiniteModule &InfiniteModule::IPlug::getParent() const
00131 {
00132    return(static_cast<InfiniteModule &>(Plug::getParent()));
00133 }
00134 
00135 const StrChunkPtr InfiniteModule::IPlug::i_Read()
00136 {
00137    return(getParent().feed_);
00138 }
00139 
00140 void InfiniteModule::IPlug::i_Write(const StrChunkPtr &ptr)
00141 {
00142 }
00143 
00144 };  // namespace strmod
00145 };  // namespace strmod
00146 
00147 #endif

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