casacore
UnitName.h
Go to the documentation of this file.
1 //# UnitName.h: defines a tagged unit definition
2 //# Copyright (C) 1994,1995,1996,1997,1998,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_UNITNAME_H
29 #define CASA_UNITNAME_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/casa/BasicSL/String.h>
35 #include <casacore/casa/Quanta/Unit.h>
36 #include <casacore/casa/Quanta/UnitVal.h>
37 #include <casacore/casa/iosfwd.h>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 //# Forward Declarations
42 
43 //# Constants
44 // <note role=warning>
45 // SUN compiler does not accept non-simple default arguments
46 // </note>
47 static const String EmptyString="";
48 
49 // <summary>
50 // handles physical units
51 // </summary>
52 
53 // <use visibility=export>
54 
55 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tUnit">
56 //
57 // <prerequisite>
58 // You should have at least a preliminary understanding of these classes:
59 // <li> <linkto class=Unit>Unit</linkto>
60 // </prerequisite>
61 //
62 // <etymology>
63 // The class name derives from the basic Unit and the Name giving possibilities
64 // of this class to a newly defined unit tag.
65 // </etymology>
66 //
67 // <synopsis>
68 // Physical units are strings consisting of one or more names of known
69 // basic units, separated by '.' or ' ' (for multiplication) or '/' (for
70 // division). Each name can optionally be preceded by a standard decimal
71 // prefix, and/or followed by an (optionally signed) exponent.
72 //
73 // Example:
74 // km/s/(Mpc.s)2 is identical to km.s-1.Mpc-2.s-2
75 //
76 // See the <linkto class="Unit">Unit</linkto> class for more details.
77 //
78 // The UnitName class defines new basic, tagged units. If, e.g., for one
79 // reason or another you want, in addition to the standard defined SI and
80 // customary units, to define a unit with a name 'KPH' to stand for the
81 // composite SI unit 'km/s', it can be done by creating a UnitName, and
82 // mapping it to the UnitMap lists.
83 // <note role=tip> The UnitMap::putUser can also be used without creating a UnitName
84 // first
85 // </note>
86 // <srcblock>
87 // UnitName myKPH( "KPH", UnitVal(3.6,"km/ks"));
88 // UnitMap::putUser(myKPH);
89 // </srcblock>
90 //
91 // <h3> Constructing a tagged unit definition </h3>
92 // The following constructors are available:
93 // <ol>
94 // <li> UnitName() create unnamed value 1.
95 // <li> UnitName(const UnitName&) copy constructor
96 // <li> UnitName("tag", UnitVal, "full name")
97 // </ol>
98 //
99 // An assignment (copy semantics) is available.
100 //
101 //
102 // <h3> Obtaining information about tagged unit </h3>
103 // The following information can be obatined from a UnitName:
104 // <ol>
105 // <li> UnitVal getVal() const will return the unit definition value
106 // <li> String getName() const will return the unit name
107 // </ol>
108 //
109 //
110 // </synopsis>
111 //
112 // <example>
113 // To obtain the definition of a Jy, you could:
114 // <srcblock>
115 // // Define a UnitVal unit definition
116 // UnitVal mydef;
117 // // And fill it with the appropiate definition
118 // mydef = (UnitMap::getUnit("Jy"))->getVal();
119 // </srcblock>
120 // </example>
121 //
122 //# // <motivation>
123 //# // </motivation>
124 //
125 // <todo asof="941110">
126 // <li> Some inlining (did not work first go)
127 // </todo>
128 
129 class UnitName {
130 //# friends
131 // Output the unit tag, description and its definition
132  friend ostream& operator<< (ostream &os, const UnitName &name);
133 
134 public:
135 //# Constructors
136 // Default constructor
137  UnitName();
138 
139 // Copy constructor
140  UnitName(const UnitName &other);
141 
142 // Construct from different parts
143 // <group>
144  UnitName(const String &tag, const UnitVal &kind,
145  const String &name = EmptyString);
146  UnitName(const Unit &tag, const String &name = EmptyString);
147 // </group>
148 
149 
150 // Destructor
151  ~UnitName();
152 
153 //# Operators
154 // Assigment (copy semantics)
155  UnitName &operator=(const UnitName &other);
156 
157 //# General member functions
158 // Get definition value of the unit
159  const UnitVal &getVal() const;
160 
161 // Get the name tag of the defined unit
162  const String &getName() const;
163 
164 // Get the full name of the defined unit
165  const String &getFullName() const;
166 
167 private:
168 //# Data members
169 // Value of defined unit
171 
172 // Name tag of unit
174 
175 // Full name and description of unit
177 
178 };
179 
180 //# Inline Implementations
181 
182 
183 } //# NAMESPACE CASACORE - END
184 
185 #endif
String basicName
Full name and description of unit.
Definition: UnitName.h:176
const String & getName() const
Get the name tag of the defined unit.
UnitName & operator=(const UnitName &other)
Assigment (copy semantics)
describes any valid unit as a factor and a dimenion of SI units
Definition: UnitVal.h:166
UnitVal basicKind
Value of defined unit.
Definition: UnitName.h:170
String basicTag
Name tag of unit.
Definition: UnitName.h:173
const UnitVal & getVal() const
Get definition value of the unit.
handles physical units
Definition: UnitName.h:129
defines physical units
Definition: Unit.h:189
friend ostream & operator<<(ostream &os, const UnitName &name)
Output the unit tag, description and its definition.
~UnitName()
Destructor.
static const String EmptyString
Warning: SUN compiler does not accept non-simple default arguments
Definition: UnitName.h:47
const String & getFullName() const
Get the full name of the defined unit.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
this file contains all the compiler specific defines
Definition: mainpage.dox:28
UnitName()
Default constructor.