.. _program_listing_file__tmp_ws_src_ecl_core_ecl_time_include_ecl_time_timestamp_base.hpp: Program Listing for File timestamp_base.hpp =========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/ecl_core/ecl_time/include/ecl/time/timestamp_base.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_TIME_TIMESTAMP_BASE_HPP_ #define ECL_TIME_TIMESTAMP_BASE_HPP_ /***************************************************************************** ** Includes *****************************************************************************/ #include #include #include #include #include "macros.hpp" /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { /***************************************************************************** ** Implementation *****************************************************************************/ class ecl_time_PUBLIC TimeStampBase { public: /********************* ** Constructors **********************/ explicit TimeStampBase() {}; explicit TimeStampBase (const double& decimal_time_value); TimeStampBase (const time_t &seconds, const long &nanoseconds); virtual ~TimeStampBase() {} /****************************************** ** Stamps *******************************************/ const TimeStampBase& stamp (const double& decimal_time_value); const TimeStampBase& stamp (const time_t &seconds, const long &nanoseconds); /****************************************** ** Accessors *******************************************/ long sec() const { return time.tv_sec; } long msec() const { return time.tv_nsec/1000000L; } long usec() const { return time.tv_nsec/1000; } long nsec() const { return time.tv_nsec; } operator double() const { return ( time.tv_sec + time.tv_nsec*0.000000001); } /****************************************** ** Comparison Operators *******************************************/ bool operator==(const TimeStampBase& time_stamp); bool operator!=(const TimeStampBase& time_stamp); bool operator<=(const TimeStampBase& time_stamp); bool operator>=(const TimeStampBase& time_stamp); bool operator<(const TimeStampBase& time_stamp); bool operator>(const TimeStampBase& time_stamp); /****************************************** ** Mathematical Operators *******************************************/ TimeStampBase operator+(const TimeStampBase& time_stamp ); void operator+=(const TimeStampBase& time_stamp); TimeStampBase operator-(const TimeStampBase& time_stamp ); void operator-=(const TimeStampBase& time_stamp); /****************************************** ** Insertion Operator *******************************************/ template friend OutputStream& operator << ( OutputStream &ostream , const TimeStampBase& time_stamp ); protected: TimeStructure time; }; /***************************************************************************** ** Implementation [Insertion Operator] *****************************************************************************/ template OutputStream& operator <<( OutputStream &ostream , const TimeStampBase& time_stamp ) { if ( ( time_stamp.time.tv_sec == 0 ) && (time_stamp.time.tv_nsec < 0 ) ) { ostream << "-"; } ostream << time_stamp.time.tv_sec << "."; long nanoseconds = std::abs(time_stamp.time.tv_nsec); if ( nanoseconds < 10 ) { ostream << "00000000"; } else if ( nanoseconds < 100 ) { ostream << "0000000"; } else if ( nanoseconds < 1000 ) { ostream << "000000"; } else if ( nanoseconds < 10000 ) { ostream << "00000"; } else if ( nanoseconds < 100000 ) { ostream << "0000"; } else if ( nanoseconds < 1000000 ) { ostream << "000"; } else if ( nanoseconds < 10000000 ) { ostream << "00"; } else if ( nanoseconds < 100000000 ) { ostream << "0"; } ostream << nanoseconds; return ostream; } } // namespace ecl #endif /* ECL_TIME_TIMESTAMP_BASE_HPP_ */