output_text_stream.hpp
Go to the documentation of this file.
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 #include "../macros.hpp"
00030 
00031 /*****************************************************************************
00032 ** Namespaces
00033 *****************************************************************************/
00034 
00035 namespace ecl {
00036 namespace interfaces {
00037 
00038 /*****************************************************************************
00039 ** Interface [OutputTextStream]
00040 *****************************************************************************/
00041 
00054 template <typename Device, bool OutputDevice = true >
00055 class ECL_PUBLIC OutputTextStream {};
00056 
00079 template <typename Device>
00080 class ECL_PUBLIC OutputTextStream<Device,true> : public virtual BaseTextStream<Device> {
00081     public:
00093         OutputTextStream() :
00094                 toCharString(30) // character buffer size
00095                 {
00096             ecl_compile_time_concept_check(OutputCharDeviceConcept<Device>);
00097                 };
00098 
00099         virtual ~OutputTextStream() {}
00100 
00101         OutputTextStream<Device>& operator << ( const char &c ) ecl_assert_throw_decl(ecl::StandardException);
00102         OutputTextStream<Device>& operator << ( const char *s ) ecl_assert_throw_decl(ecl::StandardException);
00103         OutputTextStream<Device>& operator << ( const std::string &s ) ecl_assert_throw_decl(ecl::StandardException);
00104         OutputTextStream<Device>& operator << ( const short &i ) ecl_assert_throw_decl(ecl::StandardException);
00105         OutputTextStream<Device>& operator << ( const int &i ) ecl_assert_throw_decl(ecl::StandardException);
00106         OutputTextStream<Device>& operator << ( const long &i ) ecl_assert_throw_decl(ecl::StandardException);
00107         OutputTextStream<Device>& operator << ( const long long &i ) ecl_assert_throw_decl(ecl::StandardException);
00108         OutputTextStream<Device>& operator << ( const unsigned short &i ) ecl_assert_throw_decl(ecl::StandardException);
00109         OutputTextStream<Device>& operator << ( const unsigned int &i ) ecl_assert_throw_decl(ecl::StandardException);
00110         OutputTextStream<Device>& operator << ( const unsigned long &i ) ecl_assert_throw_decl(ecl::StandardException);
00111                 OutputTextStream<Device>& operator << ( const unsigned long long &i ) ecl_assert_throw_decl(ecl::StandardException);
00112         OutputTextStream<Device>& operator << ( const bool b ) ecl_assert_throw_decl(ecl::StandardException);
00113         OutputTextStream<Device>& operator << ( const float &f ) ecl_assert_throw_decl(ecl::StandardException);
00114         OutputTextStream<Device>& operator << ( const double &d ) ecl_assert_throw_decl(ecl::StandardException);
00115 
00116         /*********************
00117          * Friend Manipulators
00118          *********************/
00119         template <typename Action>
00120         OutputTextStream<Device>& operator << ( ecl::Manipulator<Action> &manipulator ) ecl_assert_throw_decl(ecl::StandardException)
00121         {
00122                 manipulator.insert(*this);
00123                 return *this;
00124         }
00125 
00132 //        friend interfaces::OutputTextStream& operator << (interfaces::OutputTextStream& ostream, void (*manipulator)(interfaces::OutputTextStream&) )
00133 //        {
00134 //            (*manipulator)(ostream);
00135 //            return ostream;
00136 //        }
00137 
00138         /*********************
00139           ** Buffer functionality
00140         **********************/
00141          void flush() ecl_assert_throw_decl(ecl::StandardException);
00142 
00143     private:
00144         ecl::Converter<char*> toCharString;
00145 };
00146 
00147 /*****************************************************************************
00148 ** Implementation [OutputTextStream]
00149 *****************************************************************************/
00150 
00158 template <typename Device>
00159 OutputTextStream<Device>& OutputTextStream<Device,true>::operator<< ( const char& c ) ecl_assert_throw_decl(ecl::StandardException) {
00160         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00161         this->io_device.write(c);
00162     return *this;
00163 }
00172 template <typename Device>
00173 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const char *s ) ecl_assert_throw_decl(ecl::StandardException) {
00174         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00175     this->io_device.write(s,strlen(s));
00176     return *this;
00177 }
00178 
00187 template <typename Device>
00188 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const std::string &s ) ecl_assert_throw_decl(ecl::StandardException) {
00189         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00190     this->io_device.write(&s[0],s.size());
00191     return *this;
00192 }
00200 template <typename Device>
00201 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const short &i ) ecl_assert_throw_decl(ecl::StandardException)
00202 {
00203         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00204     *this << toCharString(i);
00205     return *this;
00206 }
00214 template <typename Device>
00215 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const int &i ) ecl_assert_throw_decl(ecl::StandardException)
00216 {
00217         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00218     *this << toCharString(i);
00219     return *this;
00220 }
00221 
00229 template <typename Device>
00230 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const long &i ) ecl_assert_throw_decl(ecl::StandardException)
00231 {
00232         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00233     *this << toCharString(i);
00234     return *this;
00235 }
00236 
00244 template <typename Device>
00245 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const long long &i ) ecl_assert_throw_decl(ecl::StandardException)
00246 {
00247         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00248     *this << toCharString(i);
00249     return *this;
00250 }
00251 
00259 template <typename Device>
00260 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned short &i ) ecl_assert_throw_decl(ecl::StandardException)
00261 {
00262         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00263     *this << toCharString(i);
00264     return *this;
00265 }
00266 
00274 template <typename Device>
00275 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned int &i ) ecl_assert_throw_decl(ecl::StandardException)
00276 {
00277         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00278     *this << toCharString(i);
00279     return *this;
00280 }
00281 
00289 template <typename Device>
00290 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned long &i ) ecl_assert_throw_decl(ecl::StandardException)
00291 {
00292         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00293     *this << toCharString(i);
00294     return *this;
00295 }
00303 template <typename Device>
00304 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned long long &i ) ecl_assert_throw_decl(ecl::StandardException)
00305 {
00306         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00307     *this << toCharString(i);
00308     return *this;
00309 }
00317 template <typename Device>
00318 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const bool b ) ecl_assert_throw_decl(ecl::StandardException)
00319 {
00320         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00321     if ( b ) { *this << "true"; } else { *this << "false"; };
00322     return *this;
00323 }
00324 
00331 template <typename Device>
00332 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const float &f ) ecl_assert_throw_decl(ecl::StandardException)
00333 {
00334         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00335     *this << toCharString(f);
00336     return *this;
00337 }
00338 
00345 template <typename Device>
00346 OutputTextStream<Device>&  OutputTextStream<Device,true>::operator << ( const double &d ) ecl_assert_throw_decl(ecl::StandardException)
00347 {
00348         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00349     *this << toCharString(d);
00350     return *this;
00351 }
00352 
00360 template <typename Device>
00361 void OutputTextStream<Device,true>::flush() ecl_assert_throw_decl(ecl::StandardException) {
00362         ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
00363         this->io_device.flush();
00364 }
00365 
00366 } // namespace interfaces
00367 } // namespace ecl
00368 
00369 #endif /* ECL_STREAMS_OUTPUT_TEXT_STREAM_HPP_ */


ecl_streams
Author(s): Daniel Stonier
autogenerated on Wed Aug 26 2015 11:27:40