casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: 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 //#
27 //# $Id$
28 
29 
30 #ifndef CASA_RECORDFIELDID_H
31 #define CASA_RECORDFIELDID_H
32 
33 //# Includes
34 #include <casacore/casa/aips.h>
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 //# Forward Declarations
40 class RecordInterface;
41 
42 
43 // <summary>
44 // The identification of a record field.
45 // </summary>
46 
47 // <use visibility=export>
48 // <reviewed reviewer="Mark Wieringa" date="1996/04/15" tests="tRecord">
49 // </reviewed>
50 
51 // <prerequisite>
52 // <li> <linkto class="RecordInterface">RecordInterface</linkto>.
53 // </prerequisite>
54 
55 // <etymology>
56 // RecordFieldId gives the identification of a field in a record.
57 // </etymology>
58 
59 // <synopsis>
60 // This class provides the user to identify a field in a record.
61 // Identification can be done by means of the field name or by means
62 // of its field number.
63 // <br>For the programmer the most convenient way is probably the name,
64 // because that is the natural identification.
65 // However, identification by means of field number is much faster
66 // and could be used when it is known.
67 // </synopsis>
68 
69 // <example>
70 // <srcblock>
71 // void someFunc (const Record& record)
72 // {
73 // float value1 = record.asfloat ("name"); // identify by name
74 // float value2 = record.asfloat (0); // identify by number
75 // }
76 // </srcBlock>
77 // </example>
78 
79 // <motivation>
80 // This class makes it possible that many functions in Record classes
81 // have to be defined only once. The constructors of RecordFieldId
82 // make it possible that a number and a string are automatically
83 // converted, so the user does not have to instantiate a RecordFieldId
84 // object explicitly.
85 // </motivation>
86 
87 //# <todo asof="1996/03/12">
88 //# </todo>
89 
90 
92 {
93 public:
94  // Construct it from a field number.
96 
97  // Construct it from a field name.
98  // <group>
99  RecordFieldId (const String& name);
100  RecordFieldId (const std::string& name);
101  RecordFieldId (const Char* name);
102  // </group>
103 
104  // Get the field number.
105  Int fieldNumber() const;
106 
107  // Get the field name.
108  const String& fieldName() const;
109 
110  // Is the id given by name?
111  Bool byName() const;
112 
113 private:
117 };
118 
119 
120 
121 inline RecordFieldId::RecordFieldId (Int fieldNumber)
122 : byName_p (False),
123  number_p (fieldNumber)
124 {}
125 
126 inline RecordFieldId::RecordFieldId (const String& fieldName)
127 : byName_p (True),
128  number_p (-1),
129  name_p (fieldName)
130 {}
131 
132 inline RecordFieldId::RecordFieldId (const std::string& fieldName)
133 : byName_p (True),
134  number_p (-1),
135  name_p (fieldName)
136 {}
137 
138 inline RecordFieldId::RecordFieldId (const Char* fieldName)
139 : byName_p (True),
140  number_p (-1),
141  name_p (fieldName)
142 {}
143 
145 {
146  return number_p;
147 }
148 
149 inline const String& RecordFieldId::fieldName() const
150 {
151  return name_p;
152 }
153 
155 {
156  return byName_p;
157 }
158 
159 
160 
161 } //# NAMESPACE CASACORE - END
162 
163 #endif
int Int
Definition: aipstype.h:50
Bool byName() const
Is the id given by name?
char Char
Definition: aipstype.h:46
const String & fieldName() const
Get the field name.
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
The identification of a record field.
Definition: RecordFieldId.h:91
Int fieldNumber() const
Get the field number.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
RecordFieldId(Int fieldNumber)
Construct it from a field number.
const Bool False
Definition: aipstype.h:44
String: the storage and methods of handling collections of characters.
Definition: String.h:223
const Bool True
Definition: aipstype.h:43
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42