timestamp_base.hpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Ifdefs
00010 *****************************************************************************/
00011 
00012 #ifndef ECL_TIME_TIMESTAMP_BASE_HPP_
00013 #define ECL_TIME_TIMESTAMP_BASE_HPP_
00014 
00015 /*****************************************************************************
00016 ** Includes
00017 *****************************************************************************/
00018 
00019 #include <cstdlib>
00020 #include <ecl/time_lite/types.hpp>
00021 #include <ecl/config/macros.hpp>
00022 #include <ecl/exceptions/standard_exception.hpp>
00023 #include "macros.hpp"
00024 
00025 /*****************************************************************************
00026 ** Namespaces
00027 *****************************************************************************/
00028 
00029 namespace ecl {
00030 
00031 /*****************************************************************************
00032 ** Implementation
00033 *****************************************************************************/
00040 class ecl_time_PUBLIC TimeStampBase {
00041 public:
00042     /*********************
00043     ** Constructors
00044     **********************/
00045         explicit TimeStampBase() {}; 
00056     explicit TimeStampBase (const double& decimal_time_value) ecl_assert_throw_decl(StandardException);
00066     TimeStampBase (const time_t &seconds, const long &nanoseconds) ecl_assert_throw_decl(StandardException);
00067 
00068     virtual ~TimeStampBase() {}
00069 
00070     /******************************************
00071         ** Stamps
00072         *******************************************/
00083         const TimeStampBase& stamp (const double& decimal_time_value) ecl_assert_throw_decl(StandardException);
00094         const TimeStampBase& stamp (const time_t &seconds, const long &nanoseconds) ecl_assert_throw_decl(StandardException);
00095 
00096     /******************************************
00097     ** Accessors
00098     *******************************************/
00105         long sec() const { return time.tv_sec; }
00112         long msec() const { return time.tv_nsec/1000000L; }
00119         long usec() const { return time.tv_nsec/1000; }
00126         long nsec() const { return time.tv_nsec; }
00127 
00134         operator double() const { return ( time.tv_sec + time.tv_nsec*0.000000001); }
00135 
00136         /******************************************
00137         ** Comparison Operators
00138         *******************************************/
00144         bool operator==(const TimeStampBase& time_stamp);
00150         bool operator!=(const TimeStampBase& time_stamp);
00156         bool operator<=(const TimeStampBase& time_stamp);
00162         bool operator>=(const TimeStampBase& time_stamp);
00168         bool operator<(const TimeStampBase& time_stamp);
00174         bool operator>(const TimeStampBase& time_stamp);
00175 
00176         /******************************************
00177         ** Mathematical Operators
00178         *******************************************/
00184         TimeStampBase operator+(const TimeStampBase& time_stamp );
00189         void operator+=(const TimeStampBase& time_stamp);
00199         TimeStampBase operator-(const TimeStampBase& time_stamp ) ecl_assert_throw_decl(StandardException);
00208         void operator-=(const TimeStampBase& time_stamp) ecl_assert_throw_decl(StandardException);
00209 
00210     /******************************************
00211     ** Insertion Operator
00212     *******************************************/
00213     template <typename OutputStream>
00214     friend OutputStream& operator << ( OutputStream &ostream , const TimeStampBase& time_stamp );
00215 
00216 protected:
00217     TimeStructure time;
00218 };
00219 
00220 
00221 /*****************************************************************************
00222 ** Implementation [Insertion Operator]
00223 *****************************************************************************/
00224 
00225 template <typename OutputStream>
00226 OutputStream& operator <<( OutputStream &ostream , const TimeStampBase& time_stamp )
00227 {
00228     if ( ( time_stamp.time.tv_sec == 0 ) && (time_stamp.time.tv_nsec < 0 ) ) {
00229       ostream << "-";
00230     }
00231     ostream << time_stamp.time.tv_sec << ".";
00232     long nanoseconds = std::abs(time_stamp.time.tv_nsec);
00233     if ( nanoseconds < 10 ) {
00234         ostream << "00000000";
00235     } else if ( nanoseconds < 100 ) {
00236         ostream << "0000000";
00237     } else if ( nanoseconds < 1000 ) {
00238         ostream << "000000";
00239     } else if ( nanoseconds < 10000 ) {
00240         ostream << "00000";
00241     } else if ( nanoseconds < 100000 ) {
00242         ostream << "0000";
00243     } else if ( nanoseconds < 1000000 ) {
00244         ostream << "000";
00245     } else if ( nanoseconds < 10000000 ) {
00246         ostream << "00";
00247     } else if ( nanoseconds < 100000000 ) {
00248         ostream << "0";
00249     }
00250     ostream << nanoseconds;
00251     return ostream;
00252 }
00253 
00254 } // namespace ecl
00255 
00256 #endif /* ECL_TIME_TIMESTAMP_BASE_HPP_ */
00257 
00258 
00259 


ecl_time
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:17:29