Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Jeep/JTime.hh
Go to the documentation of this file.
1 #ifndef __JEEP__JTIME__
2 #define __JEEP__JTIME__
3 
4 #include <string>
5 #include <istream>
6 #include <ostream>
7 #include <sstream>
8 #include <cctype>
9 #include <limits>
10 
11 #include "JLang/JComparable.hh"
13 
14 #include "Jeep/JPrint.hh"
15 
16 
17 /**
18  * \author mdejong
19  */
20 namespace JEEP {}
21 namespace JPP { using namespace JEEP; }
22 
23 namespace JEEP {
24 
25  using JLANG::JComparable;
26 
27 
28  /**
29  * Auxiliary class for simple time.
30  *
31  * The corresponding ASCII format is <tt>hh<separator>mm<separator>ss</tt>,
32  * where
33  * <tt>hh</tt> corresponds to the hour,
34  * <tt>mm</tt> to the minutes and
35  * <tt>ss</tt> to the seconds.\n
36  * The separator is defined by the template parameter.
37  */
38  template<char JSeparator_t>
39  struct JTime :
40  public JComparable< JTime<JSeparator_t> >
41  {
42  /**
43  * Separation character.
44  */
45  static const char SEPARATOR = JSeparator_t;
46 
47 
48  /**
49  * Default constructor.
50  */
51  JTime() :
52  hour (0),
53  minute(0),
54  second(0)
55  {}
56 
57 
58  /**
59  * Constructor.
60  *
61  * \param hour hour
62  * \param minute minute
63  * \param second second
64  */
65  JTime(const int hour,
66  const int minute,
67  const int second) :
68  hour (hour),
69  minute(minute),
70  second(second)
71  {}
72 
73 
74  /**
75  * Constructor.
76  *
77  * \param time time
78  */
79  JTime(const std::string& time)
80  {
81  std::istringstream in(time);
82 
83  in >> *this;
84  }
85 
86 
87  static JTime min() { return JTime(std::numeric_limits<int>::lowest(), 1, 1); } //!< Minimal time
88  static JTime max() { return JTime(std::numeric_limits<int>::max(), 12, 31); } //!< Maximal time
89 
90 
91  /**
92  * Less-than method.
93  *
94  * \param time time
95  * \return true if this time earlier than given time; else false
96  */
97  bool less(const JTime& time) const
98  {
99  if (this->hour == time.hour) {
100 
101  if (this->minute == time.minute)
102  return this->second < time.second;
103  else
104  return this->minute < time.minute;
105 
106  } else {
107 
108  return this->hour < time.hour;
109  }
110  }
111 
112 
113  /**
114  * Read time from input stream.
115  *
116  * \param in input stream
117  * \param object time
118  * \return input stream
119  */
120  friend inline std::istream& operator>>(std::istream& in, JTime& object)
121  {
122  using namespace std;
123  using namespace JPP;
124 
125  object = JTime();
126 
127  while (isspace(in.peek())) { in.ignore(); }
128 
129  const locale loc = in.imbue(locale(in.getloc(), new JWhiteSpacesFacet(in.getloc(), JTime::SEPARATOR)));
130 
131  in >> object.hour >> object.minute >> object.second;
132 
133  in.imbue(loc);
134 
135  return in;
136  }
137 
138 
139  /**
140  * Write time to output stream.
141  *
142  * \param out output stream
143  * \param object time
144  * \return output stream
145  */
146  friend inline std::ostream& operator<<(std::ostream& out, const JTime& object)
147  {
148  return out << FILL(2,'0') << object.hour << JTime::SEPARATOR
149  << FILL(2,'0') << object.minute << JTime::SEPARATOR
150  << FILL(2,'0') << object.second << FILL();
151  }
152 
153 
154  int hour; //!< hour
155  int minute; //!< minute
156  int second; //!< second
157  };
158 }
159 
160 #endif
friend std::ostream & operator<<(std::ostream &out, const JTime &object)
Write time to output stream.
Definition: Jeep/JTime.hh:146
static JTime max()
Maximal time.
Definition: Jeep/JTime.hh:88
I/O formatting auxiliaries.
JTime(const int hour, const int minute, const int second)
Constructor.
Definition: Jeep/JTime.hh:65
bool less(const JTime &time) const
Less-than method.
Definition: Jeep/JTime.hh:97
then awk string
int second
second
Definition: Jeep/JTime.hh:156
int minute
minute
Definition: Jeep/JTime.hh:155
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
static JTime min()
Minimal time.
Definition: Jeep/JTime.hh:87
JTime(const std::string &time)
Constructor.
Definition: Jeep/JTime.hh:79
static const char SEPARATOR
Separation character.
Definition: Jeep/JTime.hh:45
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
int hour
hour
Definition: Jeep/JTime.hh:154
JTime()
Default constructor.
Definition: Jeep/JTime.hh:51
Auxiliary class for simple time.
Definition: Jeep/JTime.hh:39
char * loc(char *orig)
friend std::istream & operator>>(std::istream &in, JTime &object)
Read time from input stream.
Definition: Jeep/JTime.hh:120