ZeusMath-Library  2.0.4
UnitSystemsManager.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch)
3  *****************************************************************************
4  * Project : Zeus Math Library
5  * Module : UnitSystemsManager
6  * Package : Zeus.ZeusMath.System
7  * Author : Martin Abbuehl
8  * Date : 27.12.2011
9  * System : Zeus-Framework
10  *****************************************************************************
11  * Licence: *
12  * This library is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU Lesser General Public License as *
14  * published by the Free Software Foundation; either version *
15  * 2.1 of the License, or (at your option) any later version. *
16  * *
17  * This library is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU Lesser General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU Lesser General Public *
23  * License along with this library; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
25  *****************************************************************************/
26 
27 /*****************************************************************************
28  * Changes:
29  * 27.12.2011 bha: created zeus 2.0
30  *****************************************************************************/
31 
32 #ifndef UnitSystemsManagerH
33 #define UnitSystemsManagerH
34 
37 #include <zeusbase/System/ZObject.h>
38 
39 // Managersyntax.
40 #define UnitSystemsManager NAMESPACE_Zeus::TUnitSystemsManager::getInstance()
41 
44 enum EUnit
45 {
46  etNoUnit = 0, // Nummerieren für Javascripts.
51  etTime_s = 5,
59  etTime_h = 13,
63  etAcceleration_mm_per_s2 = 17, //covert to foot
64  etAcceleration_m_per_s2 = 18, //covert to foot
65  etPercent = 19,
67  etAcceleration_mm_per_s2_to_inch = 21, //covert to inch
69 };
70 
71 BEGIN_NAMESPACE_Zeus
72 
73 /******************************************************************************/
77 /******************************************************************************/
79 {
80  public:
82  static inline TUnitSystemsManager& getInstance() { return m_Instance; }
83  void setDelegationInterface(IUnitSystemsManager& rManager);
84  void releaseDelegationInterface();
85 
86  /*************************************************************************/
89  /*************************************************************************/
90  inline EUnitSystem MQUALIFIER getUnitSystem() const
91  {
92  EUnitSystem eRetval = m_eUnitSystem;
93 
94  if (m_ptrDelegation != NULL)
95  {
96  eRetval = m_ptrDelegation->getUnitSystem();
97  } // m_ptrDelegation != NULL.
98 
99  return eRetval;
100  }
101 
102  /*************************************************************************/
105  /*************************************************************************/
106  inline void MQUALIFIER setUnitSystem(EUnitSystem eUnitSystem)
107  {
108  m_eUnitSystem = eUnitSystem;
109  if (m_ptrDelegation != NULL)
110  {
111  m_ptrDelegation->setUnitSystem(eUnitSystem);
112  }
113  }
114 
115  //Methods of IZUnknown
116  MEMORY_MANAGER_DECL
117 
119  TString getUnitText(EUnit eUnit) const;
120 
122  static TString getUnitTextMetric(EUnit eUnit);
123 
125  static TString getUnitTextInch(EUnit eUnit);
126 
129  Float getConversionFactorToMetric(EUnit eUnit) const;
130 
133  Float getConversionFactorFromMetric(EUnit eUnit) const;
134 
137  void convertToMetric(Float& fValue, EUnit eUnit,
138  bool bRound, bool bExcludeZero = false) const;
139 
142  void convertFromMetric(Float& fValue, EUnit eUnit,
143  bool bRound, bool bExcludeZero = false) const;
144 
147  Float getConversionToMetric(const Float& fValue, EUnit eUnit,
148  bool bRound, bool bExcludeZero = false) const;
149 
152  Float getConversionFromMetric(const Float& fValue, EUnit eUnit,
153  bool bRound, bool bExcludeZero = false) const;
154 
156  static void round(Float& fValue, const Float& fRoundingStep, bool bExcludeZero);
157 
159  void round(Float& rfValue, bool bExcludeZero = false);
160 
162  static Int getStandardRoundingDigits(EUnitSystem eUnitSystem);
163 
165  inline Int getStandardRoundingDigits() const { return getStandardRoundingDigits(getUnitSystem()); }
166 
168  static Float getStandardRoundingStep(EUnitSystem eUnitSystem);
169 
171  inline Float getStandardRoundingStep() const { return getStandardRoundingStep(getUnitSystem()); }
172 
174  static TString getStandardRoundingFormat(EUnitSystem eUnitSystem);
175 
177  inline TString getStandardRoundingFormat() const { return getStandardRoundingFormat(getUnitSystem()); }
178 
182  #define INVERSE(Method) Float(1) / Method()
183 
184  // Length.
185  static inline Float mm_per_m() { return 1000; }
186  static inline Float m_per_mm() { return INVERSE(mm_per_m); }
187  static inline Float um_per_mm() { return 1000; }
188  static inline Float mm_per_um() { return INVERSE(um_per_mm); }
189  static inline Float mm_per_inch() { return 25.4; }
190  static inline Float inch_per_mm() { return INVERSE(mm_per_inch); }
191  static inline Float inch_per_foot() { return 12; }
192  static inline Float foot_per_inch() { return INVERSE(inch_per_foot); }
193  static inline Float mm_per_foot() { return mm_per_inch() * inch_per_foot(); }
194  static inline Float foot_per_mm() { return INVERSE(mm_per_foot); }
195  static inline Float m_per_foot() { return m_per_mm() * mm_per_foot(); }
196  static inline Float foot_per_m() { return INVERSE(m_per_foot); }
197  // Area.
198  static inline Float mm2_per_inch2() { return TMath::pow(mm_per_inch(), 2); }
199  static inline Float inch2_per_mm2() { return INVERSE(mm2_per_inch2); }
200  // Volume.
201  static inline Float mm3_per_inch3() { return TMath::pow(mm_per_inch(), 3); }
202  static inline Float inch3_per_mm3() { return INVERSE(mm3_per_inch3); }
203  // Time.
204  static inline Float s_per_min() { return 60; }
205  static inline Float min_per_s() { return INVERSE(s_per_min); }
206  // Mass.
207  static inline Float gram_per_kilo() { return 1000; }
208  static inline Float kilo_per_gram() { return INVERSE(gram_per_kilo); }
209  static inline Float gram_per_ounce() { return 28.349523125; } // From: http://de.wikipedia.org/wiki/Unze#Definition_und_Umrechnung.
210  static inline Float ounce_per_gram() { return INVERSE(gram_per_ounce); }
211  static inline Float ounce_per_pound() { return 16; } // From http://de.wikipedia.org/wiki/Pfund#Umrechnung.
212  static inline Float pound_per_ounce() { return INVERSE(ounce_per_pound); }
213  static inline Float gram_per_pound() { return gram_per_ounce() * ounce_per_pound(); }
214  static inline Float pound_per_gram() { return INVERSE(gram_per_pound); }
215  static inline Float kilo_per_pound() { return kilo_per_gram() * gram_per_pound(); }
216  static inline Float pound_per_kilo() { return INVERSE(kilo_per_pound); }
217  // Force.
218  static inline Float earthGravity_ms2() { return 9.80665; }
219  static inline Float newton_per_kilo() { return earthGravity_ms2(); }
220  static inline Float kilo_per_newton() { return INVERSE(newton_per_kilo); }
221  static inline Float newton_per_pound() { return newton_per_kilo() * kilo_per_pound(); }
222  static inline Float pound_per_newton() { return INVERSE(newton_per_pound); }
223 
224  private:
227 
228  private:
230  static TUnitSystemsManager m_Instance;
232  TAutoPtr<IUnitSystemsManager> m_ptrDelegation;
233 
235  EUnitSystem m_eUnitSystem;
236 };
237 
238 //INLINES
239 /****************************************************************************/
242 /****************************************************************************/
243 inline TUnitSystemsManager::TUnitSystemsManager()
244 {
245  m_eUnitSystem = etUndefinedUnitSystem;
246 }
247 
248 /****************************************************************************/
251 /****************************************************************************/
252 inline void TUnitSystemsManager::releaseDelegationInterface()
253 {
254  m_ptrDelegation.release();
255 }
256 
257 /****************************************************************************/
265 /****************************************************************************/
266 inline Float TUnitSystemsManager::getConversionFactorFromMetric(EUnit eUnit) const
267 {
268  return Float(1) / getConversionFactorToMetric(eUnit);
269 }
270 
271 /****************************************************************************/
282 /****************************************************************************/
283 inline Float TUnitSystemsManager::getConversionToMetric(const Float& fValue, EUnit eUnit,
284  bool bRound, bool bExcludeZero /* = false */) const
285 {
286  Float fRetval = fValue;
287  convertToMetric(fRetval, eUnit, bRound, bExcludeZero);
288  return fRetval;
289 }
290 
291 /****************************************************************************/
302 /****************************************************************************/
303 inline Float TUnitSystemsManager::getConversionFromMetric(const Float& fValue, EUnit eUnit,
304  bool bRound, bool bExcludeZero /* = false */) const
305 {
306  Float fRetval = fValue;
307  convertFromMetric(fRetval, eUnit, bRound, bExcludeZero);
308  return fRetval;
309 }
310 
311 END_NAMESPACE_Zeus
312 
313 #endif
Int getStandardRoundingDigits() const
Die Anzahl Nachkommastellen für die Standard-Rundung lesen.
Definition: UnitSystemsManager.h:165
EUnitSystem
Definition: IUnitSystemsManager.hpp:41
static Float mm3_per_inch3()
Definition: UnitSystemsManager.h:201
Definition: UnitSystemsManager.h:78
TString getStandardRoundingFormat() const
Das Standard-Rundungsformat im aktuell in StuderWIN eingestellten Einheitensystem lesen...
Definition: UnitSystemsManager.h:177
static Float kilo_per_newton()
Definition: UnitSystemsManager.h:220
void MQUALIFIER setUnitSystem(EUnitSystem eUnitSystem)
Definition: UnitSystemsManager.h:106
static Float inch2_per_mm2()
Definition: UnitSystemsManager.h:199
EUnit
Definition: UnitSystemsManager.h:44
Definition: UnitSystemsManager.h:65
Definition: UnitSystemsManager.h:64
static Float foot_per_m()
Definition: UnitSystemsManager.h:196
static Float pound_per_gram()
Definition: UnitSystemsManager.h:214
Definition: UnitSystemsManager.h:51
Definition: UnitSystemsManager.h:54
static Float m_per_mm()
Definition: UnitSystemsManager.h:186
static Float s_per_min()
Definition: UnitSystemsManager.h:204
static Float m_per_foot()
Definition: UnitSystemsManager.h:195
Definition: UnitSystemsManager.h:58
static Float mm_per_inch()
Definition: UnitSystemsManager.h:189
static Float min_per_s()
Definition: UnitSystemsManager.h:205
Definition: UnitSystemsManager.h:53
#define zeusmath_class
Definition: PlatformDefines.hpp:48
Definition: UnitSystemsManager.h:68
Definition: UnitSystemsManager.h:61
Definition: UnitSystemsManager.h:46
Definition: IUnitSystemsManager.hpp:55
Definition: UnitSystemsManager.h:59
static Float foot_per_inch()
Definition: UnitSystemsManager.h:192
static Float pound_per_ounce()
Definition: UnitSystemsManager.h:212
Float getStandardRoundingStep() const
Den Standard-Rundungsschritt im aktuell in StuderWIN eingestellten Einheitensystem lesen...
Definition: UnitSystemsManager.h:171
#define INVERSE(Method)
UMRECHNUNGSFAKTOREN ///.
Definition: UnitSystemsManager.h:182
EUnitSystem MQUALIFIER getUnitSystem() const
Definition: UnitSystemsManager.h:90
static Float ounce_per_pound()
Definition: UnitSystemsManager.h:211
Definition: IUnitSystemsManager.hpp:43
static Float um_per_mm()
Definition: UnitSystemsManager.h:187
static Float foot_per_mm()
Definition: UnitSystemsManager.h:194
Definition: UnitSystemsManager.h:48
static Float newton_per_pound()
Definition: UnitSystemsManager.h:221
static Float mm_per_um()
Definition: UnitSystemsManager.h:188
static Float earthGravity_ms2()
Definition: UnitSystemsManager.h:218
static Float gram_per_kilo()
Definition: UnitSystemsManager.h:207
Definition: UnitSystemsManager.h:63
Definition: UnitSystemsManager.h:49
Definition: UnitSystemsManager.h:60
Definition: UnitSystemsManager.h:55
Definition: UnitSystemsManager.h:66
static Float inch_per_foot()
Definition: UnitSystemsManager.h:191
Definition: UnitSystemsManager.h:47
Definition: UnitSystemsManager.h:67
static Float ounce_per_gram()
Definition: UnitSystemsManager.h:210
static Float newton_per_kilo()
Definition: UnitSystemsManager.h:219
static Float kilo_per_pound()
Definition: UnitSystemsManager.h:215
static Float gram_per_ounce()
Definition: UnitSystemsManager.h:209
static Float pound_per_kilo()
Definition: UnitSystemsManager.h:216
static Float gram_per_pound()
Definition: UnitSystemsManager.h:213
static Float inch_per_mm()
Definition: UnitSystemsManager.h:190
static Float inch3_per_mm3()
Definition: UnitSystemsManager.h:202
Definition: UnitSystemsManager.h:52
static Float mm_per_foot()
Definition: UnitSystemsManager.h:193
Definition: UnitSystemsManager.h:56
Definition: UnitSystemsManager.h:57
static Float mm_per_m()
Definition: UnitSystemsManager.h:185
static Float kilo_per_gram()
Definition: UnitSystemsManager.h:208
static Float mm2_per_inch2()
Definition: UnitSystemsManager.h:198
Definition: UnitSystemsManager.h:50
static TUnitSystemsManager & getInstance()
Statische Singleton-Instanz holen.
Definition: UnitSystemsManager.h:82
static Float pound_per_newton()
Definition: UnitSystemsManager.h:222
Definition: UnitSystemsManager.h:62


Written by Benjamin Hadorn http://www.xatlantis.ch.
Last change made on Wed Sep 14 2016 06:45:54