casa
$Rev:20696$
|
00001 //# RecordTransformable.h: Interface class for converting to/from records 00002 //# Copyright (C) 1998,1999,2003 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id: RecordTransformable.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00028 00029 #ifndef CASA_RECORDTRANSFORMABLE_H 00030 #define CASA_RECORDTRANSFORMABLE_H 00031 00032 #include <casa/aips.h> 00033 00034 namespace casa { //# NAMESPACE CASA - BEGIN 00035 00036 class String; 00037 class RecordInterface; 00038 00039 // <summary>Interface class for converting to/from records</summary> 00040 00041 // <use visibility=export> 00042 00043 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tRecordTransformable"> 00044 // </reviewed> 00045 00046 // <prerequisite> 00047 // <li> <linkto class="RecordInterface">RecordInterface</linkto> 00048 // </prerequisite> 00049 // 00050 // <etymology> 00051 // This class defines the interface that a class should use if the can be 00052 // transformed into a record representation. 00053 // </etymology> 00054 // 00055 // <synopsis> 00056 // This abstract base class is intended to be publicly inherited by classes 00057 // that contain functions which can represent the object as a record (these 00058 // functions should be called <src>toRecord</src> and 00059 // <src>fromRecord</src>). Examples of records are: 00060 // <ul> 00061 // <li> <linkto class="Record">Record</linkto> 00062 // <li> <linkto class="TableRecord">TableRecord</linkto> 00063 // </ul> 00064 // 00065 // This interface defines two functions that convert between a RecordInterface 00066 // and the class that inherits these functions. These functions are often used 00067 // to parse input that is beyond the programs control e.g. user input from 00068 // glish or Table records that may have been generated elsewhere. Hence 00069 // exceptions should not thrown be thrown by these functions. Instead the 00070 // function should return False and append an error message to the supplied 00071 // String when the transformation cannot be accomplished. 00072 // 00073 // <note role=warning> 00074 // Converting to/from a GlishRecord requires an extra step. 00075 // First a Record should be used which can thereafter be converted to/from 00076 // a GlishRecord using the appropriate GlishRecord functions. 00077 // </note> 00078 // </synopsis> 00079 // 00080 // <example> 00081 // The following example prints out a class using its record representation. 00082 // This example is in the file tRecordTransformable.cc 00083 // <srcblock> 00084 // void printAsRecord(const RecordTransformable & myClass) { 00085 // String errorMessage; 00086 // Record rec; 00087 // if (!myClass.toRecord(errorMessage, rec)) { 00088 // cout << "Cannot convert class to a Record. The reason is:" << endl; 00089 // cout << errorMessage << endl; 00090 // } else { 00091 // cout << rec.ndefined() << endl; 00092 // } 00093 // } 00094 // </srcblock> 00095 // </example> 00096 // 00097 // <motivation> 00098 // This class was designed to standardise the function interface for converting 00099 // between an object and its record representation. 00100 // </motivation> 00101 // 00102 // <todo asof="1998/03/30"> 00103 // <li> Nothing I hope! 00104 // </todo> 00105 00106 class RecordTransformable 00107 { 00108 public: 00109 // The destructor must be virtual so that the destructor of derived classes 00110 // is actually used. 00111 virtual ~RecordTransformable(); 00112 00113 // Convert the class to an Record representation. The input record may 00114 // already contain fields and these fields may be silently overridden. New 00115 // fields may be added to the input Record. If the transformation succeeds 00116 // then the error String is unchanged and the function returns 00117 // True. Otherwise the function returns False and appends an error message to 00118 // the supplied String giving the reason why the conversion failed. 00119 virtual Bool toRecord(String & error, RecordInterface & outRecord) const = 0; 00120 00121 // Initialise the class from a Record representation. The input record should 00122 // contain the fields that are required by the class. Other fields will be 00123 // ignored. If the transformation succeeds then the error String is unchanged 00124 // and the function returns True. Otherwise the function returns False and 00125 // appends an error message to the supplied String giving the reason why the 00126 // conversion failed. 00127 virtual Bool fromRecord(String & error, const RecordInterface & inRecord) =0; 00128 00129 // Initialise the class from a String representation. A string cannot 00130 // contain enough information for many objects. Hence the default 00131 // implementation of this class returns False, indicating that the class 00132 // could not be initialised and an error message is appended to the supplied 00133 // string. If the class can be initialised from a string then this function 00134 // should be overridden. 00135 virtual Bool fromString(String & error, const String & inString); 00136 00137 // Specify the identification of the record (e.g. 'meas', 'quant'). The 00138 // default implementation returns a empty string. 00139 virtual const String &ident() const; 00140 }; 00141 00142 00143 } //# NAMESPACE CASA - END 00144 00145 #endif