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 <ecl/time_lite/types.hpp>
00020 #include <ecl/config/macros.hpp>
00021 #include <ecl/exceptions/standard_exception.hpp>
00022 #include "macros.hpp"
00023 
00024 /*****************************************************************************
00025 ** Namespaces
00026 *****************************************************************************/
00027 
00028 namespace ecl {
00029 
00030 /*****************************************************************************
00031 ** Implementation
00032 *****************************************************************************/
00039 class ecl_time_PUBLIC TimeStampBase {
00040 public:
00041     /*********************
00042     ** Constructors
00043     **********************/
00044         explicit TimeStampBase() {}; 
00055     explicit TimeStampBase (const double& decimal_time_value) ecl_assert_throw_decl(StandardException);
00065     TimeStampBase (const time_t &seconds, const long &nanoseconds) ecl_assert_throw_decl(StandardException);
00066 
00067     virtual ~TimeStampBase() {}
00068 
00069     /******************************************
00070         ** Stamps
00071         *******************************************/
00082         const TimeStampBase& stamp (const double& decimal_time_value) ecl_assert_throw_decl(StandardException);
00093         const TimeStampBase& stamp (const time_t &seconds, const long &nanoseconds) ecl_assert_throw_decl(StandardException);
00094 
00095     /******************************************
00096     ** Accessors
00097     *******************************************/
00104         long sec() const { return time.tv_sec; }
00111         long msec() const { return time.tv_nsec/1000000L; }
00118         long usec() const { return time.tv_nsec/1000; }
00125         long nsec() const { return time.tv_nsec; }
00126 
00133         operator double() const { return ( time.tv_sec + time.tv_nsec*0.000000001); }
00134 
00135         /******************************************
00136         ** Comparison Operators
00137         *******************************************/
00143         bool operator==(const TimeStampBase& time_stamp);
00149         bool operator!=(const TimeStampBase& time_stamp);
00155         bool operator<=(const TimeStampBase& time_stamp);
00161         bool operator>=(const TimeStampBase& time_stamp);
00167         bool operator<(const TimeStampBase& time_stamp);
00173         bool operator>(const TimeStampBase& time_stamp);
00174 
00175         /******************************************
00176         ** Mathematical Operators
00177         *******************************************/
00183         TimeStampBase operator+(const TimeStampBase& time_stamp );
00188         void operator+=(const TimeStampBase& time_stamp);
00198         TimeStampBase operator-(const TimeStampBase& time_stamp ) ecl_assert_throw_decl(StandardException);
00207         void operator-=(const TimeStampBase& time_stamp) ecl_assert_throw_decl(StandardException);
00208 
00209     /******************************************
00210     ** Insertion Operator
00211     *******************************************/
00212     template <typename OutputStream>
00213     friend OutputStream& operator << ( OutputStream &ostream , const TimeStampBase& time_stamp );
00214 
00215 protected:
00216     TimeStructure time;
00217 };
00218 
00219 
00220 /*****************************************************************************
00221 ** Implementation [Insertion Operator]
00222 *****************************************************************************/
00223 
00224 template <typename OutputStream>
00225 OutputStream& operator <<( OutputStream &ostream , const TimeStampBase& time_stamp )
00226 {
00227     ostream << time_stamp.time.tv_sec << ".";
00228     if ( time_stamp.time.tv_nsec < 10 ) {
00229         ostream << "00000000";
00230     } else if ( time_stamp.time.tv_nsec < 100 ) {
00231         ostream << "0000000";
00232     } else if ( time_stamp.time.tv_nsec < 1000 ) {
00233         ostream << "000000";
00234     } else if ( time_stamp.time.tv_nsec < 10000 ) {
00235         ostream << "00000";
00236     } else if ( time_stamp.time.tv_nsec < 100000 ) {
00237         ostream << "0000";
00238     } else if ( time_stamp.time.tv_nsec < 1000000 ) {
00239         ostream << "000";
00240     } else if ( time_stamp.time.tv_nsec < 10000000 ) {
00241         ostream << "00";
00242     } else if ( time_stamp.time.tv_nsec < 100000000 ) {
00243         ostream << "0";
00244     }
00245     ostream << time_stamp.time.tv_nsec;
00246     return ostream;
00247 }
00248 
00249 } // namespace ecl
00250 
00251 #endif /* ECL_TIME_TIMESTAMP_BASE_HPP_ */
00252 
00253 
00254 


ecl_time
Author(s): Daniel Stonier
autogenerated on Sun Oct 5 2014 23:35:32