1
1
////////////////////////////////////////////////////////////////////////////////
2
2
/*! @file Units.h Единицы измерения физвеличин.
3
3
- Part of RANet - Research Assistant Net Library (based on ANSI C++).
4
- Copyright(C) 2007-2010, Viktor E. Bursian, St.Petersburg, Russia.
4
- Copyright(C) 2007-2011, Viktor E. Bursian, St.Petersburg, Russia.
5
5
Viktor.Bursian@mail.ioffe.ru
6
6
*///////////////////////////////////////////////////////////////////////////////
15
16
//------------------------------------------------------------------------------
17
18
ANNOUNCE_CLASS(sUnit)
18
19
ANNOUNCE_CLASS(sUnits)
19
20
ANNOUNCE_CLASS(sPhysValue)
21
RANet_EXPORT extern real const ln10;
21
//! @todo{PhysValues} friend class sPhysRange - хорошо ли?
22
ANNOUNCE_CLASS(sPhysRange)
23
24
//------------------------------------------------------------------------------
25
inline real power10 (real E)
25
/*! Константа "пустые единицы".
27
Используется в определениях переменных или членов, когда нужно создать заведомо
28
безразмерную переменную или член типа sPhysValue или sPhysRange. Введена по двум
29
причинам. Во-первых, C++ не даёт использовать в этих местах выражение
30
@a sUnits() - думает, что это объявление функции. Во-вторых, просто
33
RANet_EXPORT extern csUnits _Unitsless_;
30
36
//------------------------------------------------------------ sMetricPrefix ---
31
37
/*! Provides transformations between metric prefixes and scale multipliers
61
67
static sString Symbol (int Log);
68
static sString CombinedSymbol (int Log);
62
69
static int Exp (sString Prefix);
63
static real Multiplier (sString Prefix);
70
static real Multiplier (int Log);
71
static real Multiplier (sString Prefix)
72
{ return Multiplier(Exp(Prefix)); };
64
73
static sString Name (int Log);
74
static csString StandardAllowance;
75
static csString NoPrefixAllowed;
67
78
//-------------------------------------------------------------------- sUnit ---
84
95
class RANet_EXPORT sUnit : public sStorable
99
typedef bool fRegisterDialog (rsString);
100
typedef fRegisterDialog * pfRegisterDialog;
102
ANNOUNCE_CLASS(sSystem)
109
map<sString,psUnit> UnitList;
111
// friend class sUnit;
88
static psUnit Register (sString symbol ,sString sense);
89
static psUnit Register (sString symbol)
90
{ return Register(symbol,sString()); };
91
static psUnit Unit (sString id);
115
static psUnit Register (sString symbol
116
,sString prefix_allowance
117
,sPhysValue definition);
118
static psUnit Register (sString symbol
119
,sString prefix_allowance);
120
static psUnit Register (sString symbol
121
,sPhysValue definition);
122
static psUnit Register (sString symbol);
123
static psUnit Find (sString symbol);
124
static bool ParseUnitWithPrefix (sString lexem
128
public://static fields
129
static sSystem System;
94
130
static psUnit _1_;
131
static pfRegisterDialog RegisterDialog;
97
134
sString Symbol () const
98
135
{ return TheSymbol; };
99
sString Sense () const
100
{ return TheSense; };
102
{ return TheSymbol + " (" + TheSense + ")"; };
136
bool PrefixAllowed (int prefix_index) const;
137
sString PrefixAllowance ()
138
{ return ThePrefixAllowance; };
139
// void SetPrefixAllowance (sString);
140
psPhysValue Definition () const
141
{ return TheDefinition; };
142
// void SetDefinition (sPhysValue);
143
bool IsBasic () const
144
{ return (TheDefinition != NULL); };
106
sUnit (sString symbol ,sString sense);
147
sUnit (); //!< makes _1_
148
sUnit (sString symbol
149
,sString prefix_allowance
150
,psPhysValue definition);
108
rsUnit operator = (sUnit);
152
rsUnit operator = (rcsUnit);
110
private://static fields
155
void MakeVeryBasicDefinitions ();
116
160
sString TheSymbol;
118
// psPhysValue TheDefinition;
119
// psUnit IsAliasOf // cm-1 (Photon energy) == cm-1 (Energy quantum)
120
// cm-1 (Reverse length) != cm-1 (Energy quantum)
121
// bitset PrefixAllowance
161
sString ThePrefixAllowance;
162
psPhysValue TheDefinition;
163
// sString TheComment;
165
friend class sSystem;
124
168
//------------------------------------------------------------------- sUnits ---
128
172
class RANet_EXPORT sUnits : public sStorable
178
static sUnits Parse (sString);
189
sString Text (eTextFormat F = Plain) const;
190
//!< visual representation for user
191
sPhysValue ToBasic () const;
194
rsUnits operator = (rcsUnits);
195
sPhysValue operator * (rcsUnits) const;
196
sPhysValue operator / (rcsUnits) const;
197
// sPhysValue operator * (rcsPhysValue) const;
198
// sPhysValue operator / (rcsPhysValue) const;
133
201
ANNOUNCE_CLASS(sTerm)
140
208
,PrefixLg(prefix_lg)
142
210
bool operator < (rcsTerm T) const
143
{ return Unit->Id() < T.Unit->Id(); };
211
{ return Unit->Symbol()
152
sUnits (psUnit unit = sUnit::_1_
157
rsUnits operator = (sUnits);
159
{ return Product.empty(); };
160
sString Text (eTextFormat F = Plain) const;
161
//!< visual representation for user
162
// sString TextRefined () const;
163
bool Comparable (rcsUnits U, real & coeff) const;
166
sPhysValue operator * (sUnits) const;
167
sPhysValue operator / (sUnits) const;
170
// void DissolveOrder (int & log_shift);
171
// void Normalize (int log_shift = 0);
172
// sUnits Refine () const;
220
typedef std::list<sTerm> tProduct;
221
typedef std::valarray<int> tPrefixes;
224
static void SubstituteDefinitions (real & coeff
175
void SimplifyProduct (int & log_shift);
228
int MultBy (rcsUnits);
229
int DivideBy (rcsUnits);
230
// bool Comparable (rcsUnits units
232
// ,bool & power_of_ten) const;
233
bool Comparable (rcsUnits units
234
,real & ratio) const;
235
int DissolveOrder (unsigned short int level
237
,int min_rest_expected = 0
238
,int max_rest_expected = -1);
239
int SimplifyProduct (int log_shift = 0);
240
// void OrderPushIn (int log_shift);
242
void FindBestChoice (tPrefixes & best_choice
244
,int & best_rest_order
245
,int min_rest_expected
246
,int max_rest_expected
247
,tPrefixes considered_product
251
,unsigned short int level);
178
std::list<sTerm> Product;
258
friend class sPhysValue;
259
//! @todo{PhysValues} friend class sPhysRange - хорошо ли?
260
friend class sPhysRange;
181
263
//------------------------------------------------------------------------------