.. _program_listing_file__tmp_ws_src_ecl_core_ecl_streams_include_ecl_streams_text_streams_output_text_stream.hpp: Program Listing for File output_text_stream.hpp =============================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/ecl_core/ecl_streams/include/ecl/streams/text_streams/output_text_stream.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_STREAMS_OUTPUT_TEXT_STREAM_HPP_ #define ECL_STREAMS_OUTPUT_TEXT_STREAM_HPP_ /***************************************************************************** ** Includes *****************************************************************************/ #include #include #include #include #include #include #include "../manipulators/manipulator.hpp" #include "../macros.hpp" /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { namespace interfaces { /***************************************************************************** ** Interface [OutputTextStream] *****************************************************************************/ template class ECL_PUBLIC OutputTextStream {}; template class ECL_PUBLIC OutputTextStream : public virtual BaseTextStream { public: OutputTextStream() : toCharString(30) // character buffer size { ecl_compile_time_concept_check(OutputCharDeviceConcept); }; virtual ~OutputTextStream() {} OutputTextStream& operator << ( const char &c ); OutputTextStream& operator << ( const char *s ); OutputTextStream& operator << ( const std::string &s ); OutputTextStream& operator << ( const short &i ); OutputTextStream& operator << ( const int &i ); OutputTextStream& operator << ( const long &i ); OutputTextStream& operator << ( const long long &i ); OutputTextStream& operator << ( const unsigned short &i ); OutputTextStream& operator << ( const unsigned int &i ); OutputTextStream& operator << ( const unsigned long &i ); OutputTextStream& operator << ( const unsigned long long &i ); OutputTextStream& operator << ( const bool b ); OutputTextStream& operator << ( const float &f ); OutputTextStream& operator << ( const double &d ); /********************* * Friend Manipulators *********************/ template OutputTextStream& operator << ( ecl::Manipulator &manipulator ) { manipulator.insert(*this); return *this; } // friend interfaces::OutputTextStream& operator << (interfaces::OutputTextStream& ostream, void (*manipulator)(interfaces::OutputTextStream&) ) // { // (*manipulator)(ostream); // return ostream; // } /********************* ** Buffer functionality **********************/ void flush(); private: ecl::Converter toCharString; }; /***************************************************************************** ** Implementation [OutputTextStream] *****************************************************************************/ template OutputTextStream& OutputTextStream::operator<< ( const char& c ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); this->io_device.write(c); return *this; } template OutputTextStream& OutputTextStream::operator << ( const char *s ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); this->io_device.write(s,strlen(s)); return *this; } template OutputTextStream& OutputTextStream::operator << ( const std::string &s ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); this->io_device.write(&s[0],s.size()); return *this; } template OutputTextStream& OutputTextStream::operator << ( const short &i ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); *this << toCharString(i); return *this; } template OutputTextStream& OutputTextStream::operator << ( const int &i ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); *this << toCharString(i); return *this; } template OutputTextStream& OutputTextStream::operator << ( const long &i ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); *this << toCharString(i); return *this; } template OutputTextStream& OutputTextStream::operator << ( const long long &i ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); *this << toCharString(i); return *this; } template OutputTextStream& OutputTextStream::operator << ( const unsigned short &i ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); *this << toCharString(i); return *this; } template OutputTextStream& OutputTextStream::operator << ( const unsigned int &i ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); *this << toCharString(i); return *this; } template OutputTextStream& OutputTextStream::operator << ( const unsigned long &i ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); *this << toCharString(i); return *this; } template OutputTextStream& OutputTextStream::operator << ( const unsigned long long &i ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); *this << toCharString(i); return *this; } template OutputTextStream& OutputTextStream::operator << ( const bool b ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); if ( b ) { *this << "true"; } else { *this << "false"; }; return *this; } template OutputTextStream& OutputTextStream::operator << ( const float &f ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); *this << toCharString(f); return *this; } template OutputTextStream& OutputTextStream::operator << ( const double &d ) { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); *this << toCharString(d); return *this; } template void OutputTextStream::flush() { ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open.")); this->io_device.flush(); } } // namespace interfaces } // namespace ecl #endif /* ECL_STREAMS_OUTPUT_TEXT_STREAM_HPP_ */