VR-Forces 4.0.4 Class Documentation
include/drawerNative/conversions.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 2008 MaK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: conversions.h,v $ $Revision: 1.4 $ $State: Exp $
00007 *********************************************************************/
00008 
00011 
00012 #ifndef CONVERSIONS_H_
00013 #define CONVERSIONS_H_
00014 
00015 #include "drawerNative/drawerNativeDefines.h"
00016 #include "tdbutil/tdbUnits.h"      
00017 
00018 #include <QtCore/QString>
00019 #include <QtCore/QStringList>
00020 #include <QtCore/QHash>
00021 #include <QtCore/QList>
00022 
00041 
00042 class DtConverter;
00043 
00044 typedef DtConverter* (*DtConverterFcn)(bool);
00045 
00046 class DT_DLL_drawerNative DtConverterClass
00047 {
00048 public:
00049    DtConverterClass() : myFcn(0), myReverse(false) {};
00050    DtConverterClass(DtConverterFcn fcn, bool reverse) :
00051       myFcn(fcn), myReverse(reverse) {};
00052    DtConverterClass(const DtConverterClass& orig) :
00053       myFcn(orig.myFcn), myReverse(orig.myReverse) {};
00054 
00055    DtConverterFcn myFcn;
00056    bool myReverse;
00057 };
00058 
00059 class DT_DLL_drawerNative DtUnit
00060 {
00061 public:
00062    DtUnit();
00063    DtUnit(const QString& m, const QString& t);
00064    DtUnit(const DtUnit&);
00065    DtUnit& operator=(const DtUnit&);
00066 
00067    virtual QString stringRep() const;
00068 
00069    bool operator==(const DtUnit& rhs) const { return ((myMeasurement == rhs.myMeasurement) && (myTime == rhs.myTime)); };
00070    bool operator!=(const DtUnit& rhs) const { return !(*this == rhs); };
00071 
00072    const QString& measurement() const { return myMeasurement; };
00073    const QString& time() const { return myTime; };
00074 
00075    bool isValid() const { return (myMeasurement.length() || myTime.length()); };
00076 
00077 public:
00078    static QString measurementTitle(const DtUnit& u);
00079    static void registerMeasurementTitle(const QString& m, const QString& t, const QString& v);
00080 
00083    static QString unitDisplayTitle(const QString& u);
00084    static void registerUnitDisplayTitle(const QString& m, const QString& t);
00085 
00087    static QString unitForDisplayTitle(const QString&);
00088 
00089    static const QHash<QString, QString>& unitDisplayTitles();
00090 
00091 protected:
00092    QString     myMeasurement;
00093    QString     myTime;
00094    static QHash<QString, QHash<QString, QString> > theMeasurementTitles;
00095    static QHash<QString, QString> theUnitTitles;
00096 };
00097 
00098 class DT_DLL_drawerNative DtConverter
00099 {
00100 public:
00101    DtConverter(bool reverse);
00102 
00103    virtual double convert(double, bool reverse = false) const { return 0; };
00104 
00105    bool reverse() const { return myReverse; };
00106 
00107 protected:
00108    bool myReverse;
00109 };
00110 
00111 class DT_DLL_drawerNative DtMetersToMiles : public DtConverter
00112 {
00113 public:
00114    DtMetersToMiles(bool);
00115    virtual double convert(double, bool reverse = false) const;
00116 
00117    static DtConverter* create(bool);
00118 };
00119 
00120 class DT_DLL_drawerNative DtMetersToFeet : public DtConverter
00121 {
00122 public:
00123    DtMetersToFeet(bool);
00124    virtual double convert(double, bool reverse = false) const;
00125    static DtConverter* create(bool);
00126 };
00127 
00128 class DT_DLL_drawerNative DtMetersToKilometers : public DtConverter
00129 {
00130 public:
00131    DtMetersToKilometers(bool);
00132    virtual double convert(double, bool reverse = false) const;
00133    static DtConverter* create(bool);
00134 };
00135 
00136 class DT_DLL_drawerNative DtMetersToNauticalMiles: public DtConverter
00137 {
00138 public:
00139    DtMetersToNauticalMiles(bool);
00140    virtual double convert(double, bool reverse = false) const;
00141    static DtConverter* create(bool);
00142 };
00143 
00144 class DT_DLL_drawerNative DtRadiansToDegrees : public DtConverter
00145 {
00146 public:
00147    DtRadiansToDegrees(bool);
00148    virtual double convert(double, bool reverse = false) const;
00149    static DtConverter* create(bool);
00150 };
00151 
00152 class DT_DLL_drawerNative DtMinutesToHours : public DtConverter
00153 {
00154 public:
00155    DtMinutesToHours(bool);
00156    virtual double convert(double, bool reverse = false) const;
00157    static DtConverter* create(bool);
00158 };
00159 
00160 class DT_DLL_drawerNative DtSecondsToMinutes : public DtConverter
00161 {
00162 public:
00163    DtSecondsToMinutes(bool);
00164    virtual double convert(double, bool reverse = false) const;
00165    static DtConverter* create(bool);
00166 };
00167 
00169 
00170 class DT_DLL_drawerNative DtOneToOneConverter : public DtConverter
00171 {
00172 public:
00173    DtOneToOneConverter(bool);
00174    virtual double convert(double, bool reverse = false) const;
00175    static DtConverter* create(bool);
00176 };
00177 
00178 class DT_DLL_drawerNative DtUnitConverterFactory : public QObject
00179 {
00180    Q_OBJECT
00181 
00182 public:
00183    enum DtConversionType
00184    {
00185        DtConvertMeasurement,
00186        DtConvertTime
00187    };
00188 
00189 public:
00190    DtUnitConverterFactory();
00191    
00192    virtual ~DtUnitConverterFactory();
00193 
00194 public:
00198    virtual void registerUnitConversion(const QString& from, const QString& to, DtConverterFcn fcn,
00199                const QString& title = "", const QString& unitTitle = "", bool addTimeUnits = false);
00200 
00201 public:
00202    virtual void registerConversion(const QString& from, const QString& to, DtConverterFcn);
00203 
00205    virtual bool init();
00206 
00207    virtual DtUnit parse(const QString&) const;
00208    virtual bool canConvert(const DtUnit&, const DtUnit&) const;
00209    virtual double convert(const DtUnit& from, const DtUnit& to, double val, bool& valid, bool reverse = false) const;
00210    virtual double convert(DtConversionType, const DtUnit& from, const DtUnit& to, double val, bool& valid,
00211       bool reverse = false) const;
00212    virtual double convertReverse(const DtUnit& from, const DtUnit& to, double val, bool& valid) const;
00213    virtual QList<DtConverter*> conversion(DtConversionType type, const DtUnit& from, const DtUnit& to) const;
00214    virtual void findPath(DtConversionType type, const DtUnit& from, const DtUnit& to, const QHash<QString, DtConverterClass>&,
00215       QList<DtConverter*>& path) const;
00216 
00219    virtual double convertSourceToDestination(double val, const QString& source, const QString& destination) const;
00220 
00222    virtual double convertDestinationToSource(double val, const QString& source, const QString& destination) const;
00223 
00224    static DtUnitConverterFactory* create();
00225 
00226    virtual QString unitTitle(const QString& u) const;
00227 
00228 protected:
00229    virtual void registerConverters();
00230    virtual void registerConversion(const QString& from, const QString& to, DtConverterFcn, bool);
00231 
00232 protected:
00233    QHash<QString, QHash<QString, DtConverterClass> > myConverters;
00234    mutable QHash<QString, QList<DtConverter*> > myConversions;
00235 };
00236 
00237 #endif
00238 

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)