BlackTime.h
Go to the documentation of this file.
1  /*
2 
3  ####################################################################################
4  # BlackLib Library controls Beaglebone Black's inputs and outputs. #
5  # Copyright (C) 2013-2015 by Yigit YUCE #
6  ####################################################################################
7  # #
8  # This file is part of BlackLib library. #
9  # #
10  # BlackLib library is free software: you can redistribute it and/or modify #
11  # it under the terms of the GNU Lesser General Public License as published by #
12  # the Free Software Foundation, either version 3 of the License, or #
13  # (at your option) any later version. #
14  # #
15  # BlackLib library is distributed in the hope that it will be useful, #
16  # but WITHOUT ANY WARRANTY; without even the implied warranty of #
17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18  # GNU Lesser General Public License for more details. #
19  # #
20  # You should have received a copy of the GNU Lesser General Public License #
21  # along with this program. If not, see <http://www.gnu.org/licenses/>. #
22  # #
23  # For any comment or suggestion please contact the creator of BlackLib Library #
24  # at ygtyce@gmail.com #
25  # #
26  ####################################################################################
27 
28  */
29 
30 
31 
32 #ifndef BLACKTIME_H_
33 #define BLACKTIME_H_
34 
35 #include <ctime>
36 #include <string>
37 #include <cmath>
38 #include <sys/time.h>
39 
40 
41 namespace BlackLib
42 {
43 
44  // ######################################### BLACKTIMEELAPSED DECLARATION STARTS ######################################### //
45 
51  {
57  {
58  hour = 0;
59  minute = 0;
60  second = 0;
61  miliSecond = 0;
62  microSecond = 0;
63  }
64 
65  unsigned int hour;
66  unsigned int minute;
67  unsigned int second;
68  unsigned int miliSecond;
69  unsigned int microSecond;
70  };
71 
72  // ########################################## BLACKTIMEELAPSED DECLARATION ENDS ########################################## //
73 
74 
75 
76 
77 
78  // ########################################### BLACKTIME DECLARATION STARTS ############################################ //
79 
175  class BlackTime
176  {
177  public:
178 
192  BlackTime();
193 
213  BlackTime(int h,int m,int s);
214 
218  virtual ~BlackTime();
219 
236  int getHour();
237 
254  int getMinute();
255 
272  int getSecond();
273 
296  bool setTime(int h,int m,int s);
297 
340  void start();
341 
350 
359 
386  BlackTime& addHour(int h);
387 
414  BlackTime& addMinute(int m);
415 
442  BlackTime& addSecond(int s);
443 
480  std::string toString(std::string format);
481 
482 
483 
516  static bool isValid(int h,int m,int s);
517 
531  static BlackTime getCurrentTime();
532 
548  static BlackTime fromSecondToTime(long int s);
549 
566  static long int fromTimeToSecond(BlackTime t);
567 
590 
610 
631 
649  bool operator==(BlackTime t);
650 
668  bool operator!=(BlackTime t);
669 
687  bool operator< (BlackTime t);
688 
706  bool operator> (BlackTime t);
707 
725  bool operator<=(BlackTime t);
726 
744  bool operator>=(BlackTime t);
745 
746 
747 
748  private:
749  int hour;
750  int minute;
751  int second;
753  };
754 
755 
756  // ############################################ BLACKTIME DECLARATION ENDS ############################################# //
757 
758 
759 
760 } /* namespace BlackLib */
761 
762 #endif /* BLACKTIME_H_ */
bool operator==(BlackTime t)
Checks equality of two BlackTime.
Definition: BlackTime.cpp:322
bool setTime(int h, int m, int s)
Sets new time values if they are valid.
Definition: BlackTime.cpp:76
int getMinute()
Exports minute value.
Definition: BlackTime.cpp:64
BlackTime & addMinute(int m)
Adds minutes to current minute value.
Definition: BlackTime.cpp:140
BlackTimeElapsed()
Default constructor of BlackTimeElapsed struct.
Definition: BlackTime.h:56
BlackTime()
Constructor of BlackTime class.
Definition: BlackTime.cpp:13
BlackTimeElapsed restart()
Restarts the time measurement.
Definition: BlackTime.cpp:95
std::string toString(std::string format)
Exports readable and formatted version of the time.
Definition: BlackTime.cpp:188
BlackTimeElapsed elapsed()
Exports the elapsed time.
Definition: BlackTime.cpp:102
unsigned int hour
is used to hold the elapsed hour
Definition: BlackTime.h:65
BlackTime operator+(BlackTime t)
Calculates sum of two BlackTime.
Definition: BlackTime.cpp:304
static long int fromTimeToSecond(BlackTime t)
Converts BlackTime to seconds.
Definition: BlackTime.cpp:181
bool operator<=(BlackTime t)
Compares two BlackTime.
Definition: BlackTime.cpp:346
unsigned int miliSecond
is used to hold the elapsed milisecond
Definition: BlackTime.h:68
BlackTime & addHour(int h)
Adds hours to current hour value.
Definition: BlackTime.cpp:131
int getSecond()
Exports second value.
Definition: BlackTime.cpp:70
int minute
is used to hold the minute value
Definition: BlackTime.h:750
static BlackTime fromSecondToTime(long int s)
Converts seconds to BlackTime.
Definition: BlackTime.cpp:167
bool operator>=(BlackTime t)
Compares two BlackTime.
Definition: BlackTime.cpp:351
timeval measureStartTime
is used to hold the start point for measuring elapsed time
Definition: BlackTime.h:752
void start()
Starts the time measurement.
Definition: BlackTime.cpp:90
static BlackTime getCurrentTime()
Exports the current system time.
Definition: BlackTime.cpp:49
Interacts with end user, to do basic time operations.
Definition: BlackTime.h:175
int hour
is used to hold the hour value
Definition: BlackTime.h:749
Holds elapsed time properties.
Definition: BlackTime.h:50
BlackTime & addSecond(int s)
Adds seconds to current second value.
Definition: BlackTime.cpp:152
unsigned int microSecond
is used to hold the elapsed microsecond
Definition: BlackTime.h:69
BlackTime & operator=(BlackTime t)
Assigns one BlackTime to other one.
Definition: BlackTime.cpp:312
unsigned int minute
is used to hold the elapsed minute
Definition: BlackTime.h:66
bool operator!=(BlackTime t)
Checks not equality of two BlackTime.
Definition: BlackTime.cpp:329
BlackTime operator-(BlackTime t)
Calculates difference of two BlackTime.
Definition: BlackTime.cpp:296
static bool isValid(int h, int m, int s)
Checks the validation of input parameters.
Definition: BlackTime.cpp:43
int getHour()
Exports hour value.
Definition: BlackTime.cpp:58
virtual ~BlackTime()
Destructor of BlackTime class.
Definition: BlackTime.cpp:38
bool operator<(BlackTime t)
Compares two BlackTime.
Definition: BlackTime.cpp:336
bool operator>(BlackTime t)
Compares two BlackTime.
Definition: BlackTime.cpp:341
Definition: BlackADC.cpp:36
int second
is used to hold the second value
Definition: BlackTime.h:751
unsigned int second
is used to hold the elapsed second
Definition: BlackTime.h:67