astrotypes  0.0
Quantity.h
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 #ifndef PSS_ASTROTYPES_UNITS_QUANTITY_H
25 #define PSS_ASTROTYPES_UNITS_QUANTITY_H
26 
27 #pragma GCC diagnostic push
28 #pragma GCC diagnostic ignored "-Wall"
29 #pragma GCC diagnostic ignored "-Wpragmas"
30 #pragma GCC diagnostic ignored "-Wunused-parameter"
31 #pragma GCC diagnostic ignored "-Wunused-variable"
32 #include <boost/units/quantity.hpp>
33 #pragma GCC diagnostic pop
34 
35 namespace pss {
36 namespace astrotypes {
37 namespace units {
38 
44 template<typename Unit, typename NumericalRep, class Enabled = void>
45 class Quantity : public boost::units::quantity<Unit, NumericalRep>
46 {
47  typedef boost::units::quantity<Unit, NumericalRep> BaseT;
48 
49  public:
50  // export base class constructors
51  //using boost::units::quantity<Unit, NumericalRep>::quantity;
52 
56  Quantity(BaseT const& b) : BaseT(b) {}
57  Quantity(BaseT&& b) : BaseT(std::move(b)) {}
58 
62  template<typename UnitType, typename OtherDataType
63  , typename Enable = typename std::enable_if<!std::is_same<UnitType, Unit>::value, void>::type>
64  explicit Quantity(boost::units::quantity<UnitType, OtherDataType> const& o) : BaseT(o) {}
65 
69  template<typename UnitType, typename OtherDataType>
70  Quantity& operator=(boost::units::quantity<UnitType, OtherDataType> const& o)
71  {
72  static_cast<BaseT&>(*this) = BaseT(o);
73  return *this;
74  }
75 };
76 
77 template<typename Unit, typename Rep, typename Unit2, typename Rep2>
78 Quantity<Unit, Rep> operator+(Quantity<Unit, Rep> const& a, boost::units::quantity<Unit2, Rep2> const& b)
79 {
80  return Quantity<Unit, Rep>(static_cast<boost::units::quantity<Unit, Rep>>(a) + b);
81 }
82 
83 template<typename Unit, typename Rep, typename Unit2, typename Rep2>
84 Quantity<Unit, Rep> operator-(Quantity<Unit, Rep> const& a, boost::units::quantity<Unit2, Rep2> const& b)
85 {
86  return Quantity<Unit, Rep>(static_cast<boost::units::quantity<Unit, Rep>>(a) - b);
87 }
88 
89 } // namespace units
90 } // namespace astrotypes
91 } // namespace pss
92 
93 namespace boost {
94 namespace units {
95 
96 template<typename T1, typename Unit, typename X>
97 struct multiply_typeof_helper<T1, pss::astrotypes::units::Quantity<Unit, X>>
98 {
99  typedef typename multiply_typeof_helper<T1, quantity<Unit, X>>::type BoostType;
101 };
102 
103 template<typename T1, typename Unit, typename X>
104 struct multiply_typeof_helper<pss::astrotypes::units::Quantity<Unit, X>, T1>
105 {
106  typedef typename multiply_typeof_helper<quantity<Unit, X>, T1>::type BoostType;
108 };
109 
110 template<typename T1, typename Unit, typename X>
111 struct divide_typeof_helper<T1, pss::astrotypes::units::Quantity<Unit, X>>
112 {
113  typedef typename divide_typeof_helper<T1, quantity<Unit, X>>::type BoostType;
115 };
116 
117 template<typename T1, typename Unit, typename X>
118 struct divide_typeof_helper<pss::astrotypes::units::Quantity<Unit, X>, T1>
119 {
120  typedef typename divide_typeof_helper<quantity<Unit, X>, T1>::type BoostType;
122 };
123 
124 } // namespace units
125 } // namespace boost
126 #endif // PSS_ASTROTYPES_UNITS_QUANTITY_H
divide_typeof_helper< T1, quantity< Unit, X > >::type BoostType
Definition: Quantity.h:113
Definition: Quantity.h:93
multiply_typeof_helper< quantity< Unit, X >, T1 >::type BoostType
Definition: Quantity.h:106
STL namespace.
pss::astrotypes::units::Quantity< typename BoostType::unit_type, typename BoostType::value_type > type
Definition: Quantity.h:100
multiply_typeof_helper< T1, quantity< Unit, X > >::type BoostType
Definition: Quantity.h:99
TimePoint< ClockType, Duration > operator+(TimePoint< ClockType, Duration > const &lhs, Duration2 const &rhs)
Definition: TimePoint.cpp:117
Quantity(BaseT const &b)
Default empty constructor.
Definition: Quantity.h:56
pss::astrotypes::units::Quantity< typename BoostType::unit_type, typename BoostType::value_type > type
Definition: Quantity.h:107
TimePoint< ClockType, DurationType > operator-(TimePoint< ClockType, DurationType > const &lhs, boost::units::quantity< boost::units::si::time, Rep > const &rhs)
Definition: TimePoint.cpp:135
pss::astrotypes::units::Quantity< typename BoostType::unit_type, typename BoostType::value_type > type
Definition: Quantity.h:114
pss::astrotypes::units::Quantity< typename BoostType::unit_type, typename BoostType::value_type > type
Definition: Quantity.h:121
divide_typeof_helper< quantity< Unit, X >, T1 >::type BoostType
Definition: Quantity.h:120
Quantity(boost::units::quantity< UnitType, OtherDataType > const &o)
instatiate from alternative unit
Definition: Quantity.h:64
Quantity & operator=(boost::units::quantity< UnitType, OtherDataType > const &o)
copy ssignment
Definition: Quantity.h:70