TBTK
Need a break? Support the development by playing Polarity Puzzles
Constant.h
1 /* Copyright 2019 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
17 
24 #ifndef COM_DAFER45_TBTK_QUANTITY_CONSTANT
25 #define COM_DAFER45_TBTK_QUANTITY_CONSTANT
26 
27 #include "TBTK/Quantity/Base.h"
28 #include "TBTK/Quantity/Derived.h"
29 #include "TBTK/TBTK.h"
30 
31 #include <cmath>
32 #include <map>
33 #include <string>
34 
35 namespace TBTK{
36 namespace Quantity{
37 
38 class Constant{
39 public:
40  Constant(){};
41 
42  template<typename Quantity>
43  explicit Constant(double value, Quantity);
44 
45  template<typename Quantity>
46  int getExponent() const;
47 
48  operator double(){
49  return value;
50  };
51 private:
52  double value;
53  std::vector<int> exponents;
54 };
55 
56 template<typename Quantity>
57 Constant::Constant(
58  double value,
59  Quantity
60 ) :
61  value(value),
62  exponents(7)
63 {
64  exponents[0] = static_cast<int>(Quantity::Exponent::Angle);
65  exponents[1] = static_cast<int>(Quantity::Exponent::Charge);
66  exponents[2] = static_cast<int>(Quantity::Exponent::Count);
67  exponents[3] = static_cast<int>(Quantity::Exponent::Energy);
68  exponents[4] = static_cast<int>(Quantity::Exponent::Length);
69  exponents[5] = static_cast<int>(Quantity::Exponent::Temperature);
70  exponents[6] = static_cast<int>(Quantity::Exponent::Time);
71 }
72 
73 template<>
74 inline int Constant::getExponent<Angle>() const{
75  return exponents[0];
76 }
77 
78 template<>
79 inline int Constant::getExponent<Charge>() const{
80  return exponents[1];
81 }
82 
83 template<>
84 inline int Constant::getExponent<Count>() const{
85  return exponents[2];
86 }
87 
88 template<>
89 inline int Constant::getExponent<Energy>() const{
90  return exponents[3];
91 }
92 
93 template<>
94 inline int Constant::getExponent<Length>() const{
95  return exponents[4];
96 }
97 
98 template<>
99 inline int Constant::getExponent<Temperature>() const{
100  return exponents[5];
101 }
102 
103 template<>
104 inline int Constant::getExponent<Time>() const{
105  return exponents[6];
106 }
107 
108 }; //End of namesapce Quantity
109 }; //End of namesapce TBTK
110 
111 #endif
112 
Derived Quantity.
TBTK initialization.
Definition: Boolean.h:32
Base Quantity.