VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
unitConversions.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2013 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 
8 #pragma once
9 
11 #include "tdbutil/tdbUnits.h"
13 
14 #include <QtCore/QString>
15 #include <QtCore/QStringList>
16 #include <QtCore/QHash>
17 #include <QtCore/QList>
18 
19 static const char* DtUnitTimeDay = "day";
20 static const char* DtUnitPercent = "percent";
21 static const char* DtUnitRounds = "rounds";
22 static const char* DtUnitRatio = "ratio";
23 static const char* DtUnitMils = "mils";
24 
43 
44 class DtConverter;
45 
46 typedef DtConverter* (*DtConverterFcn)(bool);
47 
50 
52 {
53 
54 public:
55 
58  {
59  };
60 
62  virtual ~DtUnitConverter()
63  {
64  };
65 
68  {
69  };
70 
72  DtUnitConverter& operator=(const DtUnitConverter& rhs)
73  {
74  if (this == &rhs)
75  {
76  return *this;
77  }
78 
79  return *this;
80  };
81 
82  virtual bool init()
83  {
84  return true;
85  }
86 
88  virtual double metersToLocal(double meters) = 0;
89 
91  virtual double localToMeters(double local) = 0;
92 };
93 
95 
97 {
98 
99 public:
100 
103  {
104  };
105 
107  virtual ~DtMeterConverter()
108  {
109  };
110 
113  DtUnitConverter(orig)
114  {
115  };
116 
119  {
120  if (this == &rhs)
121  {
122  return *this;
123  }
124 
126 
127  return *this;
128  };
129 
131  virtual double metersToLocal(double meters);
132 
134  virtual double localToMeters(double local);
135 };
136 
138 {
139 
140 public:
141 
144  {
145  };
146 
149  {
150  };
151 
154  DtUnitConverter(orig)
155  {
156  };
157 
160  {
161  if (this == &rhs)
162  {
163  return *this;
164  }
165 
167 
168  return *this;
169  };
170 
172  virtual double metersToLocal(double meters);
173 
175  virtual double localToMeters(double local);
176 };
177 
179 {
180 
181 public:
182 
185  {
186  };
187 
189  virtual ~DtFeetConverter()
190  {
191  };
192 
195  DtUnitConverter(orig)
196  {
197  };
198 
201  {
202  if (this == &rhs)
203  {
204  return *this;
205  }
206 
208 
209  return *this;
210  };
211 
213  virtual double metersToLocal(double meters);
214 
216  virtual double localToMeters(double local);
217 };
218 
220 {
221 
222 public:
223 
226  {
227  };
228 
230  virtual ~DtMileConverter()
231  {
232  };
233 
236  DtUnitConverter(orig)
237  {
238  };
239 
242  {
243  if (this == &rhs)
244  {
245  return *this;
246  }
247 
249 
250  return *this;
251  };
252 
254  virtual double metersToLocal(double meters);
255 
257  virtual double localToMeters(double local);
258 };
259 
261 {
262 
263 public:
264 
267  {
268  };
269 
272  {
273  };
274 
277  DtUnitConverter(orig)
278  {
279  };
280 
283  {
284  if (this == &rhs)
285  {
286  return *this;
287  }
288 
290 
291  return *this;
292  };
293 
295  virtual double metersToLocal(double meters);
296 
298  virtual double localToMeters(double local);
299 };
300 
302 {
303 public:
304  DtConverterClass() : myFcn(0), myReverse(false) {};
305  DtConverterClass(DtConverterFcn fcn, bool reverse) :
306  myFcn(fcn), myReverse(reverse) {};
308  myFcn(orig.myFcn), myReverse(orig.myReverse) {};
309 
310  DtConverterFcn myFcn;
311  bool myReverse;
312 };
313 
315 {
316 public:
317  DtUnit();
318  DtUnit(const QString& m, const QString& t);
319  DtUnit(const DtUnit&);
320  DtUnit& operator=(const DtUnit&);
321 
322  virtual QString stringRep() const;
323 
324  bool operator==(const DtUnit& rhs) const { return ((myMeasurement == rhs.myMeasurement) && (myTime == rhs.myTime)); };
325  bool operator!=(const DtUnit& rhs) const { return !(*this == rhs); };
326 
327  const QString& measurement() const { return myMeasurement; };
328  const QString& time() const { return myTime; };
329 
330  bool isValid() const { return (myMeasurement.length() || myTime.length()); };
331 
332 public:
333  static QString measurementTitle(const DtUnit& u);
334  static void registerMeasurementTitle(const QString& m, const QString& t, const QString& v);
335 
338  static QString unitDisplayTitle(const QString& u);
339  static void registerUnitDisplayTitle(const QString& m, const QString& t);
340 
342  static QString unitForDisplayTitle(const QString&);
343 
344  static const QHash<QString, QString>& unitDisplayTitles();
345 
346 protected:
347  QString myMeasurement;
348  QString myTime;
349  static QHash<QString, QHash<QString, QString> > theMeasurementTitles;
350  static QHash<QString, QString> theUnitTitles;
351 };
352 
354 {
355 public:
356  DtConverter(bool reverse);
357 
358  virtual double convert(double, bool reverse = false) const { return 0; };
359 
360  bool reverse() const { return myReverse; };
361 
362 protected:
363  bool myReverse;
364 };
365 
367 {
368 public:
369  DtMetersToMiles(bool);
370  virtual double convert(double, bool reverse = false) const;
371 
372  static DtConverter* create(bool);
373 };
374 
376 {
377 public:
378  DtRatioToPercent(bool);
379  virtual double convert(double, bool reverse = false) const;
380 
381  static DtConverter* create(bool);
382 };
383 
385 {
386 public:
387  DtMetersToFeet(bool);
388  virtual double convert(double, bool reverse = false) const;
389  static DtConverter* create(bool);
390 };
391 
393 {
394 public:
395  DtMetersToKilometers(bool);
396  virtual double convert(double, bool reverse = false) const;
397  static DtConverter* create(bool);
398 };
399 
401 {
402 public:
404  virtual double convert(double, bool reverse = false) const;
405  static DtConverter* create(bool);
406 };
407 
409 {
410 public:
411  DtRadiansToDegrees(bool);
412  virtual double convert(double, bool reverse = false) const;
413  static DtConverter* create(bool);
414 };
415 
417 {
418 public:
419  DtRadiansToMils(bool);
420  virtual double convert(double, bool reverse = false) const;
421  static DtConverter* create(bool);
422 };
423 
425 {
426 public:
427  DtMinutesToHours(bool);
428  virtual double convert(double, bool reverse = false) const;
429  static DtConverter* create(bool);
430 };
431 
433 {
434 public:
435  DtSecondsToMinutes(bool);
436  virtual double convert(double, bool reverse = false) const;
437  static DtConverter* create(bool);
438 };
439 
441 {
442 public:
443  DtHoursToDays(bool);
444  virtual double convert(double, bool reverse = false) const;
445  static DtConverter* create(bool);
446 };
447 
449 
451 {
452 public:
453  DtOneToOneConverter(bool);
454  virtual double convert(double, bool reverse = false) const;
455  static DtConverter* create(bool);
456 };
457 
459 {
460 public:
462  {
464  DtConvertTime
465  };
466 
467 public:
469 
470  virtual ~DtUnitConverterFactory();
471 
472 public:
476  virtual void registerUnitConversion(const QString& from, const QString& to, DtConverterFcn fcn,
477  const QString& title = "", const QString& unitTitle = "", bool addTimeUnits = false);
478 
479 public:
480  static DtUnitConverterFactory& instance(makVrv::DtDe&);
481  static void registerInstance(makVrv::DtDe&, DtUnitConverterFactory*);
482 
483  virtual void registerConversion(const QString& from, const QString& to, DtConverterFcn);
484 
486  virtual bool init();
487 
488  virtual DtUnit parse(const QString&) const;
489  virtual bool canConvert(const DtUnit&, const DtUnit&) const;
490  virtual double convert(const DtUnit& from, const DtUnit& to, double val, bool& valid, bool reverse = false) const;
491  virtual double convert(DtConversionType, const DtUnit& from, const DtUnit& to, double val, bool& valid,
492  bool reverse = false) const;
493  virtual double convertReverse(const DtUnit& from, const DtUnit& to, double val, bool& valid) const;
494  virtual QList<DtConverter*> conversion(DtConversionType type, const DtUnit& from, const DtUnit& to) const;
495  virtual void findPath(DtConversionType type, const DtUnit& from, const DtUnit& to, const QHash<QString, DtConverterClass>&,
496  QList<DtConverter*>& path) const;
497 
500  virtual double convertSourceToDestination(double val, const QString& source, const QString& destination) const;
501 
503  virtual double convertDestinationToSource(double val, const QString& source, const QString& destination) const;
504 
505  virtual QString unitTitle(const QString& u) const;
506 
507 protected:
508  virtual void registerConverters();
509  virtual void registerConversion(const QString& from, const QString& to, DtConverterFcn, bool);
510 
511 protected:
512  QHash<QString, QHash<QString, DtConverterClass> > myConverters;
513  mutable QHash<QString, QList<DtConverter*> > myConversions;
515 };

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)