casacore
Loading...
Searching...
No Matches
RecordTransformable.h
Go to the documentation of this file.
1//# RecordTransformable.h: Interface class for converting to/from records
2//# Copyright (C) 1998,1999,2003
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_RECORDTRANSFORMABLE_H
27#define CASA_RECORDTRANSFORMABLE_H
28
29#include <casacore/casa/aips.h>
30
31namespace casacore { //# NAMESPACE CASACORE - BEGIN
32
33class String;
34class RecordInterface;
35
36// <summary>Interface class for converting to/from records</summary>
37
38// <use visibility=export>
39
40// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tRecordTransformable">
41// </reviewed>
42
43// <prerequisite>
44// <li> <linkto class="RecordInterface">RecordInterface</linkto>
45// </prerequisite>
46//
47// <etymology>
48// This class defines the interface that a class should use if the can be
49// transformed into a record representation.
50// </etymology>
51//
52// <synopsis>
53// This abstract base class is intended to be publicly inherited by classes
54// that contain functions which can represent the object as a record (these
55// functions should be called <src>toRecord</src> and
56// <src>fromRecord</src>). Examples of records are:
57// <ul>
58// <li> <linkto class="Record">Record</linkto>
59// <li> <linkto class="TableRecord">TableRecord</linkto>
60// </ul>
61//
62// This interface defines two functions that convert between a RecordInterface
63// and the class that inherits these functions. These functions are often used
64// to parse input that is beyond the programs control e.g. user input from
65// glish or Table records that may have been generated elsewhere. Hence
66// exceptions should not thrown be thrown by these functions. Instead the
67// function should return False and append an error message to the supplied
68// String when the transformation cannot be accomplished.
69//
70// <note role=warning>
71// Converting to/from a GlishRecord requires an extra step.
72// First a Record should be used which can thereafter be converted to/from
73// a GlishRecord using the appropriate GlishRecord functions.
74// </note>
75// </synopsis>
76//
77// <example>
78// The following example prints out a class using its record representation.
79// This example is in the file tRecordTransformable.cc
80// <srcblock>
81// void printAsRecord(const RecordTransformable & myClass) {
82// String errorMessage;
83// Record rec;
84// if (!myClass.toRecord(errorMessage, rec)) {
85// cout << "Cannot convert class to a Record. The reason is:" << endl;
86// cout << errorMessage << endl;
87// } else {
88// cout << rec.ndefined() << endl;
89// }
90// }
91// </srcblock>
92// </example>
93//
94// <motivation>
95// This class was designed to standardise the function interface for converting
96// between an object and its record representation.
97// </motivation>
98//
99// <todo asof="1998/03/30">
100// <li> Nothing I hope!
101// </todo>
102
104{
105public:
106 // The destructor must be virtual so that the destructor of derived classes
107 // is actually used.
109
110 // Convert the class to an Record representation. The input record may
111 // already contain fields and these fields may be silently overridden. New
112 // fields may be added to the input Record. If the transformation succeeds
113 // then the error String is unchanged and the function returns
114 // True. Otherwise the function returns False and appends an error message to
115 // the supplied String giving the reason why the conversion failed.
116 virtual Bool toRecord(String & error, RecordInterface & outRecord) const = 0;
117
118 // Initialise the class from a Record representation. The input record should
119 // contain the fields that are required by the class. Other fields will be
120 // ignored. If the transformation succeeds then the error String is unchanged
121 // and the function returns True. Otherwise the function returns False and
122 // appends an error message to the supplied String giving the reason why the
123 // conversion failed.
124 virtual Bool fromRecord(String & error, const RecordInterface & inRecord) =0;
125
126 // Initialise the class from a String representation. A string cannot
127 // contain enough information for many objects. Hence the default
128 // implementation of this class returns False, indicating that the class
129 // could not be initialised and an error message is appended to the supplied
130 // string. If the class can be initialised from a string then this function
131 // should be overridden.
132 virtual Bool fromString(String & error, const String & inString);
133
134 // Specify the identification of the record (e.g. 'meas', 'quant'). The
135 // default implementation returns a empty string.
136 virtual const String &ident() const;
137};
138
139
140} //# NAMESPACE CASACORE - END
141
142#endif
virtual Bool fromString(String &error, const String &inString)
Initialise the class from a String representation.
virtual Bool fromRecord(String &error, const RecordInterface &inRecord)=0
Initialise the class from a Record representation.
virtual Bool toRecord(String &error, RecordInterface &outRecord) const =0
Convert the class to an Record representation.
virtual const String & ident() const
Specify the identification of the record (e.g.
virtual ~RecordTransformable()
The destructor must be virtual so that the destructor of derived classes is actually used.
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
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40