AaronCameron.net
Because you all make me very, very tired.
Not a Member? - Login or Create an Account
Wednesday the 23rd of May 2012 @ 06:29pm
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cUniStreamImp.h

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2003  Aaron Cameron
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 
00019 A copy of the GNU Lesser General Public License has been provided with
00020 this library in the file 'COPYING'.
00021 
00022 Contact information for the author of this library has been provided
00023 with this library in the file 'AUTHOR'.
00024 ************************************************************************/
00025 #ifndef _n2l4_cUniStreamImp_H
00026 #define _n2l4_cUniStreamImp_H
00027 
00028 #include "n2l/n2l.h"
00029 
00030 #include "cStreamFilterInterface.h"
00031 #include "cInsertionStreamInterface.h"
00032 #include "cStreamConverterInterface.h"
00033 
00034 #include <vector>
00035 
00036 
00037 namespace n2l
00038 {
00042     template <  class TIValue,
00043                 class TOValue,
00044                 class TVContainer >
00045     class cUniStreamImp
00046     {
00047     public:
00048         typedef cUniStreamImp<TIValue,TOValue,TVContainer> tThis;
00049         
00050         typedef TIValue     tInValue;
00051         typedef TOValue     tOutValue;
00052         typedef TVContainer tValueContainer;
00053 
00054         typedef cStreamConverterInterface<tInValue,tOutValue>   tConverter;
00055 
00056         // Seperate joins and filters into pre and post conversions
00057         typedef cInsertionStreamInterface<tInValue> tPreConvJoiner;
00058         typedef cStreamFilterInterface<tInValue>    tPreFilter;
00059         
00060         typedef cInsertionStreamInterface<tInValue> tPostConvJoiner;
00061         typedef cStreamFilterInterface<tOutValue>   tPostFilter;
00062         
00063         typedef typename tValueContainer::size_type tSize;
00064         
00065         
00066         typedef std::vector<cAutoPtr<tPreFilter> >      tPreFilterContainer;
00067         typedef typename tPreFilterContainer::iterator  tPreFilterIterator;
00068         
00069         typedef std::vector<cAutoPtr<tPostFilter> >     tPostFilterContainer;
00070         typedef typename tPostFilterContainer::iterator tPostFilterIterator;
00071 
00072 
00073         typedef std::vector<cAutoPtr<tPreConvJoiner> >      tPreConvJoinContainer;
00074         typedef typename tPreConvJoinContainer::iterator    tPreConvJoinIterator;
00075 
00076         typedef std::vector<cAutoPtr<tPostConvJoiner> >     tPostConvJoinContainer;
00077         typedef typename tPostConvJoinContainer::iterator   tPostConvJoinIterator;
00078 
00079         /* ************************************************************ */
00080         cUniStreamImp( const cAutoPtr<tConverter> & i_ioConverter ) :
00081             mConverter(i_ioConverter),
00082             mConnected(true)
00083         {
00084         }
00085 
00086 
00087         /* ************************************************************ */
00088         void push( const tInValue & i_value )
00089         {
00090             if (!connected()) return;
00091 
00092             const tPreFilterIterator EndPreFilterIt = mPreFilters.end();
00093             for (   tPreFilterIterator filterIt = mPreFilters.begin();
00094                     EndPreFilterIt!=filterIt; ++filterIt )
00095                 if (!(*filterIt)->allow(i_value)) return;
00096 
00097             const tPreConvJoinIterator EndPreStreamIt = mPreConvJoiners.end();
00098             for (   tPreConvJoinIterator streamIt = mPreConvJoiners.begin();
00099                     EndPreStreamIt!=streamIt; ++streamIt )
00100                 (*streamIt)->push(i_value);
00101 
00102             tOutValue temp;
00103             mConverter->convert(temp,i_value);
00104 
00105             const tPostFilterIterator EndPostFilterIt = mPostFilters.end();
00106             for (   tPostFilterIterator filterIt = mPostFilters.begin();
00107                     EndPostFilterIt!=filterIt; ++filterIt )
00108                 if (!(*filterIt)->allow(temp)) return;
00109 
00110             const tPostConvJoinIterator EndPostStreamIt = mPostConvJoiners.end();
00111             for (   tPostConvJoinIterator streamIt = mPostConvJoiners.begin();
00112                     EndPostStreamIt!=streamIt; ++streamIt )
00113                 (*streamIt)->push(temp);
00114 
00115             mValues.push(temp);         
00116         }
00117 
00118 
00119         /* ************************************************************ */
00120         const tBool pop( tOutValue & oValue )
00121         {
00122             if (mValues.empty()) return false;
00123             oValue = mValues.front();
00124             mValues.pop();
00125             return true;
00126         }
00127 
00128 
00129         /* ************************************************************ */
00130         const tSize size() const
00131         {
00132             return mValues.size();
00133         }
00134 
00135 
00136         /* ************************************************************ */
00137         const tBool empty() const
00138         {
00139             return mValues.empty();
00140         }
00141 
00142 
00143         /* ************************************************************ */
00144         void attachInsertionFilter( const cAutoPtr<tPreFilter> & i_ioFilter )
00145         {
00146             mPreFilters.push_back( i_ioFilter );
00147         }
00148 
00149 
00150         /* ************************************************************ */
00151         void attachExtractionFilter( const cAutoPtr<tPostFilter> & i_ioFilter )
00152         {
00153             mPostFilters.push_back( i_ioFilter );
00154         }
00155 
00156 
00157         /* ************************************************************ */
00158         void attachPreConversionStream( const cAutoPtr<tPreConvJoiner> & i_ioStream )
00159         {
00160             mPreConvJoiners.push_back(i_ioStream);
00161         }
00162 
00163         /* ************************************************************ */
00164         void attachPostConversionStream( const cAutoPtr<tPostConvJoiner> & i_ioStream )
00165         {
00166             mPostConvJoiners.push_back(i_ioStream);
00167         }
00168 
00169         /* ************************************************************ */
00170         const tBool connected() const 
00171         {
00172             return mConnected;
00173         }
00174 
00175         /* ************************************************************ */
00176         void disconnect()
00177         {
00178             mConnected = false;
00179         }
00180 
00181         
00182     private:
00183         tValueContainer         mValues;
00184         tPreFilterContainer     mPreFilters;
00185         tPostFilterContainer    mPostFilters;
00186         tPreConvJoinContainer   mPreConvJoiners;
00187         tPostConvJoinContainer  mPostConvJoiners;
00188 
00189         cAutoPtr<tConverter>    mConverter;
00190     
00191         tBool                   mConnected;
00192 
00193     }; // class
00194 
00195 } // namespace n2l
00196 
00197 #endif
©2012 Aaron Cameron