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