scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
scifir::time_duration Class Reference

#include <base_units.hpp>

Inheritance diagram for scifir::time_duration:
Inheritance graph
[legend]
Collaboration diagram for scifir::time_duration:
Collaboration graph
[legend]

Public Member Functions

 time_duration ()
 
 time_duration (const scalar_unit &)
 
 time_duration (scalar_unit &&)
 
 time_duration (float new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 time_duration (double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 time_duration (long double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 time_duration (int new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 time_duration (float new_value, const string &init_dimensions)
 
 time_duration (double new_value, const string &init_dimensions)
 
 time_duration (long double new_value, const string &init_dimensions)
 
 time_duration (int new_value, const string &init_dimensions)
 
 time_duration (float new_value, const vector< dimension > &new_dimensions)
 
 time_duration (double new_value, const vector< dimension > &new_dimensions)
 
 time_duration (long double new_value, const vector< dimension > &new_dimensions)
 
 time_duration (int new_value, const vector< dimension > &new_dimensions)
 
 time_duration (const string &init_time)
 
 operator std::chrono::seconds () const
 
int get_years () const
 
int get_months () const
 
int get_weeks () const
 
int get_days () const
 
int get_hours () const
 
int get_minutes () const
 
int get_seconds () const
 
string get_finish_date () const
 
string display_as_time () const
 
string display_years () const
 
string display_months () const
 
string display_weeks () const
 
string display_days () const
 
string display_hours () const
 
string display_minutes () const
 
string display_seconds () const
 
template<typename T1 , typename T2 >
scifir::time_durationoperator+= (chrono::duration< T1, T2 > x)
 
template<typename T1 , typename T2 >
scifir::time_durationoperator-= (chrono::duration< T1, T2 > x)
 
void operator+= (scalar_unit x)
 Addition operator, it adds a scalar_unit class to another, by converting their dimensions to be equal first. If their basic dimensions are different, it doesn't sums to the value.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator+= (T y)
 Addition operator, it adds the numeric type to the value, independent of the dimensions.
 
void operator-= (scalar_unit x)
 Substraction operator, it substracts a scalar_unit class to another, by converting their dimensions to be equal first. If their basic dimensions are different, it doesn't substracts to the value.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator-= (T y)
 Substraction operator, it substracts the numeric type to the value, independent of the dimensions.
 
- Public Member Functions inherited from scifir::scalar_unit
 scalar_unit ()
 Default constructor, the value is 0 and the dimensions are empty.
 
 scalar_unit (const scalar_unit &x)
 Copy constructor, copies the value and the dimensions.
 
 scalar_unit (scalar_unit &&x)
 Move constructor, moves the value and the dimensions.
 
 scalar_unit (float new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 scalar_unit (double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 scalar_unit (long double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 scalar_unit (int new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 scalar_unit (float new_value, const string &init_dimensions)
 Creates a new scalar_unit with the value and with the dimensions specified in the string.
 
 scalar_unit (double new_value, const string &init_dimensions)
 Creates a new scalar_unit, the double is casted to a float.
 
 scalar_unit (long double new_value, const string &init_dimensions)
 Creates a new scalar_unit, the long double is casted to a float.
 
 scalar_unit (int new_value, const string &init_dimensions)
 Creates a new scalar_unit, the int is casted to a float.
 
 scalar_unit (float new_value, const vector< dimension > &new_dimensions)
 Creates a new scalar_unit with the value given and copying the dimensions.
 
 scalar_unit (double new_value, const vector< dimension > &new_dimensions)
 Creates a new scalar_unit, the double is casted to a float, the dimensions are copied.
 
 scalar_unit (long double new_value, const vector< dimension > &new_dimensions)
 Creates a new scalar_unit, the long double is casted to a float, the dimensions are copied.
 
 scalar_unit (int new_value, const vector< dimension > &new_dimensions)
 Creates a new scalar_unit, the int is casted to a float, the dimensions are copied.
 
 scalar_unit (const string &init_scalar)
 Creates a new scalar_unit, the initialization string specifies both the value and the dimensions.
 
scalar_unitoperator= (const scalar_unit &x)
 Copy assignment, it assigns a copy of the scalar_unit.
 
scalar_unitoperator= (scalar_unit &&x)
 Move assignment, it moves the scalar_unit.
 
scalar_unitoperator= (const string &init_scalar)
 Assignment with an initialization string, the value and the dimensions are both specified.
 
 operator float () const
 Cast the scalar_unit to their float equivalent, it discards the dimensions and copies the value to a float.
 
bool operator== (scalar_unit x) const
 Comparison operator, two scalar_unit classes are considered equivalent if they have the same value given the same dimensions.
 
scalar_unit operator+ (scalar_unit x) const
 Addition operator, it sums two scalar_unit classes, their dimensions are changed to be equal first. If the basic dimensions are different, it returns an empty scalar_unit class.
 
scalar_unit operator- (scalar_unit x) const
 Substraction operator, it substracts one scalar_unit from the other, their dimensions are changed to be equal first. If the basic dimensions are different, it returns an empty scalar_unit class.
 
scalar_unit operator* (scalar_unit x) const
 Multiplication operator, it multiplies two scalar_unit classes, their dimensions are also multiplied.
 
scalar_unit operator/ (scalar_unit x) const
 Division operator, it divides one scalar_unit class with the other, their dimensions are also divided.
 
scalar_unit operator^ (const scalar_unit &x) const
 Power operator, it powers a scalar_unit class with another, if that second scalar_unit class, which is the exponent, as empty dimensions. If the exponent doesn't has empty dimensions it returns an empty scalar_unit class.
 
void operator+= (scalar_unit x)
 Addition operator, it adds a scalar_unit class to another, by converting their dimensions to be equal first. If their basic dimensions are different, it doesn't sums to the value.
 
void operator-= (scalar_unit x)
 Substraction operator, it substracts a scalar_unit class to another, by converting their dimensions to be equal first. If their basic dimensions are different, it doesn't substracts to the value.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scalar_unit operator+ (T y) const
 Addition operator, it sums the numeric type to the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scalar_unit operator- (T y) const
 Substraction operator, it substracts the numeric type to the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scalar_unit operator* (T y) const
 Multiplication operator, it multiplies the numeric type with the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scalar_unit operator/ (T y) const
 Division operator, it divides the value with the numeric type, independent of the dimensions.
 
template<typename T , typename = typename enable_if<is_integer_number<T>::value>::type>
scalar_unit operator^ (T y) const
 Power operator, it powers the value with the numeric type, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator+= (T y)
 Addition operator, it adds the numeric type to the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator-= (T y)
 Substraction operator, it substracts the numeric type to the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator*= (T y)
 Multiplication operator, it multiplies the numeric type to the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator/= (T y)
 Division operator, it divides the numeric type to the value, independent of the dimensions.
 
scalar_unitoperator++ ()
 Increment operator, it increases the value by one.
 
scalar_unitoperator++ (int)
 Increment operator, it increases the value by one.
 
scalar_unitoperator-- ()
 Decrement operator, it decreases the value by one.
 
scalar_unitoperator-- (int)
 Decrement operator, it decreases the value by one.
 
void change_dimensions (const string &init_dimensions)
 Changes the dimensions to the dimensions specified by the initialization string of dimensions.
 
void change_dimensions (const scalar_unit &x)
 Changes the dimensions to the same dimensions of the scalar_unit.
 
bool has_dimensions (const string &init_dimensions) const
 Checks if the basic dimensions are the same as the initialization string of dimensions.
 
bool has_dimensions (const vector< dimension > &x_dimensions) const
 Checks if the basic dimensions are the same as some set of dimensions.
 
bool has_dimensions (const scalar_unit &x) const
 Checks if the basic dimensions are the same as other scalar_unit.
 
bool has_empty_dimensions () const
 Checks if there aren't base dimensions.
 
bool is_dimensionless () const
 Returns true if there aren't dimensions or if all dimensions are dimensionless.
 
bool has_simple_dimensions () const
 Returns true if there's only a simple dimension.
 
bool has_single_dimensions () const
 Returns true if there's only one dimension, which can be simple or composite.
 
bool has_composite_dimensions () const
 Returns true is there's more than one simple dimension.
 
string display_dimensions () const
 Generates an string of the dimensions of the scalar_unit, with the same format as the initialization string of dimensions.
 
dimension::type get_single_dimension_type () const
 Returns the dimension::type if there's only one dimension, returns dimension::NONE if there's more than one dimension or if the dimensions are empty.
 
vector< dimensionget_base_dimensions () const
 Generates a set of the base dimensions of the dimensions of the scalar_unit.
 
const vector< dimension > & get_dimensions () const
 Read-only getter of the dimensions.
 
const floatget_value () const
 Read-only getter of the value.
 
string display (int number_of_decimals=2, bool with_brackets=false, bool use_close_prefix=false) const
 Generates a string representation of the scalar_unit, with the value and the dimensions. The dimensions can be enclosed by brackets, and the value can be set to have the closest prefix.
 
string base_display (int number_of_decimals=2, bool with_brackets=false, bool use_close_prefix=false) const
 Generates a string representation of the scalar_unit, with its dimensions converted to their base counterpart.
 
string custom_display (const string &init_dimensions, int number_of_decimals=2, bool with_brackets=false) const
 Generates a string representation of the scalar_unit, with the dimensions changed to any set of dimensions, specified by an initialization string of dimensions.
 
string to_latex (const string &init_dimensions, int number_of_decimals=2, bool with_brackets=false) const
 

Static Public Attributes

static const string dimensions_match = "s"
 
static const vector< dimensionreal_dimensions = create_base_dimensions("s")
 

Additional Inherited Members

- Protected Member Functions inherited from scifir::scalar_unit
void add_dimension (const dimension &new_dimension)
 Internal function. It adds a dimension, changing the value according to the conversion factor of the added dimension and the prefix.
 
void remove_dimension (const dimension &old_dimension)
 Internal function. It removes a dimension, changing the value according to the conversion factor of the removed dimension and the prefix.
 
void initialize_from_string (string init_scalar, const vector< dimension > &real_dimensions)
 Internal function. It sets the value and the dimensions of the scalar_unit to the value and dimensions specified by the initialization string of scalar_unit.
 
void check_dimensions (const vector< dimension > &real_dimensions)
 
- Protected Attributes inherited from scifir::scalar_unit
vector< dimensiondimensions
 Dimensions of the scalar_unit. They can be simple dimensions, composite dimensions or special names.
 
float value
 Value of the scalar_unit. It changes automatically when the dimensions change.
 

Detailed Description

Definition at line 18 of file base_units.hpp.

Constructor & Destructor Documentation

◆ time_duration() [1/16]

scifir::time_duration::time_duration ( )

Definition at line 24 of file base_units.cpp.

24 : scalar_unit()
25 {
27 }
vector< dimension > dimensions
Dimensions of the scalar_unit. They can be simple dimensions, composite dimensions or special names.
scalar_unit()
Default constructor, the value is 0 and the dimensions are empty.
static const vector< dimension > real_dimensions

◆ time_duration() [2/16]

scifir::time_duration::time_duration ( const scalar_unit x)

Definition at line 29 of file base_units.cpp.

30 {
31 if (x.has_dimensions(time_duration::real_dimensions))
32 {
33 value = x.get_value();
34 dimensions = x.get_dimensions();
35 }
36 }
float value
Value of the scalar_unit. It changes automatically when the dimensions change.

◆ time_duration() [3/16]

scifir::time_duration::time_duration ( scalar_unit &&  x)

Definition at line 38 of file base_units.cpp.

39 {
40 if (x.has_dimensions(time_duration::real_dimensions))
41 {
42 value = std::move(x.get_value());
43 dimensions = std::move(x.get_dimensions());
44 }
45 }

◆ time_duration() [4/16]

scifir::time_duration::time_duration ( float  new_value,
dimension::type  new_dimension,
prefix::type  new_prefix,
dimension::position  new_position = dimension::NUMERATOR 
)
explicit

Definition at line 47 of file base_units.cpp.

47 : scalar_unit(new_value,new_dimension,new_prefix,new_position)
48 {}

◆ time_duration() [5/16]

scifir::time_duration::time_duration ( double  new_value,
dimension::type  new_dimension,
prefix::type  new_prefix,
dimension::position  new_position = dimension::NUMERATOR 
)
explicit

Definition at line 50 of file base_units.cpp.

50 : scalar_unit(new_value,new_dimension,new_prefix,new_position)
51 {}

◆ time_duration() [6/16]

scifir::time_duration::time_duration ( long double  new_value,
dimension::type  new_dimension,
prefix::type  new_prefix,
dimension::position  new_position = dimension::NUMERATOR 
)
explicit

Definition at line 53 of file base_units.cpp.

53 : scalar_unit(new_value,new_dimension,new_prefix,new_position)
54 {}

◆ time_duration() [7/16]

scifir::time_duration::time_duration ( int  new_value,
dimension::type  new_dimension,
prefix::type  new_prefix,
dimension::position  new_position = dimension::NUMERATOR 
)
explicit

Definition at line 56 of file base_units.cpp.

56 : scalar_unit(new_value,new_dimension,new_prefix,new_position)
57 {}

◆ time_duration() [8/16]

scifir::time_duration::time_duration ( float  new_value,
const string init_dimensions 
)
explicit

Definition at line 59 of file base_units.cpp.

59 : scalar_unit(new_value,init_dimensions)
60 {}

◆ time_duration() [9/16]

scifir::time_duration::time_duration ( double  new_value,
const string init_dimensions 
)
explicit

Definition at line 62 of file base_units.cpp.

62 : scalar_unit(new_value,init_dimensions)
63 {}

◆ time_duration() [10/16]

scifir::time_duration::time_duration ( long double  new_value,
const string init_dimensions 
)
explicit

Definition at line 65 of file base_units.cpp.

65 : scalar_unit(new_value,init_dimensions)
66 {}

◆ time_duration() [11/16]

scifir::time_duration::time_duration ( int  new_value,
const string init_dimensions 
)
explicit

Definition at line 68 of file base_units.cpp.

68 : scalar_unit(new_value,init_dimensions)
69 {}

◆ time_duration() [12/16]

scifir::time_duration::time_duration ( float  new_value,
const vector< dimension > &  new_dimensions 
)
explicit

Definition at line 71 of file base_units.cpp.

71 : scalar_unit(new_value,new_dimensions)
72 {}

◆ time_duration() [13/16]

scifir::time_duration::time_duration ( double  new_value,
const vector< dimension > &  new_dimensions 
)
explicit

Definition at line 74 of file base_units.cpp.

74 : scalar_unit(new_value,new_dimensions)
75 {}

◆ time_duration() [14/16]

scifir::time_duration::time_duration ( long double  new_value,
const vector< dimension > &  new_dimensions 
)
explicit

Definition at line 77 of file base_units.cpp.

77 : scalar_unit(new_value,new_dimensions)
78 {}

◆ time_duration() [15/16]

scifir::time_duration::time_duration ( int  new_value,
const vector< dimension > &  new_dimensions 
)
explicit

Definition at line 80 of file base_units.cpp.

80 : scalar_unit(new_value,new_dimensions)
81 {}

◆ time_duration() [16/16]

scifir::time_duration::time_duration ( const string init_time)
explicit

Definition at line 83 of file base_units.cpp.

83 : scalar_unit()
84 {
85 if(!isdigit(init_time[0]))
86 {
87 return;
88 }
89 else
90 {
91 vector<string> init_values;
92 boost::split(init_values,init_time,boost::is_any_of(" "));
93 value = 0;
94 for (unsigned int i = 0; i < init_values.size(); i++)
95 {
96 int j = 0;
97 while(isdigit(init_values[i][j]) || init_values[i][j] == '.' || init_values[i][j] == ' ' || init_values[i][j] == '*' || init_values[i][j] == '^' || init_values[i][j] == 'e' || init_values[i][j] == 'E')
98 {
99 if (init_values[i][j] == ' ')
100 {
101 break;
102 }
103 j++;
104 }
105 string string_value = init_values[i].substr(0, j);
106 boost::algorithm::erase_all(string_value, " ");
107 size_t search_e = string_value.find("E");
108 if (search_e != string::npos)
109 {
110 string_value.replace(search_e,1,"e");
111 }
112 size_t search_10 = string_value.find("*10^");
113 if (search_10 != string::npos)
114 {
115 string_value.replace(search_10,4,"e");
116 }
117 stringstream ss(string_value);
118 float init_value_float;
119 ss >> init_value_float;
120 string init_value_dimension = init_values[i].substr(j);
121 float init_value_dimension_quantity = 0.0f;
122 if (init_value_dimension == "d")
123 {
124 init_value_dimension_quantity = 86400.0f;
125 }
126 else if(init_value_dimension == "h")
127 {
128 init_value_dimension_quantity = 3600.0f;
129 }
130 else if(init_value_dimension == "min")
131 {
132 init_value_dimension_quantity = 60.0f;
133 }
134 else if(init_value_dimension == "s")
135 {
136 init_value_dimension_quantity = 1.0f;
137 }
138 value += init_value_float * init_value_dimension_quantity;
139 }
141 }
142 }
vector< dimension > create_dimensions(string init_dimensions)
Creates the dimensions from an initialization string of dimensions.

Member Function Documentation

◆ display_as_time()

string scifir::time_duration::display_as_time ( ) const

Definition at line 269 of file base_units.cpp.

270 {
271 ostringstream output;
272 scifir::time_duration remaining_time = *this;
273 scifir::time_duration one_year ("365d");
274 if (*this >= one_year)
275 {
276 int total_of_years = int(trunc((*this / one_year).get_value()));
277 output << total_of_years << "y ";
278 remaining_time -= scifir::time_duration(float(total_of_years) * 365,"d");
279 }
280 scifir::time_duration one_month("30d");
281 if (remaining_time >= one_month)
282 {
283 int total_of_months = int(trunc((remaining_time / one_month).get_value()));
284 output << total_of_months << "m ";
285 remaining_time -= scifir::time_duration(float(total_of_months) * 30,"d");
286 }
287 scifir::time_duration one_day("1d");
288 if (remaining_time >= one_day)
289 {
290 int total_of_days = int(trunc((remaining_time / one_day).get_value()));
291 output << total_of_days << "d ";
292 remaining_time -= scifir::time_duration(float(total_of_days),"d");
293 }
294 scifir::time_duration one_hour("1h");
295 if (remaining_time >= one_hour)
296 {
297 int total_of_hours = int(trunc((remaining_time / one_hour).get_value()));
298 output << total_of_hours << "h ";
299 remaining_time -= scifir::time_duration(float(total_of_hours),"h");
300 }
301 scifir::time_duration one_minute("1min");
302 if (remaining_time >= one_minute)
303 {
304 int total_of_minutes = int(trunc((remaining_time / one_minute).get_value()));
305 output << total_of_minutes << "min ";
306 remaining_time -= scifir::time_duration(float(total_of_minutes),"min");
307 }
308 scifir::time_duration one_second("1s");
309 if (remaining_time >= one_second)
310 {
311 remaining_time.change_dimensions("s");
312 float total_of_seconds = float(remaining_time.get_value());
313 output << total_of_seconds << "s";
314 }
315 return output.str();
316 }
void change_dimensions(const string &init_dimensions)
Changes the dimensions to the dimensions specified by the initialization string of dimensions.
const float & get_value() const
Read-only getter of the value.

◆ display_days()

string scifir::time_duration::display_days ( ) const

Definition at line 339 of file base_units.cpp.

340 {
341 ostringstream out;
342 out << get_days() << " d";
343 return out.str();
344 }

◆ display_hours()

string scifir::time_duration::display_hours ( ) const

Definition at line 346 of file base_units.cpp.

347 {
348 ostringstream out;
349 out << get_hours() << " h";
350 return out.str();
351 }

◆ display_minutes()

string scifir::time_duration::display_minutes ( ) const

Definition at line 353 of file base_units.cpp.

354 {
355 ostringstream out;
356 out << get_minutes() << " min";
357 return out.str();
358 }

◆ display_months()

string scifir::time_duration::display_months ( ) const

Definition at line 325 of file base_units.cpp.

326 {
327 ostringstream out;
328 out << get_months() << " months";
329 return out.str();
330 }

◆ display_seconds()

string scifir::time_duration::display_seconds ( ) const

Definition at line 360 of file base_units.cpp.

361 {
362 ostringstream out;
363 out << get_seconds() << " s";
364 return out.str();
365 }

◆ display_weeks()

string scifir::time_duration::display_weeks ( ) const

Definition at line 332 of file base_units.cpp.

333 {
334 ostringstream out;
335 out << get_weeks() << " weeks";
336 return out.str();
337 }

◆ display_years()

string scifir::time_duration::display_years ( ) const

Definition at line 318 of file base_units.cpp.

319 {
320 ostringstream out;
321 out << get_years() << " y";
322 return out.str();
323 }

◆ get_days()

int scifir::time_duration::get_days ( ) const

Definition at line 193 of file base_units.cpp.

194 {
195 scifir::time_duration one_day("1d");
196 if (*this >= one_day)
197 {
198 return int(trunc((*this / one_day).get_value()));
199 }
200 else
201 {
202 return 0;
203 }
204 }

◆ get_finish_date()

string scifir::time_duration::get_finish_date ( ) const

◆ get_hours()

int scifir::time_duration::get_hours ( ) const

Definition at line 206 of file base_units.cpp.

207 {
208 scifir::time_duration one_hour("1h");
209 if (*this >= one_hour)
210 {
211 return int(trunc((*this / one_hour).get_value()));
212 }
213 else
214 {
215 return 0;
216 }
217 }

◆ get_minutes()

int scifir::time_duration::get_minutes ( ) const

Definition at line 219 of file base_units.cpp.

220 {
221 scifir::time_duration one_minute = scifir::time_duration("1min");
222 if (*this >= one_minute)
223 {
224 return int(trunc((*this / one_minute).get_value()));
225 }
226 else
227 {
228 return 0;
229 }
230 }

◆ get_months()

int scifir::time_duration::get_months ( ) const

Definition at line 167 of file base_units.cpp.

168 {
169 scifir::time_duration one_month("30d");
170 if (*this >= one_month)
171 {
172 return int(trunc((*this / one_month).get_value()));
173 }
174 else
175 {
176 return 0;
177 }
178 }

◆ get_seconds()

int scifir::time_duration::get_seconds ( ) const

Definition at line 232 of file base_units.cpp.

233 {
234 scifir::time_duration one_second("1s");
235 if (*this >= one_second)
236 {
237 return int(trunc((*this / one_second).get_value()));
238 }
239 else
240 {
241 return 0;
242 }
243 }

◆ get_weeks()

int scifir::time_duration::get_weeks ( ) const

Definition at line 180 of file base_units.cpp.

181 {
182 scifir::time_duration one_week("7d");
183 if (*this >= one_week)
184 {
185 return int(trunc((*this / one_week).get_value()));
186 }
187 else
188 {
189 return 0;
190 }
191 }

◆ get_years()

int scifir::time_duration::get_years ( ) const

Definition at line 154 of file base_units.cpp.

155 {
156 scifir::time_duration one_year ("365d");
157 if (*this >= one_year)
158 {
159 return int(trunc((*this / one_year).get_value()));
160 }
161 else
162 {
163 return 0;
164 }
165 }

◆ operator std::chrono::seconds()

scifir::time_duration::operator std::chrono::seconds ( ) const
explicit

Definition at line 147 of file base_units.cpp.

148 {
149 scifir::time_duration a = *this;
150 a.change_dimensions("s");
151 return std::chrono::seconds(int(a.get_value()));
152 }

◆ operator+=() [1/3]

template<typename T1 , typename T2 >
scifir::time_duration & scifir::time_duration::operator+= ( chrono::duration< T1, T2 x)
inline

Definition at line 60 of file base_units.hpp.

61 {
62 chrono::seconds d = chrono::duration_cast<chrono::seconds>(x);
63 scifir::time_duration x_second = scifir::time_duration((long double)d.count(),"s");
65 return *this;
66 }
void operator+=(scalar_unit x)
Addition operator, it adds a scalar_unit class to another, by converting their dimensions to be equal...

◆ operator+=() [2/3]

void scalar_unit::operator+= ( scalar_unit  x)

Addition operator, it adds a scalar_unit class to another, by converting their dimensions to be equal first. If their basic dimensions are different, it doesn't sums to the value.

Definition at line 234 of file scalar_unit.cpp.

187 {
188 if(!has_dimensions(x))
189 {
190 cerr << "Cannot sum different dimensions" << endl;
191 return;
192 }
193 x.change_dimensions(*this);
194 value += x.get_value();
195 }
bool has_dimensions(const string &init_dimensions) const
Checks if the basic dimensions are the same as the initialization string of dimensions.

◆ operator+=() [3/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void scalar_unit::operator+= ( T  y)
inline

Addition operator, it adds the numeric type to the value, independent of the dimensions.

Definition at line 276 of file scalar_unit.hpp.

277 {
278 value += y;
279 }

◆ operator-=() [1/3]

template<typename T1 , typename T2 >
scifir::time_duration & scifir::time_duration::operator-= ( chrono::duration< T1, T2 x)
inline

Definition at line 69 of file base_units.hpp.

70 {
71 chrono::seconds d = chrono::duration_cast<chrono::seconds>(x);
72 scifir::time_duration x_second = scifir::time_duration((long double)d.count(),"s");
74 return *this;
75 }
void operator-=(scalar_unit x)
Substraction operator, it substracts a scalar_unit class to another, by converting their dimensions t...

◆ operator-=() [2/3]

void scalar_unit::operator-= ( scalar_unit  x)

Substraction operator, it substracts a scalar_unit class to another, by converting their dimensions to be equal first. If their basic dimensions are different, it doesn't substracts to the value.

Definition at line 235 of file scalar_unit.cpp.

198 {
199 if(!has_dimensions(x))
200 {
201 cerr << "Cannot substract different dimensions" << endl;
202 return;
203 }
204 x.change_dimensions(*this);
205 value -= x.get_value();
206 }

◆ operator-=() [3/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void scalar_unit::operator-= ( T  y)
inline

Substraction operator, it substracts the numeric type to the value, independent of the dimensions.

Definition at line 282 of file scalar_unit.hpp.

283 {
284 value -= y;
285 }

Member Data Documentation

◆ dimensions_match

const string scifir::time_duration::dimensions_match = "s"
static

Definition at line 82 of file base_units.hpp.

◆ real_dimensions

const vector< dimension > scifir::time_duration::real_dimensions = create_base_dimensions("s")
static

Definition at line 83 of file base_units.hpp.


The documentation for this class was generated from the following files: