casacore
Loading...
Searching...
No Matches
RecordFieldId.h
Go to the documentation of this file.
1//# RecordFieldId.h: The identification of a record field
2//# Copyright (C) 1995,1996
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
27#ifndef CASA_RECORDFIELDID_H
28#define CASA_RECORDFIELDID_H
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/BasicSL/String.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36//# Forward Declarations
37class RecordInterface;
38
39
40// <summary>
41// The identification of a record field.
42// </summary>
43
44// <use visibility=export>
45// <reviewed reviewer="Mark Wieringa" date="1996/04/15" tests="tRecord">
46// </reviewed>
47
48// <prerequisite>
49// <li> <linkto class="RecordInterface">RecordInterface</linkto>.
50// </prerequisite>
51
52// <etymology>
53// RecordFieldId gives the identification of a field in a record.
54// </etymology>
55
56// <synopsis>
57// This class provides the user to identify a field in a record.
58// Identification can be done by means of the field name or by means
59// of its field number.
60// <br>For the programmer the most convenient way is probably the name,
61// because that is the natural identification.
62// However, identification by means of field number is much faster
63// and could be used when it is known.
64// </synopsis>
65
66// <example>
67// <srcblock>
68// void someFunc (const Record& record)
69// {
70// float value1 = record.asfloat ("name"); // identify by name
71// float value2 = record.asfloat (0); // identify by number
72// }
73// </srcBlock>
74// </example>
75
76// <motivation>
77// This class makes it possible that many functions in Record classes
78// have to be defined only once. The constructors of RecordFieldId
79// make it possible that a number and a string are automatically
80// converted, so the user does not have to instantiate a RecordFieldId
81// object explicitly.
82// </motivation>
83
84//# <todo asof="1996/03/12">
85//# </todo>
86
87
89{
90public:
91 // Construct it from a field number.
93
94 // Construct it from a field name.
95 // <group>
96 RecordFieldId (const String& name);
97 RecordFieldId (const std::string& name);
98 RecordFieldId (const Char* name);
99 // </group>
100
101 // Get the field number.
102 Int fieldNumber() const;
103
104 // Get the field name.
105 const String& fieldName() const;
106
107 // Is the id given by name?
108 Bool byName() const;
109
110private:
114};
115
116
117
119: byName_p (False),
120 number_p (fieldNumber)
121{}
122
123inline RecordFieldId::RecordFieldId (const String& fieldName)
124: byName_p (True),
125 number_p (-1),
126 name_p (fieldName)
127{}
128
129inline RecordFieldId::RecordFieldId (const std::string& fieldName)
130: byName_p (True),
131 number_p (-1),
132 name_p (fieldName)
133{}
134
135inline RecordFieldId::RecordFieldId (const Char* fieldName)
136: byName_p (True),
137 number_p (-1),
138 name_p (fieldName)
139{}
140
142{
143 return number_p;
144}
145
146inline const String& RecordFieldId::fieldName() const
147{
148 return name_p;
149}
150
152{
153 return byName_p;
154}
155
156
157
158} //# NAMESPACE CASACORE - END
159
160#endif
Int fieldNumber() const
Get the field number.
const String & fieldName() const
Get the field name.
RecordFieldId(Int fieldNumber)
Construct it from a field number.
Bool byName() const
Is the id given by name?
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
const Bool False
Definition aipstype.h:42
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
char Char
Definition aipstype.h:44