casa
$Rev:20696$
|
00001 //# Template.h: Canonicalise, format etc. aips++ template definitions 00002 //# Copyright (C) 2001,2002,2004,2005 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This program is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU General Public License as published by the Free 00007 //# Software Foundation; either version 2 of the License, or (at your option) 00008 //# any later version. 00009 //# 00010 //# This program 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 General Public License for 00013 //# more details. 00014 //# 00015 //# You should have received a copy of the GNU General Public License along 00016 //# with this program; if not, write to the Free Software Foundation, Inc., 00017 //# 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 //# $Id: Template.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00027 00028 #ifndef CASA_TEMPLATE_H 00029 #define CASA_TEMPLATE_H 00030 00031 //# Includes 00032 #include <casa/aips.h> 00033 #include <casa/Containers/Block.h> 00034 #include <casa/BasicSL/String.h> 00035 #include <casa/iosfwd.h> 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 00039 //# Forward declarations 00040 class Regex; 00041 template <class T> class Vector; 00042 00043 // <summary> 00044 // Canonicalise, format and other actions on aips++ template definitions 00045 // </summary> 00046 00047 // <use visibility=local> 00048 00049 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tSpectralFit" demos=""> 00050 // </reviewed> 00051 00052 // <prerequisite> 00053 // <li> Knowledge about the aips++ DYO template system 00054 // </prerequisite> 00055 00056 // <synopsis> 00057 // A set of methods on template repository files and on template definitions to be 00058 // used in the reident, used, unused and duplicates programs (see 00059 // <a href="../../../reference/System?System.html">Sytem manual</a> 00060 // for details. <br /br> 00061 // Methods exist to read templates, to canonicalise them for comparison and 00062 // search functions and to format them for output. 00063 // </synopsis> 00064 // 00065 // <motivation> 00066 // To make template formatting identical across formatting/testing programs. 00067 // </motivation> 00068 // 00069 // <todo asof="2001/03/20"> 00070 // <li> nothing I know 00071 // </todo> 00072 00073 class Template { 00074 public: 00075 00076 //# Constructors 00077 // Default constructor. Need to read data into it 00078 Template(); 00079 // Create from the file names given 00080 explicit Template(const Vector<String> &files); 00081 // Create from the file name given 00082 explicit Template(const String &filename); 00083 00084 // Destructor 00085 ~Template(); 00086 00087 // Operators 00088 const String &operator[](uInt n) { return output_p[n]; } 00089 00090 //# Member functions 00091 // Clear the object for a re-use. 00092 void reset(); 00093 // Read the templates file or files into the class. Multiple reading is additive. 00094 // Errors are reported to cerr, and commented out in the file. 00095 // <group> 00096 void read(const Vector<String> &files); 00097 void read(const String &filename); 00098 // </group> 00099 // Get the number of template entries 00100 uInt getCount() const { return count_p; }; 00101 // Get the number of template definition lines found 00102 uInt getTDCount() const { return tdcount_p; }; 00103 // Get the number of templates found after all processing 00104 uInt getTCount() const { return tcount_p; }; 00105 // Get the number of duplicates found 00106 uInt getDCount() { return dcount_p; }; 00107 // Get the various template definition information fields. 00108 // Meant for testing and special projects only. 00109 // <group> 00110 const String &getTDFlist(uInt n) { return tdflist_p[n]; }; 00111 const String &getTDlist(uInt n) { return tdlist_p[n]; }; 00112 const uInt &getTDfile(uInt n) { return tdfile_p[n]; }; 00113 const uInt &getTDline(uInt n) { return tdline_p[n]; }; 00114 const String &getTDname(uInt n) { return tdname_p[n]; }; 00115 // </group> 00116 00117 // Canonicalise the template entries in the object. If switch True, do only 00118 // the templates entry for duplication 00119 void canonical(const Bool tmplonly=False); 00120 // Split the entries in number, name id, rest 00121 void splitName(); 00122 // Sort the data on name and number and fill in missing number. If switch 00123 // is True, renumber all template entries in sequence. 00124 void sortName(const Bool renumber=False); 00125 // Write the data formatted to the specified file. Notify errors and warnings 00126 // by writing to <src>cerr</src>. If <src>warn</src> is False, some warnings will be 00127 // compressed into a general warning. 00128 void writeOut(ostream &os, const Bool warn=False); 00129 // Write the duplicate list; the userFile gets ***; isSys gives the system switch 00130 void writeDup(ostream &os, const String &userFile, Bool isSys=False); 00131 00132 private: 00133 //# Data 00134 // Each element is a template entry on a single line 00135 Block<String> output_p; 00136 // Count the lines 00137 uInt count_p; 00138 // Count the templates 00139 uInt tcount_p; 00140 // Record comment lines 00141 Block<String> comout_p; 00142 // And where they originated 00143 Block<Int> comptr_p; 00144 // And count the comment lines 00145 uInt ccount_p; 00146 // Indicate data split 00147 Bool isSplit_p; 00148 // Count the duplicates 00149 uInt dcount_p; 00150 // Data split of number string (or empty/spaces) 00151 Block<String> nstring_p; 00152 // Data split all text 00153 Block<String> allstring_p; 00154 // Data split name string (first include file) 00155 Block<String> namstring_p; 00156 // Data split numeric number 00157 Block<uInt> nval_p; 00158 00159 // List of files used 00160 Block<String> tdflist_p; 00161 // Number of template definitions extracted from input 00162 uInt tdcount_p; 00163 // List of template definitions 00164 Block<String> tdlist_p; 00165 // Pointers to in which file in list 00166 Block<uInt> tdfile_p; 00167 // Line number in file at which template found 00168 Block<uInt> tdline_p; 00169 // List of comparison names 00170 Block<String> tdname_p; 00171 00172 //# Constructors 00173 // Copy constructor (not implemented) 00174 Template(const Template &other); 00175 //# Operators 00176 // Assignment (not implemented) 00177 Template &operator=(const Template &other); 00178 //# Member functions 00179 // Save comment 00180 void setComment(const String &txt, const Bool atstart=False); 00181 // Save a line 00182 void setOutput(const String &txt); 00183 00184 //# Static conversion data 00185 // Patterns to analyse an input line 00186 static const Regex spaces; 00187 static const Regex comment; 00188 static const Regex ifRE; 00189 static const Regex endifRE; 00190 static const Regex elseRE; 00191 static const Regex templateRE; 00192 static const Regex contRE; 00193 static const Regex fileRE; 00194 static const Regex typedefRE; 00195 static const Regex auxtemplRE; 00196 static const Regex namespaceRE; 00197 00198 // Simple pattern and replacements to make canonical templates files 00199 static const uInt Ncanon = 52; 00200 static const Regex PATcanon[Ncanon]; 00201 static const String REPcanon[Ncanon]; 00202 00203 // For canonical change: replacement of pattern with pattern 00204 static const uInt Ncanon2 = 15; 00205 static const Regex PATcanon20[Ncanon2]; 00206 static const Regex PATcanon21[Ncanon2]; 00207 static const String REPcanon2[Ncanon2]; 00208 00209 // Make canonical numbers of 4 digits minimum 00210 static const uInt Nnmin = 4; 00211 static const Regex PATnmin[Nnmin]; 00212 static const String REPnmin[Nnmin]; 00213 // Make canonical numbers of 4 digits maximum 00214 static const uInt Nnmax = 1; 00215 static const Regex PATnmax[Nnmax]; 00216 static const Regex REPnmax[Nnmax]; 00217 00218 // Patterns to split off number and name 00219 // Patterns to split off number and name 00220 static const Regex splitnum; 00221 static const Regex splitnam; 00222 00223 // Patterns to check the template line 00224 static const Regex sifRE; 00225 static const Regex stemRE; 00226 static const Regex sconstRE; 00227 static const Regex sretRE1; 00228 static const Regex sretRE2; 00229 static const Regex sretRE3; 00230 static const Regex sretRE4; 00231 static const Regex stypedefRE; 00232 static const Regex sauxtemplRE; 00233 static const Regex snamespaceRE; 00234 00235 // Replacement patterns for ifs in saved line 00236 static const uInt Ninif = 5; 00237 static const String PATinif[Ninif]; 00238 static const String REPinif[Ninif]; 00239 00240 // Tests for finding real templates for duplicate tests 00241 static const Regex classprelude; 00242 static const Regex functionprelude; 00243 static const Regex forwardprelude; 00244 static const Regex funcnameprelude; 00245 static const Regex mylistprelude; 00246 00247 // Data to remove spaces at begin, end, make single, count/remove const 00248 static const Regex leadsp; 00249 static const Regex endsp; 00250 static const Regex mulsp; 00251 static const Regex constsp; 00252 static const String nullsp; 00253 static const String singlesp; 00254 00255 // Patterns to make all typedefs comparisons for duplicates possible 00256 // Note that the first three should be in that position for run-time 00257 // change on some systems. 00258 static const uInt Ntypedef = 23; 00259 static const Regex PATtypedef0[Ntypedef]; 00260 static const Regex PATtypedef1[Ntypedef]; 00261 static String REPtypedef[Ntypedef]; 00262 00263 // Name of repository files 00264 static const String reposName; 00265 00266 }; 00267 00268 00269 } //# NAMESPACE CASA - END 00270 00271 #ifndef CASACORE_NO_AUTO_TEMPLATES 00272 #include <casa/Utilities/Template.tcc> 00273 #endif //# CASACORE_NO_AUTO_TEMPLATES 00274 #endif