$search
00001 00011 /***************************************************************************** 00012 ** Ifdefs 00013 *****************************************************************************/ 00014 00015 #ifndef ECL_STREAMS_OUTPUT_TEXT_STREAM_HPP_ 00016 #define ECL_STREAMS_OUTPUT_TEXT_STREAM_HPP_ 00017 00018 /***************************************************************************** 00019 ** Includes 00020 *****************************************************************************/ 00021 00022 #include <cstring> 00023 #include <string> 00024 #include <ecl/config/macros.hpp> 00025 #include <ecl/exceptions/standard_exception.hpp> 00026 #include <ecl/converters.hpp> 00027 #include <ecl/concepts/devices.hpp> 00028 #include "../manipulators/manipulator.hpp" 00029 00030 /***************************************************************************** 00031 ** Namespaces 00032 *****************************************************************************/ 00033 00034 namespace ecl { 00035 namespace interfaces { 00036 00037 /***************************************************************************** 00038 ** Interface [OutputTextStream] 00039 *****************************************************************************/ 00040 00053 template <typename Device, bool OutputDevice = true > 00054 class ECL_PUBLIC OutputTextStream {}; 00055 00078 template <typename Device> 00079 class ECL_PUBLIC OutputTextStream<Device,true> : public virtual BaseTextStream<Device> { 00080 public: 00092 OutputTextStream() : 00093 toCharString(30) // character buffer size 00094 { 00095 ecl_compile_time_concept_check(OutputCharDeviceConcept<Device>); 00096 }; 00097 00098 virtual ~OutputTextStream() {} 00099 00100 OutputTextStream<Device>& operator << ( const char &c ) ecl_assert_throw_decl(ecl::StandardException); 00101 OutputTextStream<Device>& operator << ( const char *s ) ecl_assert_throw_decl(ecl::StandardException); 00102 OutputTextStream<Device>& operator << ( const std::string &s ) ecl_assert_throw_decl(ecl::StandardException); 00103 OutputTextStream<Device>& operator << ( const short &i ) ecl_assert_throw_decl(ecl::StandardException); 00104 OutputTextStream<Device>& operator << ( const int &i ) ecl_assert_throw_decl(ecl::StandardException); 00105 OutputTextStream<Device>& operator << ( const long &i ) ecl_assert_throw_decl(ecl::StandardException); 00106 OutputTextStream<Device>& operator << ( const long long &i ) ecl_assert_throw_decl(ecl::StandardException); 00107 OutputTextStream<Device>& operator << ( const unsigned short &i ) ecl_assert_throw_decl(ecl::StandardException); 00108 OutputTextStream<Device>& operator << ( const unsigned int &i ) ecl_assert_throw_decl(ecl::StandardException); 00109 OutputTextStream<Device>& operator << ( const unsigned long &i ) ecl_assert_throw_decl(ecl::StandardException); 00110 OutputTextStream<Device>& operator << ( const unsigned long long &i ) ecl_assert_throw_decl(ecl::StandardException); 00111 OutputTextStream<Device>& operator << ( const bool b ) ecl_assert_throw_decl(ecl::StandardException); 00112 OutputTextStream<Device>& operator << ( const float &f ) ecl_assert_throw_decl(ecl::StandardException); 00113 OutputTextStream<Device>& operator << ( const double &d ) ecl_assert_throw_decl(ecl::StandardException); 00114 00115 /********************* 00116 * Friend Manipulators 00117 *********************/ 00118 template <typename Action> 00119 OutputTextStream<Device>& operator << ( ecl::Manipulator<Action> &manipulator ) ecl_assert_throw_decl(ecl::StandardException) 00120 { 00121 manipulator.insert(*this); 00122 return *this; 00123 } 00124 00131 // friend interfaces::OutputTextStream& operator << (interfaces::OutputTextStream& ostream, void (*manipulator)(interfaces::OutputTextStream&) ) 00132 // { 00133 // (*manipulator)(ostream); 00134 // return ostream; 00135 // } 00136 00137 /********************* 00138 ** Buffer functionality 00139 **********************/ 00140 void flush() ecl_assert_throw_decl(ecl::StandardException); 00141 00142 private: 00143 ecl::Converter<char*> toCharString; 00144 }; 00145 00146 /***************************************************************************** 00147 ** Implementation [OutputTextStream] 00148 *****************************************************************************/ 00149 00157 template <typename Device> 00158 OutputTextStream<Device>& OutputTextStream<Device,true>::operator<< ( const char& c ) ecl_assert_throw_decl(ecl::StandardException) { 00159 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00160 this->io_device.write(c); 00161 return *this; 00162 } 00171 template <typename Device> 00172 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const char *s ) ecl_assert_throw_decl(ecl::StandardException) { 00173 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00174 this->io_device.write(s,strlen(s)); 00175 return *this; 00176 } 00177 00186 template <typename Device> 00187 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const std::string &s ) ecl_assert_throw_decl(ecl::StandardException) { 00188 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00189 this->io_device.write(&s[0],s.size()); 00190 return *this; 00191 } 00199 template <typename Device> 00200 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const short &i ) ecl_assert_throw_decl(ecl::StandardException) 00201 { 00202 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00203 *this << toCharString(i); 00204 return *this; 00205 } 00213 template <typename Device> 00214 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const int &i ) ecl_assert_throw_decl(ecl::StandardException) 00215 { 00216 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00217 *this << toCharString(i); 00218 return *this; 00219 } 00220 00228 template <typename Device> 00229 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const long &i ) ecl_assert_throw_decl(ecl::StandardException) 00230 { 00231 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00232 *this << toCharString(i); 00233 return *this; 00234 } 00235 00243 template <typename Device> 00244 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const long long &i ) ecl_assert_throw_decl(ecl::StandardException) 00245 { 00246 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00247 *this << toCharString(i); 00248 return *this; 00249 } 00250 00258 template <typename Device> 00259 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned short &i ) ecl_assert_throw_decl(ecl::StandardException) 00260 { 00261 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00262 *this << toCharString(i); 00263 return *this; 00264 } 00265 00273 template <typename Device> 00274 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned int &i ) ecl_assert_throw_decl(ecl::StandardException) 00275 { 00276 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00277 *this << toCharString(i); 00278 return *this; 00279 } 00280 00288 template <typename Device> 00289 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned long &i ) ecl_assert_throw_decl(ecl::StandardException) 00290 { 00291 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00292 *this << toCharString(i); 00293 return *this; 00294 } 00302 template <typename Device> 00303 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned long long &i ) ecl_assert_throw_decl(ecl::StandardException) 00304 { 00305 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00306 *this << toCharString(i); 00307 return *this; 00308 } 00316 template <typename Device> 00317 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const bool b ) ecl_assert_throw_decl(ecl::StandardException) 00318 { 00319 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00320 if ( b ) { *this << "true"; } else { *this << "false"; }; 00321 return *this; 00322 } 00323 00330 template <typename Device> 00331 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const float &f ) ecl_assert_throw_decl(ecl::StandardException) 00332 { 00333 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00334 *this << toCharString(f); 00335 return *this; 00336 } 00337 00344 template <typename Device> 00345 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const double &d ) ecl_assert_throw_decl(ecl::StandardException) 00346 { 00347 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00348 *this << toCharString(d); 00349 return *this; 00350 } 00351 00359 template <typename Device> 00360 void OutputTextStream<Device,true>::flush() ecl_assert_throw_decl(ecl::StandardException) { 00361 ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); 00362 this->io_device.flush(); 00363 } 00364 00365 } // namespace interfaces 00366 } // namespace ecl 00367 00368 #endif /* ECL_STREAMS_OUTPUT_TEXT_STREAM_HPP_ */