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