casacore
Loading...
Searching...
No Matches
UnitDim.h
Go to the documentation of this file.
1// # UnitDim.h: defines the (private) class describing basic SI dimensions
2// # Copyright (C) 1994,1995,1996,1997,1999,2000,2001
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_UNITDIM_H
27#define CASA_UNITDIM_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/iosfwd.h>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// # Forward Declarations
36class String;
37class UnitVal;
38class UnitMap;
39
40//
41// <summary>
42// describes a unit in basic SI unit dimensions
43// </summary>
44
45// <use visibility=local>
46
47// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tUnit">
48//
49// <prerequisite>
50// You should have at least a preliminary understanding of these classes:
51// <li> <linkto class=Unit>Unit</linkto>
52// </prerequisite>
53//
54// <etymology>
55// Based on Unit and the Dimension of a unit in SI defining units
56// </etymology>
57//
58// <synopsis>
59// Physical units are strings consisting of one or more names of known
60// basic units, separated by '.' or ' ' (for multiplication) or '/' (for
61// division). Each name can optionally be preceded by a standard decimal
62// prefix, and/or followed by an (optionally signed) exponent.
63// Example:
64// km/s/(Mpc.s)2 is identical to km.s-1.Mpc-2.s-2
65//
66// See the <linkto class=Unit>Unit</linkto> for more details.
67//
68// The UnitDim class is a private class for use by the Unit classes. It
69// contains the dimensions in the 9 basic defining SI units of a unit.
70// </synopsis>
71//
72// <example>
73// </example>
74//
75// <motivation>
76// The UnitDim class has been separated to keep the interface between a
77// complex unit description string and the basic SI units clean.
78// </motivation>
79//
80// <todo asof="941110">
81// <li> Some inlining (did not work first go)
82// </todo>
83
84class UnitDim {
85 // # Friends
86 friend class UnitVal;
87 friend class UnitMap;
88 // Output the SI dimensions (e.g. 'km/s/g' as 'm kg-1 s-1')
89 friend ostream &operator<<(ostream &os, const UnitDim &du);
90
91 public:
92 // # Enumerations
93 // Enumeration of the order and number of the defining SI units.
94 // If order or contents changed, change also in dimName() and dimFull().
95 enum Dim { Dm = 0, Dkg, Ds, DA, DK, Dcd, Dmol, Drad, Dsr, Dnon, Dnumber };
96// Constants
97// Number of Longs to cater for 9 bytes.
98#define UNITDIM_DLNUMBER 3
99
100 // Destructor
102
103 protected:
104 void init();
105 void init(Int pos);
106
107 private:
108 // # Constructors
109 // Construct a unit with zero dimension in all SI units
110 UnitDim() { init(); }
111
112 // Copy constructor
113 UnitDim(const UnitDim &other);
114
115 // Construct a unit dimension with a one in the indicated position (as
116 // Dim enumerator) and zeroes in all other units
117 UnitDim(Int pos) { init(pos); }
118
119 // # Operators
120 // Assignment (copy semantics)
121 UnitDim &operator=(const UnitDim &other);
122 // Operators to combine unit dimensions
123 // <group name="combine">
124 // Multiplication adds the unit dimensions of all SI units
125 UnitDim &operator*=(const UnitDim &other);
126 UnitDim operator*(const UnitDim &other) const;
128 // Division subtracts the unit dimensions of all SI units
129 UnitDim &operator/=(const UnitDim &other);
130 UnitDim operator/(const UnitDim &other) const;
131 // </group>
132 // Compare dimension of units
133 // <group name="compare">
134 // Compare for equal dimensions
135 Bool operator==(const UnitDim &other) const;
136 // Compare for unequal dimensions
137 Bool operator!=(const UnitDim &other) const;
138 // </group>
139
140 // # General Member Functions
141 // Raise all SI defining units to an integer power
143
144 // Get the tag for specified dimension
145 static const String &dimName(uInt which);
146
147 // Get the full name for the specified dimension
148 static const String &dimFull(uInt which);
149
150 // # Data Members
151 // 1-byte vector to contain the dimensions of the defining SI units
152 // (using same storage as Long vector for speed reasons)
154 signed char *unitDim;
155};
156
157// # Inline Implementations
158
159// # Global definitions
160// Output
161ostream &operator<<(ostream &os, const UnitDim &du);
162
163} // namespace casacore
164
165#endif
#define UNITDIM_DLNUMBER
Constants Number of Longs to cater for 9 bytes.
Definition UnitDim.h:98
String: the storage and methods of handling collections of characters.
Definition String.h:355
UnitDim()
Construct a unit with zero dimension in all SI units.
Definition UnitDim.h:110
friend ostream & operator<<(ostream &os, const UnitDim &du)
Output the SI dimensions (e.g.
UnitDim(Int pos)
Construct a unit dimension with a one in the indicated position (as Dim enumerator) and zeroes in all...
Definition UnitDim.h:117
static const String & dimName(uInt which)
Get the tag for specified dimension.
void init(Int pos)
Bool operator!=(const UnitDim &other) const
Compare for unequal dimensions.
signed char * unitDim
Definition UnitDim.h:154
UnitDim(const UnitDim &other)
Copy constructor.
UnitDim & operator*=(const UnitDim &other)
Operators to combine unit dimensions .
UnitDim & operator/=(const UnitDim &other)
Division subtracts the unit dimensions of all SI units.
friend class UnitMap
Definition UnitDim.h:87
UnitDim & operator=(const UnitDim &other)
Assignment (copy semantics).
Long unitLong[UNITDIM_DLNUMBER]
1-byte vector to contain the dimensions of the defining SI units (using same storage as Long vector f...
Definition UnitDim.h:153
UnitDim operator*(const UnitDim &other) const
Dim
Enumeration of the order and number of the defining SI units.
Definition UnitDim.h:95
UnitDim pow(Int p)
Raise all SI defining units to an integer power.
~UnitDim()
Destructor.
static const String & dimFull(uInt which)
Get the full name for the specified dimension.
Bool operator==(const UnitDim &other) const
Compare dimension of units .
friend class UnitVal
Definition UnitDim.h:86
UnitDim operator/(const UnitDim &other) const
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
long Long
Definition aipstype.h:50
unsigned int uInt
Definition aipstype.h:49
T & operator*()
Provide access to the field's value.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40