astrotypes  0.0
BoostDurationCast.cpp
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018 PulsarSearchSoft
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 namespace pss {
26 namespace astrotypes {
27 namespace units {
28 
29 template<class BoostUnit>
30 struct boost_unit_to_std_ratio {
31  static_assert(std::is_same<BoostUnit, BoostUnit>::value, "Unkown conversion from boost unit to std::ratio");
32 };
33 
34 template<>
36  typedef std::ratio<86400, 1> type;
37 };
38 
39 template<>
41  typedef std::ratio<1,1> type;
42 };
43 
44 template<>
46  typedef std::milli type;
47 };
48 
49 template<>
51  typedef std::micro type;
52 };
53 
54 template<>
56  typedef std::nano type;
57 };
58 
59 template<>
61  typedef std::pico type;
62 };
63 
64 template<typename BoostType, typename ChronoType>
65 struct has_equivalent_unit : public std::is_same<typename boost_unit_to_std_ratio<typename BoostType::unit_type>::type
66  , typename ChronoType::period>::type
67 {
68 };
69 
70 template<typename BoostUnit, typename BoostUnit2, typename NumT, typename Num2T>
71 struct has_equivalent_unit<boost::units::quantity<BoostUnit, NumT>,
72  boost::units::quantity<BoostUnit2, Num2T>> : public std::is_same<NumT, Num2T>::type
73 {
74 };
75 
76 template<typename BoostType, typename ChronoType>
77 struct has_equivalent_rep : public std::is_same<typename BoostType::value_type, typename ChronoType::rep>::type
78 {
79 };
80 
81 template<typename BoostUnit, typename BoostUnit2, typename NumT, typename Num2T>
82 struct has_equivalent_rep<boost::units::quantity<BoostUnit, NumT>,
83  boost::units::quantity<BoostUnit2, Num2T>> : public std::is_same<BoostUnit, BoostUnit2>::type
84 {
85 };
86 
87 template<typename BoostType, typename ChronoType>
88 struct is_equivalent : public std::conditional<has_equivalent_unit<BoostType, ChronoType>::value
89  && has_equivalent_rep<BoostType, ChronoType>::value
90  , std::true_type, std::false_type
91  >::type
92 {
93 };
94 
95 } // namespace units
96 } // namespace astrotypes
97 } // namespace pss
boost::units::make_scaled_unit< boost::units::si::time, boost::units::scale< 10, boost::units::static_rational<-3 >>>::type MilliSecond
Definition: TimeUnits.h:47
Definition: Quantity.h:93
boost::units::make_scaled_unit< boost::units::si::time, boost::units::scale< 10, boost::units::static_rational<-12 >>>::type PicoSecond
Definition: TimeUnits.h:56
boost::units::make_scaled_unit< boost::units::si::time, boost::units::scale< 10, boost::units::static_rational<-9 >>>::type NanoSecond
Definition: TimeUnits.h:53
conversion helper from boost time units to the std::chrono::duration::period equivalent ...
determine is the NumericalRep of the chrono::duration and the boost::quatity are equivalent ...
determine is the units of the chrono::duration and the boost::quatity are equivalent ...
boost::units::make_scaled_unit< boost::units::si::time, boost::units::scale< 10, boost::units::static_rational<-6 >>>::type MicroSecond
Definition: TimeUnits.h:50
boost::units::si::time Second
Definition: TimeUnits.h:44
determine is the boost::quanity and the std::chrono:;duration are equivalent reperesentations i...
boost::units::make_scaled_unit< boost::units::si::time, boost::units::scale< 86400, boost::units::static_rational< 1 >>>::type Day
Definition: TimeUnits.h:43