1 | #include "RpUnits.h" |
---|
2 | #include "RpUnitsCInterface.h" |
---|
3 | |
---|
4 | #ifdef __cplusplus |
---|
5 | extern "C" { |
---|
6 | #endif |
---|
7 | |
---|
8 | RpUnits* defineUnit(const char* unitSymbol, RpUnits* basis) { |
---|
9 | |
---|
10 | return RpUnits::define(unitSymbol, basis); |
---|
11 | } |
---|
12 | |
---|
13 | RpUnits* defineConv( RpUnits* fromUnit, |
---|
14 | RpUnits* toUnit, |
---|
15 | double (*convForwFxnPtr)(double), |
---|
16 | double (*convBackFxnPtr)(double) ) { |
---|
17 | |
---|
18 | return RpUnits::define(fromUnit,toUnit,convForwFxnPtr,convBackFxnPtr); |
---|
19 | } |
---|
20 | |
---|
21 | RpUnits* find(const char* key) { |
---|
22 | |
---|
23 | return RpUnits::find(key); |
---|
24 | } |
---|
25 | |
---|
26 | const char* getUnits(RpUnits* unit) { |
---|
27 | |
---|
28 | static std::string retVal; |
---|
29 | retVal = unit->getUnits(); |
---|
30 | return retVal.c_str(); |
---|
31 | } |
---|
32 | |
---|
33 | const char* getUnitsName(RpUnits* unit) { |
---|
34 | |
---|
35 | static std::string retVal; |
---|
36 | retVal = unit->getUnitsName(); |
---|
37 | return retVal.c_str(); |
---|
38 | } |
---|
39 | |
---|
40 | double getExponent(RpUnits* unit) { |
---|
41 | |
---|
42 | return unit->getExponent(); |
---|
43 | } |
---|
44 | |
---|
45 | RpUnits* getBasis(RpUnits* unit) { |
---|
46 | |
---|
47 | return unit->getBasis(); |
---|
48 | } |
---|
49 | |
---|
50 | int makeMetric(RpUnits* basis) { |
---|
51 | |
---|
52 | return RpUnits::makeMetric(basis); |
---|
53 | } |
---|
54 | |
---|
55 | const char* convert ( const char* fromVal, |
---|
56 | const char* toUnitsName, |
---|
57 | int showUnits, |
---|
58 | int* result ) { |
---|
59 | |
---|
60 | static std::string retVal; |
---|
61 | retVal = RpUnits::convert(fromVal,toUnitsName,showUnits,result); |
---|
62 | return retVal.c_str(); |
---|
63 | } |
---|
64 | |
---|
65 | const char* convert_str ( const char* fromVal, |
---|
66 | const char* toUnitsName, |
---|
67 | int showUnits, |
---|
68 | int* result ) { |
---|
69 | |
---|
70 | static std::string retVal; |
---|
71 | retVal = RpUnits::convert(fromVal,toUnitsName,showUnits,result); |
---|
72 | return retVal.c_str(); |
---|
73 | } |
---|
74 | |
---|
75 | const char* convert_obj_str( RpUnits* fromUnits, |
---|
76 | RpUnits* toUnits, |
---|
77 | double val, |
---|
78 | int showUnits ) { |
---|
79 | |
---|
80 | return convert_obj_str_result(fromUnits,toUnits,val,showUnits,NULL); |
---|
81 | } |
---|
82 | |
---|
83 | const char* convert_obj_str_result( RpUnits* fromUnits, |
---|
84 | RpUnits* toUnits, |
---|
85 | double val, |
---|
86 | int showUnits, |
---|
87 | int* result ) { |
---|
88 | |
---|
89 | static std::string retVal; |
---|
90 | retVal = fromUnits->convert(toUnits,val,showUnits,result); |
---|
91 | return retVal.c_str(); |
---|
92 | } |
---|
93 | |
---|
94 | double convert_dbl ( const char* fromVal, |
---|
95 | const char* toUnitsName, |
---|
96 | int* result ) { |
---|
97 | |
---|
98 | std::string convStr; |
---|
99 | double retVal = 0.0; |
---|
100 | |
---|
101 | convStr = RpUnits::convert(fromVal,toUnitsName,0,result); |
---|
102 | |
---|
103 | if (!convStr.empty()) { |
---|
104 | retVal = atof(convStr.c_str()); |
---|
105 | } |
---|
106 | |
---|
107 | return retVal; |
---|
108 | } |
---|
109 | |
---|
110 | double convert_obj_double( RpUnits* fromUnits, |
---|
111 | RpUnits* toUnits, |
---|
112 | double val ) { |
---|
113 | |
---|
114 | return convert_obj_double_result(fromUnits,toUnits,val,NULL); |
---|
115 | } |
---|
116 | |
---|
117 | double convert_obj_double_result( RpUnits* fromUnits, |
---|
118 | RpUnits* toUnits, |
---|
119 | double val, |
---|
120 | int* result ) { |
---|
121 | |
---|
122 | return fromUnits->convert(toUnits,val,result); |
---|
123 | } |
---|
124 | |
---|
125 | int add_presets ( const char* presetName ) { |
---|
126 | |
---|
127 | return RpUnits::addPresets(presetName); |
---|
128 | } |
---|
129 | |
---|
130 | #ifdef __cplusplus |
---|
131 | } |
---|
132 | #endif |
---|