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
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/iosfwd.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36//# Forward Declarations
37class String;
38class UnitVal;
39class UnitMap;
40
41//
42// <summary>
43// describes a unit in basic SI unit dimensions
44// </summary>
45
46// <use visibility=local>
47
48// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tUnit">
49//
50// <prerequisite>
51// You should have at least a preliminary understanding of these classes:
52// <li> <linkto class=Unit>Unit</linkto>
53// </prerequisite>
54//
55// <etymology>
56// Based on Unit and the Dimension of a unit in SI defining units
57// </etymology>
58//
59// <synopsis>
60// Physical units are strings consisting of one or more names of known
61// basic units, separated by '.' or ' ' (for multiplication) or '/' (for
62// division). Each name can optionally be preceded by a standard decimal
63// prefix, and/or followed by an (optionally signed) exponent.
64// Example:
65// km/s/(Mpc.s)2 is identical to km.s-1.Mpc-2.s-2
66//
67// See the <linkto class=Unit>Unit</linkto> for more details.
68//
69// The UnitDim class is a private class for use by the Unit classes. It
70// contains the dimensions in the 9 basic defining SI units of a unit.
71// </synopsis>
72//
73// <example>
74// </example>
75//
76// <motivation>
77// The UnitDim class has been separated to keep the interface between a
78// complex unit description string and the basic SI units clean.
79// </motivation>
80//
81// <todo asof="941110">
82// <li> Some inlining (did not work first go)
83// </todo>
84
85class UnitDim {
86
87//# Friends
88 friend class UnitVal;
89 friend class UnitMap;
90// Output the SI dimensions (e.g. 'km/s/g' as 'm kg-1 s-1')
91 friend ostream& operator<<(ostream &os, const UnitDim &du);
92
93public:
94//# Enumerations
95// Enumeration of the order and number of the defining SI units.
96// If order or contents changed, change also in dimName() and dimFull().
97 enum Dim {Dm=0, Dkg, Ds, DA, DK, Dcd, Dmol, Drad, Dsr, Dnon, Dnumber};
98// Constants
99// Number of Longs to cater for 9 bytes.
100#define UNITDIM_DLNUMBER 3
101
102// Destructor
104protected:
105 void init( );
106 void init(Int pos);
107
108private:
109//# Constructors
110// Construct a unit with zero dimension in all SI units
111 UnitDim() { init( ); }
112
113// Copy constructor
114 UnitDim(const UnitDim &other);
115
116// Construct a unit dimension with a one in the indicated position (as
117// Dim enumerator) and zeroes in all other units
118 UnitDim(Int pos) { init(pos); }
119
120//# Operators
121// Assignment (copy semantics)
122 UnitDim &operator=(const UnitDim &other);
123// Operators to combine unit dimensions
124// <group name="combine">
125// Multiplication adds the unit dimensions of all SI units
126 UnitDim &operator*=(const UnitDim &other);
127 UnitDim operator*(const UnitDim &other) const;
129// Division subtracts the unit dimensions of all SI units
130 UnitDim &operator/=(const UnitDim &other);
131 UnitDim operator/(const UnitDim &other) const;
132// </group>
133// Compare dimension of units
134// <group name="compare">
135// Compare for equal dimensions
136 Bool operator==(const UnitDim &other) const;
137// Compare for unequal dimensions
138 Bool operator!=(const UnitDim &other) const;
139// </group>
140
141//# General Member Functions
142// Raise all SI defining units to an integer power
144
145// Get the tag for specified dimension
146 static const String& dimName(uInt which);
147
148// Get the full name for the specified dimension
149 static const String& dimFull(uInt which);
150
151//# Data Members
152// 1-byte vector to contain the dimensions of the defining SI units
153// (using same storage as Long vector for speed reasons)
155 signed char *unitDim;
156
157};
158
159
160//# Inline Implementations
161
162//# Global definitions
163// Output
164 ostream& operator<<(ostream &os, const UnitDim &du);
165
166
167} //# NAMESPACE CASACORE - END
168
169#endif
#define UNITDIM_DLNUMBER
Constants Number of Longs to cater for 9 bytes.
Definition UnitDim.h:100
String: the storage and methods of handling collections of characters.
Definition String.h:223
UnitDim()
Construct a unit with zero dimension in all SI units.
Definition UnitDim.h:111
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:118
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:155
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.
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:154
UnitDim operator*(const UnitDim &other) const
Dim
Enumeration of the order and number of the defining SI units.
Definition UnitDim.h:97
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
UnitDim operator/(const UnitDim &other) const
this file contains all the compiler specific defines
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
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40