1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#pragma once
/*
===========================
Boring Introductory Stuff
===========================
*/
#define _DIMENSIONS_H_
#include <vector>
#include <string>
#include <windows.h>
#ifndef tstring
#ifdef _UNICODE
typedef std::wstring tstring;
#else
typedef std::string tstring;
#endif // _UNICODE
#endif // tstring
//Some useful typedefs from the Windows SDK.
//Since these are defined in WinNT.h, I'll take the chance of using this condition:
#ifndef _WINNT_
#ifdef _UNICODE
typedef wchar_t *LPTSTR;
typedef wchar_t const *LPCTSTR;
#else
typedef char *LPTSTR;
typedef char const *LPCTSTR;
#endif // _UNICODE
#endif // _WINNT_
//If tchar.h has been included, the following is defined already.
#ifndef _T
#ifdef _UNICODE
#define __T(x) L##x
#else
#define __T(x) x
#endif // _UNICODE
#define _T(x) __T(x)
#endif // _T
#ifndef NULL
#define NULL 0
#endif // NULL
/*
===============================
END Boring Introductory Stuff
===============================
*/
/*
===============
Basic Classes
===============
*/
class Unit
{
//Public Interface
public:
virtual bool IsStandardUnit() const { return false; }
virtual double GetConversionFactor() const { return 1 }
virtual LPCTSTR GetName() const { return NULL; }
virtual LPCTSTR GetSymbol() const { return NULL; }
};
class UnitContext
{
//Member data.
private:
double m_exponent;
Unit &m_unit;
//Constructors
public:
UnitContext() : m_exponent(0), m_unit()
{ }
UnitContext(double exponent, Unit &unit) : m_exponent(exponent), m_unit(unit)
{ }
//Public Interface
public:
double GetExponent() const { return m_exponent; }
void SetExponent(double newExponent) { m_exponent = newExponent; }
Unit const& GetUnit() const { return m_unit; }
void SetUnit(Unit const &newUnit) { m_unit = newUnit };
}
class CompoundUnit : public Unit
{
//Internal data.
protected:
std::vector<UnitContext> _units;
//Constructors
public:
CompoundUnit() : Unit()
{ }
};
class Prefix : public Unit
{
//Member Data
private:
double m_convFactor;
tstring m_name;
tstring m_symbol;
//Constructors
private:
Prefix(double convFactor, LPCTSTR name, LPCTSTR symbol)
: m_convFactor(convFactor), m_name(name), m_symbol(symbol), Unit()
{ }
//Public Interface
double GetConversionFactor() const { return m_convFactor; }
LPCTSTR GetName() const { return m_name.c_str(); }
LPCTSTR GetSymbol() const { return m_symbol.c_str(); }
//Static Members
public:
static Prefix const Neutral;
static Prefix const Deca(10, _T("Deca"), _T("D"));
static Prefix const Hecto(100, _T("Hecto"), _T("H"));
static Prefix const Kilo(1000, _T("Kilo"), _T("k"));
static Prefix const deci(0.1, _T("deci"), _T("d"));
static Prefix const centi(0.01, _T("centi"), _T("c"));
static Prefix const milli(0.001, _T("milli"), _T("m"));
};
/*
===================
END Basic Classes
===================
*/
| |