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