1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     fnd_TimeSpan.h
4 
5   Copyright (C)2009 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 35684 $
14  *---------------------------------------------------------------------------*/
15 
16 /* Please see man pages for details
17 
18 
19 */
20 
21 #ifndef NN_FND_TIMESPAN_H_
22 #define NN_FND_TIMESPAN_H_
23 
24 #include <nn/types.h>
25 #include <nn/config.h>
26 #include <nn/os/os_HardwareParamsSelect.h>
27 
28 #ifdef __cplusplus
29 
30 namespace nn { namespace fnd {
31 
32 /* Please see man pages for details
33 
34 
35 
36 
37 
38 
39 
40 */
41 class TimeSpan
42 {
43 private:
44     static const s64 TICKS_PER_SECOND = NN_HW_TICKS_PER_SECOND;
45 
46     typedef const class ZeroOnlyTag {} * ZeroOnly;
47 
48 public:
49 
50     /* Please see man pages for details
51 
52 
53 
54 
55 
56 
57 
58     */
59     TimeSpan(ZeroOnly zeroOnly = 0) : m_NanoSeconds(0) { NN_UNUSED_VAR(zeroOnly); }
60 
61     /* Please see man pages for details
62 
63 
64 
65 
66 
67     */
FromNanoSeconds(s64 nanoSeconds)68     static TimeSpan FromNanoSeconds(s64 nanoSeconds) { TimeSpan ret; ret.m_NanoSeconds = nanoSeconds; return ret; }
69 
70     /* Please see man pages for details
71 
72 
73 
74 
75 
76     */
FromMicroSeconds(s64 microSeconds)77     static TimeSpan FromMicroSeconds(s64 microSeconds) { return FromNanoSeconds(microSeconds * 1000); }
78 
79     /* Please see man pages for details
80 
81 
82 
83 
84 
85     */
FromMilliSeconds(s64 milliSeconds)86     static TimeSpan FromMilliSeconds(s64 milliSeconds) { return FromNanoSeconds(milliSeconds * 1000 * 1000); }
87 
88     /* Please see man pages for details
89 
90 
91 
92 
93 
94     */
FromSeconds(s64 seconds)95     static TimeSpan FromSeconds(s64 seconds) { return FromNanoSeconds(seconds * 1000 * 1000 * 1000); }
96 
97     /* Please see man pages for details
98 
99 
100 
101 
102 
103     */
FromMinutes(s64 minutes)104     static TimeSpan FromMinutes(s64 minutes) { return FromNanoSeconds(minutes * 1000 * 1000 * 1000 * 60); }
105 
106     /* Please see man pages for details
107 
108 
109 
110 
111 
112     */
FromHours(s64 hours)113     static TimeSpan FromHours(s64 hours) { return FromNanoSeconds(hours * 1000 * 1000 * 1000 * 60 * 60); }
114 
115     /* Please see man pages for details
116 
117 
118 
119 
120 
121     */
FromDays(s64 days)122     static TimeSpan FromDays(s64 days) { return FromNanoSeconds(days * 1000 * 1000 * 1000 * 60 * 60 * 24); }
123 
124     /* Please see man pages for details
125 
126 
127 
128     */
GetDays()129     s64 GetDays() const { return m_NanoSeconds / (1000LL * 1000 * 1000 * 60 * 60 * 24); }
130 
131     /* Please see man pages for details
132 
133 
134 
135     */
GetHours()136     s64 GetHours() const { return m_NanoSeconds / (1000LL * 1000 * 1000 * 60 * 60); }
137 
138     /* Please see man pages for details
139 
140 
141 
142     */
GetMinutes()143     s64 GetMinutes() const { return m_NanoSeconds / (1000LL * 1000 * 1000 * 60); }
144 
145     /* Please see man pages for details
146 
147 
148 
149     */
GetSeconds()150     s64 GetSeconds() const { return m_NanoSeconds / (1000 * 1000 * 1000); }
151     /* Please see man pages for details
152 
153 
154 
155     */
GetMilliSeconds()156     s64 GetMilliSeconds() const { return m_NanoSeconds / (1000 * 1000); }
157     /* Please see man pages for details
158 
159 
160 
161     */
GetMicroSeconds()162     s64 GetMicroSeconds() const { return m_NanoSeconds / 1000; }
163     /* Please see man pages for details
164 
165 
166 
167     */
GetNanoSeconds()168     s64 GetNanoSeconds() const { return m_NanoSeconds; }
169 
170     friend bool operator==(const TimeSpan& lhs, const TimeSpan& rhs) { return lhs.m_NanoSeconds == rhs.m_NanoSeconds; }
171     friend bool operator!=(const TimeSpan& lhs, const TimeSpan& rhs) { return !(lhs == rhs); }
172     friend bool operator< (const TimeSpan& lhs, const TimeSpan& rhs) { return lhs.m_NanoSeconds <  rhs.m_NanoSeconds; }
173     friend bool operator> (const TimeSpan& lhs, const TimeSpan& rhs) { return rhs < lhs; }
174     friend bool operator<=(const TimeSpan& lhs, const TimeSpan& rhs) { return !(lhs > rhs); }
175     friend bool operator>=(const TimeSpan& lhs, const TimeSpan& rhs) { return !(lhs < rhs); }
176 
177     TimeSpan& operator+=(const TimeSpan& rhs) { this->m_NanoSeconds += rhs.m_NanoSeconds; return *this; }
178     friend TimeSpan operator+(const TimeSpan& lhs, const TimeSpan& rhs) { TimeSpan ret(lhs); return ret += rhs; }
179 
180     TimeSpan& operator-=(const TimeSpan& rhs) { this->m_NanoSeconds -= rhs.m_NanoSeconds; return *this; }
181     friend TimeSpan operator-(const TimeSpan& lhs, const TimeSpan& rhs) { TimeSpan ret(lhs); return ret -= rhs; }
182 
183 private:
184 
185     s64 m_NanoSeconds;
186 
187 };
188 
189 }}	// end of namespace nn
190 
191 #endif // __cplusplus
192 
193 #endif
194