casacore
Template.h
Go to the documentation of this file.
1 //# Template.h: Canonicalise, format etc. Casacore template definitions
2 //# Copyright (C) 2001,2002,2004,2005
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This program is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU General Public License as published by the Free
7 //# Software Foundation; either version 2 of the License, or (at your option)
8 //# any later version.
9 //#
10 //# This program 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 General Public License for
13 //# more details.
14 //#
15 //# You should have received a copy of the GNU General Public License along
16 //# with this program; if not, write to the Free Software Foundation, Inc.,
17 //# 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 //# $Id$
27 
28 #ifndef CASA_TEMPLATE_H
29 #define CASA_TEMPLATE_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/casa/Containers/Block.h>
34 #include <casacore/casa/BasicSL/String.h>
35 #include <casacore/casa/iosfwd.h>
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 //# Forward declarations
40 class Regex;
41 template <class T> class Vector;
42 
43 // <summary>
44 // Canonicalise, format and other actions on Casacore template definitions
45 // </summary>
46 
47 // <use visibility=local>
48 
49 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tSpectralFit" demos="">
50 // </reviewed>
51 
52 // <prerequisite>
53 // <li> Knowledge about the Casacore DYO template system
54 // </prerequisite>
55 
56 // <synopsis>
57 // A set of methods on template repository files and on template definitions to be
58 // used in the reident, used, unused and duplicates programs (see
59 // <a href="../../../reference/System?System.html">Sytem manual</a>
60 // for details. <br /br>
61 // Methods exist to read templates, to canonicalise them for comparison and
62 // search functions and to format them for output.
63 // </synopsis>
64 //
65 // <motivation>
66 // To make template formatting identical across formatting/testing programs.
67 // </motivation>
68 //
69 // <todo asof="2001/03/20">
70 // <li> nothing I know
71 // </todo>
72 
73 class Template {
74  public:
75 
76  //# Constructors
77  // Default constructor. Need to read data into it
79  // Create from the file names given
80  explicit Template(const Vector<String> &files);
81  // Create from the file name given
82  explicit Template(const String &filename);
83 
84  // Destructor
86 
87  // Operators
88  const String &operator[](uInt n) { return output_p[n]; }
89 
90  //# Member functions
91  // Clear the object for a re-use.
92  void reset();
93  // Read the templates file or files into the class. Multiple reading is additive.
94  // Errors are reported to cerr, and commented out in the file.
95  // <group>
96  void read(const Vector<String> &files);
97  void read(const String &filename);
98  // </group>
99  // Get the number of template entries
100  uInt getCount() const { return count_p; };
101  // Get the number of template definition lines found
102  uInt getTDCount() const { return tdcount_p; };
103  // Get the number of templates found after all processing
104  uInt getTCount() const { return tcount_p; };
105  // Get the number of duplicates found
106  uInt getDCount() { return dcount_p; };
107  // Get the various template definition information fields.
108  // Meant for testing and special projects only.
109  // <group>
110  const String &getTDFlist(uInt n) { return tdflist_p[n]; };
111  const String &getTDlist(uInt n) { return tdlist_p[n]; };
112  const uInt &getTDfile(uInt n) { return tdfile_p[n]; };
113  const uInt &getTDline(uInt n) { return tdline_p[n]; };
114  const String &getTDname(uInt n) { return tdname_p[n]; };
115  // </group>
116 
117  // Canonicalise the template entries in the object. If switch True, do only
118  // the templates entry for duplication
119  void canonical(const Bool tmplonly=False);
120  // Split the entries in number, name id, rest
121  void splitName();
122  // Sort the data on name and number and fill in missing number. If switch
123  // is True, renumber all template entries in sequence.
124  void sortName(const Bool renumber=False);
125  // Write the data formatted to the specified file. Notify errors and warnings
126  // by writing to <src>cerr</src>. If <src>warn</src> is False, some warnings will be
127  // compressed into a general warning.
128  void writeOut(ostream &os, const Bool warn=False);
129  // Write the duplicate list; the userFile gets ***; isSys gives the system switch
130  void writeDup(ostream &os, const String &userFile, Bool isSys=False);
131 
132  private:
133  //# Data
134  // Each element is a template entry on a single line
136  // Count the lines
138  // Count the templates
140  // Record comment lines
142  // And where they originated
144  // And count the comment lines
146  // Indicate data split
148  // Count the duplicates
150  // Data split of number string (or empty/spaces)
152  // Data split all text
154  // Data split name string (first include file)
156  // Data split numeric number
158 
159  // List of files used
161  // Number of template definitions extracted from input
163  // List of template definitions
165  // Pointers to in which file in list
167  // Line number in file at which template found
169  // List of comparison names
171 
172  //# Constructors
173  // Copy constructor (not implemented)
174  Template(const Template &other);
175  //# Operators
176  // Assignment (not implemented)
177  Template &operator=(const Template &other);
178  //# Member functions
179  // Save comment
180  void setComment(const String &txt, const Bool atstart=False);
181  // Save a line
182  void setOutput(const String &txt);
183 
184  //# Static conversion data
185  // Patterns to analyse an input line
186  static const Regex spaces;
187  static const Regex comment;
188  static const Regex ifRE;
189  static const Regex endifRE;
190  static const Regex elseRE;
191  static const Regex templateRE;
192  static const Regex contRE;
193  static const Regex fileRE;
194  static const Regex typedefRE;
195  static const Regex auxtemplRE;
196  static const Regex namespaceRE;
197 
198  // Simple pattern and replacements to make canonical templates files
199  static const uInt Ncanon = 52;
200  static const Regex PATcanon[Ncanon];
201  static const String REPcanon[Ncanon];
202 
203  // For canonical change: replacement of pattern with pattern
204  static const uInt Ncanon2 = 15;
205  static const Regex PATcanon20[Ncanon2];
206  static const Regex PATcanon21[Ncanon2];
207  static const String REPcanon2[Ncanon2];
208 
209  // Make canonical numbers of 4 digits minimum
210  static const uInt Nnmin = 4;
211  static const Regex PATnmin[Nnmin];
212  static const String REPnmin[Nnmin];
213  // Make canonical numbers of 4 digits maximum
214  static const uInt Nnmax = 1;
215  static const Regex PATnmax[Nnmax];
216  static const Regex REPnmax[Nnmax];
217 
218  // Patterns to split off number and name
219  // Patterns to split off number and name
220  static const Regex splitnum;
221  static const Regex splitnam;
222 
223  // Patterns to check the template line
224  static const Regex sifRE;
225  static const Regex stemRE;
226  static const Regex sconstRE;
227  static const Regex sretRE1;
228  static const Regex sretRE2;
229  static const Regex sretRE3;
230  static const Regex sretRE4;
231  static const Regex stypedefRE;
232  static const Regex sauxtemplRE;
233  static const Regex snamespaceRE;
234 
235  // Replacement patterns for ifs in saved line
236  static const uInt Ninif = 5;
237  static const String PATinif[Ninif];
238  static const String REPinif[Ninif];
239 
240  // Tests for finding real templates for duplicate tests
241  static const Regex classprelude;
242  static const Regex functionprelude;
243  static const Regex forwardprelude;
244  static const Regex funcnameprelude;
245  static const Regex mylistprelude;
246 
247  // Data to remove spaces at begin, end, make single, count/remove const
248  static const Regex leadsp;
249  static const Regex endsp;
250  static const Regex mulsp;
251  static const Regex constsp;
252  static const String nullsp;
253  static const String singlesp;
254 
255  // Patterns to make all typedefs comparisons for duplicates possible
256  // Note that the first three should be in that position for run-time
257  // change on some systems.
258  static const uInt Ntypedef = 23;
259  static const Regex PATtypedef0[Ntypedef];
260  static const Regex PATtypedef1[Ntypedef];
262 
263  // Name of repository files
264  static const String reposName;
265 
266 };
267 
268 
269 } //# NAMESPACE CASACORE - END
270 
271 #ifndef CASACORE_NO_AUTO_TEMPLATES
272 #include <casacore/casa/Utilities/Template.tcc>
273 #endif //# CASACORE_NO_AUTO_TEMPLATES
274 #endif
simple 1-D array
Definition: Block.h:200
String: the storage and methods of handling collections of characters.
Definition: String.h:225
static const Regex elseRE
Definition: Template.h:190
static const Regex PATnmax[Nnmax]
Definition: Template.h:215
static const Regex comment
Definition: Template.h:187
const String & getTDname(uInt n)
Definition: Template.h:114
static const Regex classprelude
Tests for finding real templates for duplicate tests.
Definition: Template.h:241
static const Regex PATcanon20[Ncanon2]
Definition: Template.h:205
static const Regex namespaceRE
Definition: Template.h:196
uInt dcount_p
Count the duplicates.
Definition: Template.h:149
Block< uInt > nval_p
Data split numeric number.
Definition: Template.h:157
void setComment(const String &txt, const Bool atstart=False)
Save comment.
Block< String > output_p
Each element is a template entry on a single line.
Definition: Template.h:135
static const Regex stemRE
Definition: Template.h:225
static const Regex sauxtemplRE
Definition: Template.h:232
static const uInt Ntypedef
Patterns to make all typedefs comparisons for duplicates possible Note that the first three should be...
Definition: Template.h:258
static const Regex PATtypedef1[Ntypedef]
Definition: Template.h:260
void read(const Vector< String > &files)
Read the templates file or files into the class.
static const String REPnmin[Nnmin]
Definition: Template.h:212
static const Regex templateRE
Definition: Template.h:191
const String & getTDlist(uInt n)
Definition: Template.h:111
uInt count_p
Count the lines.
Definition: Template.h:137
static const uInt Nnmin
Make canonical numbers of 4 digits minimum.
Definition: Template.h:210
static const Regex PATcanon21[Ncanon2]
Definition: Template.h:206
static const String singlesp
Definition: Template.h:253
Block< String > tdname_p
List of comparison names.
Definition: Template.h:170
static const uInt Nnmax
Make canonical numbers of 4 digits maximum.
Definition: Template.h:214
Block< Int > comptr_p
And where they originated.
Definition: Template.h:143
void canonical(const Bool tmplonly=False)
Canonicalise the template entries in the object.
Bool isSplit_p
Indicate data split.
Definition: Template.h:147
void splitName()
Split the entries in number, name id, rest.
void sortName(const Bool renumber=False)
Sort the data on name and number and fill in missing number.
static const Regex sretRE4
Definition: Template.h:230
uInt getTCount() const
Get the number of templates found after all processing.
Definition: Template.h:104
uInt getDCount()
Get the number of duplicates found.
Definition: Template.h:106
void reset()
Clear the object for a re-use.
static const Regex sretRE2
Definition: Template.h:228
void setOutput(const String &txt)
Save a line.
void writeDup(ostream &os, const String &userFile, Bool isSys=False)
Write the duplicate list; the userFile gets ***; isSys gives the system switch.
static const Regex sifRE
Patterns to check the template line.
Definition: Template.h:224
static const String PATinif[Ninif]
Definition: Template.h:237
Block< String > tdlist_p
List of template definitions.
Definition: Template.h:164
static const Regex mulsp
Definition: Template.h:250
static const String REPinif[Ninif]
Definition: Template.h:238
static const Regex PATcanon[Ncanon]
Definition: Template.h:200
Block< String > comout_p
Record comment lines.
Definition: Template.h:141
Block< uInt > tdline_p
Line number in file at which template found.
Definition: Template.h:168
const uInt & getTDline(uInt n)
Definition: Template.h:113
static const Regex endsp
Definition: Template.h:249
uInt ccount_p
And count the comment lines.
Definition: Template.h:145
static const Regex endifRE
Definition: Template.h:189
~Template()
Destructor.
static const Regex contRE
Definition: Template.h:192
Template & operator=(const Template &other)
Assignment (not implemented)
static const Regex leadsp
Data to remove spaces at begin, end, make single, count/remove const.
Definition: Template.h:248
static const String nullsp
Definition: Template.h:252
static const String REPcanon[Ncanon]
Definition: Template.h:201
Block< String > namstring_p
Data split name string (first include file)
Definition: Template.h:155
Block< String > tdflist_p
List of files used.
Definition: Template.h:160
uInt tdcount_p
Number of template definitions extracted from input.
Definition: Template.h:162
Template(const String &filename)
Create from the file name given.
static const Regex ifRE
Definition: Template.h:188
static const Regex snamespaceRE
Definition: Template.h:233
static const Regex spaces
Patterns to analyse an input line.
Definition: Template.h:186
static const Regex PATnmin[Nnmin]
Definition: Template.h:211
static String REPtypedef[Ntypedef]
Definition: Template.h:261
static const Regex mylistprelude
Definition: Template.h:245
Template(const Template &other)
Copy constructor (not implemented)
static const Regex constsp
Definition: Template.h:251
static const Regex splitnam
Definition: Template.h:221
static const uInt Ncanon
Simple pattern and replacements to make canonical templates files.
Definition: Template.h:199
Block< uInt > tdfile_p
Pointers to in which file in list.
Definition: Template.h:166
static const Regex fileRE
Definition: Template.h:193
Template()
Default constructor.
static const Regex auxtemplRE
Definition: Template.h:195
const String & operator[](uInt n)
Operators.
Definition: Template.h:88
static const Regex typedefRE
Definition: Template.h:194
static const Regex funcnameprelude
Definition: Template.h:244
static const Regex REPnmax[Nnmax]
Definition: Template.h:216
static const Regex forwardprelude
Definition: Template.h:243
static const Regex functionprelude
Definition: Template.h:242
void read(const String &filename)
Block< String > nstring_p
Data split of number string (or empty/spaces)
Definition: Template.h:151
static const uInt Ncanon2
For canonical change: replacement of pattern with pattern.
Definition: Template.h:204
static const Regex PATtypedef0[Ntypedef]
Definition: Template.h:259
static const String reposName
Name of repository files.
Definition: Template.h:264
static const Regex stypedefRE
Definition: Template.h:231
static const Regex sretRE1
Definition: Template.h:227
Block< String > allstring_p
Data split all text.
Definition: Template.h:153
static const uInt Ninif
Replacement patterns for ifs in saved line.
Definition: Template.h:236
static const Regex sretRE3
Definition: Template.h:229
static const String REPcanon2[Ncanon2]
Definition: Template.h:207
static const Regex sconstRE
Definition: Template.h:226
Template(const Vector< String > &files)
Create from the file names given.
const uInt & getTDfile(uInt n)
Definition: Template.h:112
uInt getTDCount() const
Get the number of template definition lines found.
Definition: Template.h:102
uInt getCount() const
Get the number of template entries.
Definition: Template.h:100
const String & getTDFlist(uInt n)
Get the various template definition information fields.
Definition: Template.h:110
void writeOut(ostream &os, const Bool warn=False)
Write the data formatted to the specified file.
uInt tcount_p
Count the templates.
Definition: Template.h:139
static const Regex splitnum
Patterns to split off number and name Patterns to split off number and name.
Definition: Template.h:220
this file contains all the compiler specific defines
Definition: mainpage.dox:28
const Bool False
Definition: aipstype.h:44
unsigned int uInt
Definition: aipstype.h:51
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42