UnixTime.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #ifndef GNSSTK_UNIXTIME_HPP
40 #define GNSSTK_UNIXTIME_HPP
41 
42 #include "TimeTag.hpp"
43 
44 #ifdef _MSC_VER
45 #ifndef _WINSOCKAPI_
46 #ifndef timeval
47 // timeval is defined in winsock.h, which we don't want to include
48 // because it breaks lots of this code
49 struct timeval {
50  long tv_sec; /* seconds */
51  long tv_usec; /* and microseconds */
52 };
53 #endif // #ifndef timeval
54 #endif // #ifndef _WINSOCKAPI_
55 #else
56 #include <sys/time.h> // for struct timeval
57 #endif
58 
59 namespace gnsstk
60 {
62 
63 
67  class UnixTime : public TimeTag
68  {
69  public:
75 
80  UnixTime( int sec = 0,
81  int usec = 0,
83  { tv.tv_sec = sec; tv.tv_usec = usec; timeSystem = ts; }
84 
88  UnixTime( struct timeval t,
90  {
91  tv.tv_sec = t.tv_sec; tv.tv_usec = t.tv_usec; timeSystem = ts;
92  }
93 
98  UnixTime( const UnixTime& right )
99  : tv( right.tv )
100  { timeSystem = right.timeSystem; }
101 
109  UnixTime( const TimeTag& right )
110  {
112  }
113 
121  UnixTime( const CommonTime& right )
122  {
123  convertFromCommonTime( right );
124  }
125 
131  UnixTime& operator=( const UnixTime& right );
132 
134  virtual ~UnixTime()
135  {}
137 
138  // The following functions are required by TimeTag.
139  virtual CommonTime convertToCommonTime() const;
140 
141  virtual void convertFromCommonTime( const CommonTime& ct );
142 
145  virtual std::string printf( const std::string& fmt ) const;
146 
149  virtual std::string printError( const std::string& fmt ) const;
150 
157  virtual bool setFromInfo( const IdToValue& info );
158 
161  virtual std::string getPrintChars() const
162  {
163  return "UuP";
164  }
165 
167  virtual std::string getDefaultFormat() const
168  {
169  return "%U %u %P";
170  }
171 
172  virtual bool isValid() const;
173 
174  virtual void reset();
175 
184  virtual bool operator==( const UnixTime& right ) const;
185  virtual bool operator!=( const UnixTime& right ) const;
186  virtual bool operator<( const UnixTime& right ) const;
187  virtual bool operator>( const UnixTime& right ) const;
188  virtual bool operator<=( const UnixTime& right ) const;
189  virtual bool operator>=( const UnixTime& right ) const;
191 
192  struct timeval tv;
193  };
194 
196 
197 } // namespace
198 
199 #endif // GNSSTK_UNIXTIME_HPP
gnsstk::UnixTime::tv
struct timeval tv
Definition: UnixTime.hpp:192
gnsstk::TimeTag::IdToValue
std::map< char, std::string > IdToValue
Definition: TimeTag.hpp:103
gnsstk::UnixTime::printf
virtual std::string printf(const std::string &fmt) const
Definition: UnixTime.cpp:105
gnsstk::UnixTime::getPrintChars
virtual std::string getPrintChars() const
Definition: UnixTime.hpp:161
gnsstk::UnixTime::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: UnixTime.cpp:54
gnsstk::UnixTime::operator<=
virtual bool operator<=(const UnixTime &right) const
Definition: UnixTime.cpp:242
gnsstk::UnixTime::UnixTime
UnixTime(const TimeTag &right)
Definition: UnixTime.hpp:109
gnsstk::TimeSystem::Unknown
@ Unknown
unknown time frame; for legacy code compatibility
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::UnixTime::operator!=
virtual bool operator!=(const UnixTime &right) const
Definition: UnixTime.cpp:209
gnsstk::TimeTag::timeSystem
TimeSystem timeSystem
time system (representation) of the data
Definition: TimeTag.hpp:204
gnsstk::UnixTime::UnixTime
UnixTime(const UnixTime &right)
Definition: UnixTime.hpp:98
gnsstk::UnixTime::UnixTime
UnixTime(const CommonTime &right)
Definition: UnixTime.hpp:121
gnsstk::TimeTag
Definition: TimeTag.hpp:58
gnsstk::UnixTime::setFromInfo
virtual bool setFromInfo(const IdToValue &info)
Definition: UnixTime.cpp:147
gnsstk::UnixTime::UnixTime
UnixTime(struct timeval t, TimeSystem ts=TimeSystem::Unknown)
Definition: UnixTime.hpp:88
gnsstk::UnixTime::operator>=
virtual bool operator>=(const UnixTime &right) const
Definition: UnixTime.cpp:248
gnsstk::UnixTime::~UnixTime
virtual ~UnixTime()
Virtual Destructor.
Definition: UnixTime.hpp:134
gnsstk::UnixTime::operator==
virtual bool operator==(const UnixTime &right) const
Definition: UnixTime.cpp:193
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::UnixTime::operator=
UnixTime & operator=(const UnixTime &right)
Definition: UnixTime.cpp:46
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
gnsstk::TimeTag::convertToCommonTime
virtual CommonTime convertToCommonTime() const =0
TimeTag.hpp
gnsstk::UnixTime::operator>
virtual bool operator>(const UnixTime &right) const
Definition: UnixTime.cpp:237
gnsstk::UnixTime
Definition: UnixTime.hpp:67
gnsstk::UnixTime::reset
virtual void reset()
Reset this object to the default state.
Definition: UnixTime.cpp:187
gnsstk::UnixTime::printError
virtual std::string printError(const std::string &fmt) const
Definition: UnixTime.cpp:126
gnsstk::UnixTime::isValid
virtual bool isValid() const
Returns true if this object's members are valid, false otherwise.
Definition: UnixTime.cpp:176
gnsstk::UnixTime::UnixTime
UnixTime(int sec=0, int usec=0, TimeSystem ts=TimeSystem::Unknown)
Definition: UnixTime.hpp:80
gnsstk::UnixTime::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: UnixTime.cpp:71
gnsstk::UnixTime::operator<
virtual bool operator<(const UnixTime &right) const
Definition: UnixTime.cpp:214
gnsstk::UnixTime::getDefaultFormat
virtual std::string getDefaultFormat() const
Return a string containing the default format to use in printing.
Definition: UnixTime.hpp:167


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:42