Present  0.9
 All Classes Files Functions Variables Typedefs Friends Macros Pages
month-delta.h
Go to the documentation of this file.
1 /*
2  * Present - Date/Time Library
3  *
4  * Definition of the MonthDelta structure and declarations of the corresponding
5  * functions
6  *
7  * This file may be included individually ONLY if being used by a C compiler.
8  * However, it is recommended (and required for C++ projects) to include
9  * "present.h" rather than these individual header files.
10  *
11  * Licensed under the MIT License.
12  * For details, see LICENSE.
13  */
14 
15 #include <time.h>
16 
17 #include "present/internal/cpp-guard.h"
18 #include "present/internal/header-utils.h"
19 #include "present/internal/types.h"
20 
21 #include "present/internal/present-month-delta-data.h"
22 
23 #ifndef _PRESENT_MONTH_DELTA_H_
24 #define _PRESENT_MONTH_DELTA_H_
25 
26 /*
27  * Forward Declarations
28  */
29 
30 /*
31  * C++ Class / C Struct Definition
32  */
33 
38 struct PRESENT_API MonthDelta {
39  /* Internal data representation */
40  struct PresentMonthDeltaData data_;
41 
42 #ifdef __cplusplus
43 
44  static MonthDelta from_months(int_month_delta months);
45 
47  static MonthDelta from_years(int_year_delta years);
48 
50  static MonthDelta zero();
51 
53  int_month_delta months() const;
54 
56  int_year_delta years() const;
57 
59  double years_decimal() const;
60 
62  bool is_negative() const;
63 
65  void negate();
66 
71  MonthDelta operator-() const;
72 
74  MonthDelta & operator++();
76  MonthDelta operator++(int);
78  MonthDelta & operator--();
80  MonthDelta operator--(int);
81 
83  MonthDelta & operator*=(const long & scale_factor);
85  MonthDelta & operator/=(const long & scale_factor);
86 
88  friend const MonthDelta operator*(
89  const MonthDelta & delta,
90  const long & scale_factor);
92  friend const MonthDelta operator/(
93  const MonthDelta & delta,
94  const long & scale_factor);
95 
97  MonthDelta & operator+=(const MonthDelta & other);
99  MonthDelta & operator-=(const MonthDelta & other);
100 
102  friend const MonthDelta operator+(
103  const MonthDelta & lhs,
104  const MonthDelta & rhs);
106  friend const MonthDelta operator-(
107  const MonthDelta & lhs,
108  const MonthDelta & rhs);
109 
111  static short compare(const MonthDelta & lhs, const MonthDelta & rhs);
112 
114  friend bool operator==(const MonthDelta &, const MonthDelta & rhs);
115  friend bool operator!=(const MonthDelta &, const MonthDelta & rhs);
116 
118  friend bool operator<(const MonthDelta & lhs, const MonthDelta & rhs);
120  friend bool operator<=(const MonthDelta & lhs, const MonthDelta & rhs);
122  friend bool operator>(const MonthDelta & lhs, const MonthDelta & rhs);
124  friend bool operator>=(const MonthDelta & lhs, const MonthDelta & rhs);
125 #endif
126 };
127 
128 /*
129  * C Method Declarations
130  */
131 
132 #ifdef __cplusplus
133 extern "C" {
134 #endif
135 
139 PRESENT_API struct MonthDelta
141 
146 PRESENT_API void
148  struct MonthDelta * const result,
150 
154 PRESENT_API struct MonthDelta
156 
161 PRESENT_API void
163  struct MonthDelta * const result,
165 
169 PRESENT_API struct MonthDelta
170 MonthDelta_zero(void);
171 
176 PRESENT_API void
177 MonthDelta_ptr_zero(struct MonthDelta * const result);
178 
182 PRESENT_API int_month_delta
183 MonthDelta_months(const struct MonthDelta * const self);
184 
190 PRESENT_API int_year_delta
191 MonthDelta_years(const struct MonthDelta * const self);
192 
197 PRESENT_API double
198 MonthDelta_years_decimal(const struct MonthDelta * const self);
199 
203 PRESENT_API present_bool
204 MonthDelta_is_negative(const struct MonthDelta * const self);
205 
210 PRESENT_API void
211 MonthDelta_negate(struct MonthDelta * const self);
212 
216 PRESENT_API void
217 MonthDelta_multiply_by(struct MonthDelta * const self, long scale_factor);
218 
222 PRESENT_API void
223 MonthDelta_divide_by(struct MonthDelta * const self, long scale_factor);
224 
229 PRESENT_API void
231  struct MonthDelta * const self,
232  const struct MonthDelta * const other);
233 
238 PRESENT_API void
240  struct MonthDelta * const self,
241  const struct MonthDelta * const other);
242 
250 PRESENT_API short
252  const struct MonthDelta * const lhs,
253  const struct MonthDelta * const rhs);
254 
258 PRESENT_API present_bool
260  const struct MonthDelta * const lhs,
261  const struct MonthDelta * const rhs);
262 
266 PRESENT_API present_bool
268  const struct MonthDelta * const lhs,
269  const struct MonthDelta * const rhs);
270 
275 PRESENT_API present_bool
277  const struct MonthDelta * const lhs,
278  const struct MonthDelta * const rhs);
279 
284 PRESENT_API present_bool
286  const struct MonthDelta * const lhs,
287  const struct MonthDelta * const rhs);
288 
293 PRESENT_API present_bool
295  const struct MonthDelta * const lhs,
296  const struct MonthDelta * const rhs);
297 
298 #ifdef __cplusplus
299 }
300 #endif
301 
302 #endif /* _PRESENT_MONTH_DELTA_H_ */
303 
int_month_delta months() const
Get the number of months represented by a MonthDelta.
present_int32 int_year_delta
Definition: types.h:91
present_bool MonthDelta_is_negative(const struct MonthDelta *const self)
Determine whether a MonthDelta is negative.
present_bool MonthDelta_less_than(const struct MonthDelta *const lhs, const struct MonthDelta *const rhs)
Determine whether a MonthDelta is less than another MonthDelta (lhs < rhs).
void MonthDelta_subtract(struct MonthDelta *const self, const struct MonthDelta *const other)
Subtract another MonthDelta from a MonthDelta.
int_month_delta MonthDelta_months(const struct MonthDelta *const self)
Get the number of months represented by a MonthDelta.
void MonthDelta_negate(struct MonthDelta *const self)
Negate a MonthDelta, making it negative if it was positive or positive if it was negative.
present_bool MonthDelta_equal(const struct MonthDelta *const lhs, const struct MonthDelta *const rhs)
Determine whether two MonthDelta instances are equal (lhs == rhs).
void MonthDelta_ptr_zero(struct MonthDelta *const result)
Create a new MonthDelta initialized to zero months.
struct MonthDelta MonthDelta_from_months(int_month_delta months)
Create a new MonthDelta based on a positive or negative number of months.
struct MonthDelta MonthDelta_from_years(int_year_delta years)
Create a new MonthDelta based on a positive or negative number of years.
present_bool MonthDelta_less_than_or_equal(const struct MonthDelta *const lhs, const struct MonthDelta *const rhs)
Determine whether a MonthDelta is less than or equal to another MonthDelta (lhs <= rhs)...
void MonthDelta_divide_by(struct MonthDelta *const self, long scale_factor)
Scale a MonthDelta by dividing it by a scale factor.
int_year_delta years() const
Get the number of years represented by a MonthDelta.
present_int32 int_month_delta
Definition: types.h:90
present_bool MonthDelta_greater_than(const struct MonthDelta *const lhs, const struct MonthDelta *const rhs)
Determine whether a MonthDelta is greater than another MonthDelta (lhs > rhs).
void MonthDelta_multiply_by(struct MonthDelta *const self, long scale_factor)
Scale a MonthDelta by multiplying it by a scale factor.
short MonthDelta_compare(const struct MonthDelta *const lhs, const struct MonthDelta *const rhs)
Compare two MonthDelta instances.
double MonthDelta_years_decimal(const struct MonthDelta *const self)
Get the number of years represented by a MonthDelta, with a fractional part if necessary.
void MonthDelta_add(struct MonthDelta *const self, const struct MonthDelta *const other)
Add another MonthDelta to a MonthDelta.
void MonthDelta_ptr_from_months(struct MonthDelta *const result, int_month_delta months)
Create a new MonthDelta based on a positive or negative number of months.
void MonthDelta_ptr_from_years(struct MonthDelta *const result, int_year_delta years)
Create a new MonthDelta based on a positive or negative number of years.
struct MonthDelta MonthDelta_zero(void)
Create a new MonthDelta initialized to zero months.
bool present_bool
Definition: types.h:21
int_year_delta MonthDelta_years(const struct MonthDelta *const self)
Get the number of years represented by a MonthDelta.
Class or struct representing a positive or negative delta of a number of months or years...
Definition: month-delta.h:38
present_bool MonthDelta_greater_than_or_equal(const struct MonthDelta *const lhs, const struct MonthDelta *const rhs)
Determine whether a MonthDelta is greater than or equal to another MonthDelta (lhs >= rhs)...