![[]](/images/special/trans.gif)
LibN2L-4 Library Code ReferenceClassesCompounds Files Members Method Index Full Reference cUniStream.hGo 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_cUniStream_H 00026 #define _n2l4_cUniStream_H 00027 00028 #include <queue> 00029 00030 #include "n2l/n2l.h" 00031 00032 #include "cAssignmentConverter.h" 00033 #include "cInsertionStreamInterface.h" 00034 #include "cExtractionStreamInterface.h" 00035 00036 //#ifdef _REENTRANT 00037 //#include "cTSUniStreamImp.h" 00038 //#else 00039 #include "cUniStreamImp.h" 00040 //#endif 00041 00042 namespace n2l 00043 { 00044 00052 template < class TIValue, 00053 class TOValue = TIValue, 00054 class TVContainer = std::queue<TOValue> > 00055 class cUniStream 00056 { 00057 private: 00058 typedef cUniStreamImp<TIValue,TOValue,TVContainer> tImp; 00059 00060 public: 00061 typedef cUniStream<TIValue,TOValue,TVContainer> tThis; 00062 00063 typedef typename tImp::tConverter tConverter; 00064 00065 typedef typename tImp::tInValue tInValue; 00066 typedef typename tImp::tOutValue tOutValue; 00067 typedef typename tImp::tValueContainer tValueContainer; 00068 typedef typename tImp::tSize tSize; 00069 00070 typedef typename tImp::tPreFilter tPreFilter; 00071 typedef typename tImp::tPostFilter tPostFilter; 00072 00073 typedef typename tImp::tPreConvJoiner tPreConvJoiner; 00074 typedef typename tImp::tPostConvJoiner tPostConvJoiner; 00075 00076 00080 class cInsertionStream : public cInsertionStreamInterface<tInValue> 00081 { 00082 public: 00083 cInsertionStream( const cAutoPtr<tImp> io_imp ) : 00084 mImp(io_imp) 00085 { 00086 if (!mImp) 00087 throw cBadDataUseException( "cInsertionStream::cInsertionStream", 00088 "Invalid cast, or null stream" ); 00089 } 00090 00091 virtual ~cInsertionStream() {} 00092 00093 virtual void push( const cUniStream::tInValue & i_value ) 00094 { 00095 mImp->push(i_value); 00096 } 00097 private: 00098 cAutoPtr<tImp> mImp; 00099 }; 00100 00104 class cExtractionStream : public cExtractionStreamInterface<tOutValue> 00105 { 00106 public: 00107 cExtractionStream( const cAutoPtr<tImp> io_imp ) : 00108 mImp(io_imp) 00109 { 00110 if (!mImp) 00111 throw cBadDataUseException( "cExtractionStream::cExtractionStream", 00112 "Invalid cast, or null stream" ); 00113 } 00114 00115 virtual ~cExtractionStream() {} 00116 00117 virtual const bool pop( cUniStream::tOutValue & o_value ) 00118 { 00119 return mImp->pop(o_value); 00120 } 00121 private: 00122 cAutoPtr<tImp> mImp; 00123 }; 00124 00125 00126 typedef cInsertionStream tInsertionStream; 00127 typedef cExtractionStream tExtractionStream; 00128 00129 00130 /* ************************************************************ */ 00131 cUniStream( const cAutoPtr<tConverter> & i_ioConverter ) : 00132 mImp( new tImp(i_ioConverter) ) 00133 {} 00134 00135 00136 /* ************************************************************ */ 00137 cUniStream() : 00138 mImp( new tImp(new cAssignmentConverter<tInValue,tOutValue>) ) 00139 {} 00140 00141 00142 /* ************************************************************ */ 00143 cUniStream( cUniStream & io_otherStream ) : 00144 mImp( io_otherStream.mImp ) {} 00145 00146 00147 /* ************************************************************ */ 00148 void push( const tInValue & i_value ) 00149 { 00150 mImp->push(i_value); 00151 } 00152 00153 00154 /* ************************************************************ */ 00155 tThis & operator <<( const tInValue & i_value ) 00156 { 00157 mImp->push(i_value); 00158 return *this; 00159 } 00160 00161 00162 /* ************************************************************ */ 00163 const bool pop( tOutValue & o_value ) 00164 { 00165 return mImp->pop(o_value); 00166 } 00167 00168 00169 /* ************************************************************ */ 00170 tThis & operator >>( tOutValue & o_value ) 00171 { 00172 mImp->pop(o_value); 00173 return *this; 00174 } 00175 00176 00177 /* ************************************************************ */ 00178 const tSize size() const 00179 { 00180 return mImp->size(); 00181 } 00182 00183 00184 /* ************************************************************ */ 00185 const tBool empty() const 00186 { 00187 return mImp->empty(); 00188 } 00189 00190 00191 /* ************************************************************ */ 00192 void attachInsertionFilter( const cAutoPtr<tPreFilter> & i_ioFilter ) 00193 { 00194 mImp->attachInsertionFilter(i_ioFilter); 00195 } 00196 00197 00198 /* ************************************************************ */ 00199 void attachExtractionFilter( const cAutoPtr<tPostFilter> & i_ioFilter ) 00200 { 00201 mImp->attachExtractionFilter(i_ioFilter); 00202 } 00203 00204 00205 /* ************************************************************ */ 00206 cAutoPtr<tInsertionStream> getInsertionStream() 00207 { 00208 return new tInsertionStream(mImp); 00209 } 00210 00211 /* ************************************************************ */ 00212 cAutoPtr<tExtractionStream> getExtractionStream() 00213 { 00214 return new tExtractionStream(mImp); 00215 } 00216 00217 /* ************************************************************ */ 00218 void attachPreConversionStream( const cAutoPtr<tPreConvJoiner> & i_ioStream ) 00219 { 00220 mImp->attachPreConversionStream(i_ioStream); 00221 } 00222 00223 /* ************************************************************ */ 00224 void attachPostConversionStream( const cAutoPtr<tPostConvJoiner> & i_ioStream ) 00225 { 00226 mImp->attachPostConversionStream(i_ioStream); 00227 } 00228 00229 /* ************************************************************ */ 00230 const tBool isConnected() const 00231 { 00232 return mImp->connected(); 00233 } 00234 00235 /* ************************************************************ */ 00236 void disconnect() 00237 { 00238 mImp->disconnect(); 00239 } 00240 00241 private: 00242 cAutoPtr<tImp> mImp; 00243 00244 }; // class 00245 00246 } // namespace n2l 00247 00248 #endif |