casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
UnitDim.h
Go to the documentation of this file.
00001 //# UnitDim.h: defines the (private) class describing basic SI dimensions
00002 //# Copyright (C) 1994,1995,1996,1997,1999,2000,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: UnitDim.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef CASA_UNITDIM_H
00029 #define CASA_UNITDIM_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/iosfwd.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward Declarations
00039 class String;
00040 class UnitVal;
00041 class UnitMap;
00042 
00043 // 
00044 // <summary>
00045 // describes a unit in basic SI unit dimensions
00046 // </summary>
00047 
00048 // <use visibility=local>
00049 
00050 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tUnit">
00051 //
00052 // <prerequisite>
00053 // You should have at least a preliminary understanding of these classes:
00054 //   <li> <linkto class=Unit>Unit</linkto>
00055 // </prerequisite>
00056 //
00057 // <etymology>
00058 // Based on Unit and the Dimension of a unit in SI defining units
00059 // </etymology>
00060 //
00061 // <synopsis> 
00062 // Physical units are strings consisting of one or more names of known
00063 // basic units, separated by '.' or ' ' (for multiplication) or '/' (for
00064 // division). Each name can optionally be preceded by a standard decimal 
00065 // prefix, and/or followed by an (optionally signed) exponent.
00066 // Example:
00067 //      km/s/(Mpc.s)2  is identical to km.s-1.Mpc-2.s-2
00068 //
00069 // See the <linkto class=Unit>Unit</linkto> for more details.
00070 //
00071 // The UnitDim class is a private class for use by the Unit classes. It
00072 // contains the dimensions in the 9 basic defining SI units of a unit.
00073 // </synopsis> 
00074 //
00075 // <example>
00076 // </example>
00077 //
00078 // <motivation>
00079 // The UnitDim class has been separated to keep the interface between a
00080 // complex unit description string and the basic SI units clean.
00081 // </motivation>
00082 //
00083 // <todo asof="941110">
00084 //   <li> Some inlining (did not work first go)
00085 // </todo>
00086 
00087 class UnitDim {
00088 
00089 //# Friends
00090     friend class UnitVal;
00091     friend class UnitMap;
00092 // Output the SI dimensions (e.g. 'km/s/g' as 'm kg-1 s-1')
00093     friend ostream& operator<<(ostream &os, const UnitDim &du);
00094 
00095 public:
00096 //# Enumerations
00097 // Enumeration of the order and number of the defining SI units.
00098 // If order or contents changed, change also in dimName() and dimFull().
00099     enum Dim {Dm=0, Dkg, Ds, DA, DK, Dcd, Dmol, Drad, Dsr, Dnon, Dnumber};
00100 // Constants
00101 // Number of Longs to cater for 9 bytes.
00102 #define UNITDIM_DLNUMBER 3
00103 
00104 // Destructor
00105     ~UnitDim();
00106 protected:
00107     void init( );
00108     void init(Int pos);
00109 
00110 private:
00111 //# Constructors
00112 // Construct a unit with zero dimension in all SI units
00113     UnitDim() { init( ); }
00114 
00115 // Copy constructor
00116     UnitDim(const UnitDim &other);
00117 
00118 // Construct a unit dimension with a one in the indicated position (as
00119 // Dim enumerator) and zeroes in all other units
00120     UnitDim(Int pos) { init(pos); }
00121 
00122 //# Operators
00123 // Assignment (copy semantics)
00124     UnitDim &operator=(const UnitDim &other);
00125 // Operators to combine unit dimensions
00126 // <group name="combine">
00127 // Multiplication adds the unit dimensions of all SI units
00128     UnitDim &operator*=(const UnitDim &other);
00129     UnitDim operator*(const UnitDim &other) const;
00130 
00131 // Division subtracts the unit dimensions of all SI units
00132     UnitDim &operator/=(const UnitDim &other);
00133     UnitDim operator/(const UnitDim &other) const;
00134 // </group>
00135 // Compare dimension of units
00136 // <group name="compare">
00137 // Compare for equal dimensions
00138     Bool operator==(const UnitDim &other) const;
00139 // Compare for unequal dimensions
00140     Bool operator!=(const UnitDim &other) const;
00141 // </group>
00142 
00143 //# General Member Functions
00144 // Raise all SI defining units to an integer power
00145     UnitDim pow(Int p);
00146 
00147 // Get the tag for specified dimension
00148   static const String& dimName(uInt which);
00149 
00150 // Get the full name for the specified dimension
00151   static const String& dimFull(uInt which);
00152 
00153 //# Data Members
00154 // 1-byte vector to contain the dimensions of the defining SI units
00155 // (using same storage as Long vector for speed reasons)
00156     Long unitLong[UNITDIM_DLNUMBER];
00157     Char *unitDim;
00158 
00159 };
00160 
00161 
00162 //# Inline Implementations
00163 
00164 //# Global definitions
00165 // Output
00166     ostream& operator<<(ostream &os, const UnitDim &du);
00167 
00168 
00169 } //# NAMESPACE CASA - END
00170 
00171 #endif