-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimingTime.hpp
More file actions
155 lines (136 loc) · 3.31 KB
/
Copy pathTimingTime.hpp
File metadata and controls
155 lines (136 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
$filename - Arduino-Devices, a library to provide a easy to use
abstractions of common electronic devices
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* This file has been taken and modified from the community edition of opensplice
* which is released under the LGPL the full project can be found at
* https://github.com/PrismTech/opensplice and http://www.prismtech.com/
*/
#ifndef TIME_HPP
#define TIME_HPP
#include "Commoninc.hpp"
#include "Timing.hpp"
#include "TimingBase.hpp"
#include "TimingDuration.hpp"
namespace Timing
{
class Time;
}
namespace Timing
{
class Time : public TimingBase<Time>
{
public:
Time()
{
start_ = micros();
}
Time(const Time& time)
{
nsec_ = time.nsec_;
sec_ = time.sec_;
}
explicit Time(uint32_t sec, uint32_t nanosec)
{
sec_ = sec;
nsec_ = nanosec;
}
void tick()
{
Timing::Time t = this->from_microsecs(micros() - start_);
nsec_ = t.nsec_;
sec_ = t.sec_;
}
uint32_t nanosec()
{
this->tick();
return nsec_;
}
uint32_t sec()
{
this->tick();
return sec_;
}
/**
* Add a Time to this Time
*
* @param a_ti Time to add
* @return this Time + a_ti
*/
Time& operator+=(const Time& a_ti);
/**
* Subtract a Time from this Time
*
* @param a_ti Time to subtract
* @return this Time - a_ti
*/
Time& operator-=(const Time& a_ti);
/**
* Multiply this Time by a factor
*
* @param factor the factor to multiply this Time by
* @return this Time * factor
*/
Time& operator*=(uint32_t factor);
/**
* Add a Time to Time
*
* @param other a Time
* @return Time + other
*/
const Time operator +(const Time& other) const;
/**
* Subtract a Time from Time
*
* @param other a Time
* @return the Time - other
*/
const Time operator -(const Time& other) const;
private:
unsigned long start_;
};
}
#if 0
/**
* Multiply Time by a factor
*
* @param lhs factor by which to multiply
* @param rhs Time to multiply
*
* @return factor * Time
*/
const Time operator *(uuint32_t lhs,
const Time& rhs);
/**
* Multiply Time by a factor
*
* @param lhs Time to multiply
* @param rhs factor by which to multiply
*
* @return Time * factor
*/
const Time operator *(const Time& lhs,
uuint32_t rhs);
/**
* Divide Time by a factor
*
* @param lhs Time to divide
* @param rhs factor by which to divide
*/
const Time operator /(const Time& lhs,
uuint32_t rhs);
};
#endif
#endif