Loading...
Searching...
No Matches
Template.h
Go to the documentation of this file.
//# Template.h: Canonicalise, format etc. Casacore template definitions
//# Copyright (C) 2001,2002,2004,2005
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This program is free software; you can redistribute it and/or modify it
//# under the terms of the GNU General Public License as published by the Free
//# Software Foundation; either version 2 of the License, or (at your option)
//# any later version.
//#
//# This program is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
//# more details.
//#
//# You should have received a copy of the GNU General Public License along
//# with this program; if not, write to the Free Software Foundation, Inc.,
//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
#ifndef CASA_TEMPLATE_H
#define CASA_TEMPLATE_H
//# Includes
#include <casacore/casa/aips.h>
#include <casacore/casa/Containers/Block.h>
#include <casacore/casa/BasicSL/String.h>
#include <casacore/casa/iosfwd.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
//# Forward declarations
class Regex;
template <class T> class Vector;
// <summary>
// Canonicalise, format and other actions on Casacore template definitions
// </summary>
// <use visibility=local>
// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tSpectralFit" demos="">
// </reviewed>
// <prerequisite>
// <li> Knowledge about the Casacore DYO template system
// </prerequisite>
// <synopsis>
// A set of methods on template repository files and on template definitions to be
// used in the reident, used, unused and duplicates programs (see
// <a href="../../../reference/System?System.html">Sytem manual</a>
// for details. <br /br>
// Methods exist to read templates, to canonicalise them for comparison and
// search functions and to format them for output.
// </synopsis>
//
// <motivation>
// To make template formatting identical across formatting/testing programs.
// </motivation>
//
// <todo asof="2001/03/20">
// <li> nothing I know
// </todo>
class Template {
public:
//# Constructors
// Default constructor. Need to read data into it
Template();
// Create from the file names given
explicit Template(const Vector<String> &files);
// Create from the file name given
explicit Template(const String &filename);
// Destructor
~Template();
// Operators
const String &operator[](uInt n) { return output_p[n]; }
//# Member functions
// Clear the object for a re-use.
void reset();
// Read the templates file or files into the class. Multiple reading is additive.
// Errors are reported to cerr, and commented out in the file.
// <group>
void read(const Vector<String> &files);
void read(const String &filename);
// </group>
// Get the number of template entries
uInt getCount() const { return count_p; };
// Get the number of template definition lines found
uInt getTDCount() const { return tdcount_p; };
// Get the number of templates found after all processing
uInt getTCount() const { return tcount_p; };
// Get the number of duplicates found
uInt getDCount() { return dcount_p; };
// Get the various template definition information fields.
// Meant for testing and special projects only.
// <group>
const String &getTDFlist(uInt n) { return tdflist_p[n]; };
const String &getTDlist(uInt n) { return tdlist_p[n]; };
const uInt &getTDfile(uInt n) { return tdfile_p[n]; };
const uInt &getTDline(uInt n) { return tdline_p[n]; };
const String &getTDname(uInt n) { return tdname_p[n]; };
// </group>
// Canonicalise the template entries in the object. If switch True, do only
// the templates entry for duplication
void canonical(const Bool tmplonly=False);
// Split the entries in number, name id, rest
void splitName();
// Sort the data on name and number and fill in missing number. If switch
// is True, renumber all template entries in sequence.
void sortName(const Bool renumber=False);
// Write the data formatted to the specified file. Notify errors and warnings
// by writing to <src>cerr</src>. If <src>warn</src> is False, some warnings will be
// compressed into a general warning.
void writeOut(ostream &os, const Bool warn=False);
// Write the duplicate list; the userFile gets ***; isSys gives the system switch
void writeDup(ostream &os, const String &userFile, Bool isSys=False);
private:
//# Data
// Each element is a template entry on a single line
Block<String> output_p;
// Count the lines
uInt count_p;
// Count the templates
uInt tcount_p;
// Record comment lines
Block<String> comout_p;
// And where they originated
Block<Int> comptr_p;
// And count the comment lines
uInt ccount_p;
// Indicate data split
Bool isSplit_p;
// Count the duplicates
uInt dcount_p;
// Data split of number string (or empty/spaces)
Block<String> nstring_p;
// Data split all text
Block<String> allstring_p;
// Data split name string (first include file)
Block<String> namstring_p;
// Data split numeric number
Block<uInt> nval_p;
// List of files used
Block<String> tdflist_p;
// Number of template definitions extracted from input
uInt tdcount_p;
// List of template definitions
Block<String> tdlist_p;
// Pointers to in which file in list
Block<uInt> tdfile_p;
// Line number in file at which template found
Block<uInt> tdline_p;
// List of comparison names
Block<String> tdname_p;
//# Constructors
// Copy constructor (not implemented)
Template(const Template &other);
//# Operators
// Assignment (not implemented)
Template &operator=(const Template &other);
//# Member functions
// Save comment
void setComment(const String &txt, const Bool atstart=False);
// Save a line
void setOutput(const String &txt);
//# Static conversion data
// Patterns to analyse an input line
static const Regex spaces;
static const Regex comment;
static const Regex ifRE;
static const Regex endifRE;
static const Regex elseRE;
static const Regex templateRE;
static const Regex contRE;
static const Regex fileRE;
static const Regex typedefRE;
static const Regex auxtemplRE;
static const Regex namespaceRE;
// Simple pattern and replacements to make canonical templates files
static const uInt Ncanon = 52;
static const Regex PATcanon[Ncanon];
static const String REPcanon[Ncanon];
// For canonical change: replacement of pattern with pattern
static const uInt Ncanon2 = 15;
static const Regex PATcanon20[Ncanon2];
static const Regex PATcanon21[Ncanon2];
static const String REPcanon2[Ncanon2];
// Make canonical numbers of 4 digits minimum
static const uInt Nnmin = 4;
static const Regex PATnmin[Nnmin];
static const String REPnmin[Nnmin];
// Make canonical numbers of 4 digits maximum
static const uInt Nnmax = 1;
static const Regex PATnmax[Nnmax];
static const Regex REPnmax[Nnmax];
// Patterns to split off number and name
// Patterns to split off number and name
static const Regex splitnum;
static const Regex splitnam;
// Patterns to check the template line
static const Regex sifRE;
static const Regex stemRE;
static const Regex sconstRE;
static const Regex sretRE1;
static const Regex sretRE2;
static const Regex sretRE3;
static const Regex sretRE4;
static const Regex stypedefRE;
static const Regex sauxtemplRE;
static const Regex snamespaceRE;
// Replacement patterns for ifs in saved line
static const uInt Ninif = 5;
static const String PATinif[Ninif];
static const String REPinif[Ninif];
// Tests for finding real templates for duplicate tests
static const Regex classprelude;
static const Regex functionprelude;
static const Regex forwardprelude;
static const Regex funcnameprelude;
static const Regex mylistprelude;
// Data to remove spaces at begin, end, make single, count/remove const
static const Regex leadsp;
static const Regex endsp;
static const Regex mulsp;
static const Regex constsp;
static const String nullsp;
static const String singlesp;
// Patterns to make all typedefs comparisons for duplicates possible
// Note that the first three should be in that position for run-time
// change on some systems.
static const uInt Ntypedef = 23;
static const Regex PATtypedef0[Ntypedef];
static const Regex PATtypedef1[Ntypedef];
static String REPtypedef[Ntypedef];
// Name of repository files
static const String reposName;
};
} //# NAMESPACE CASACORE - END
#ifndef CASACORE_NO_AUTO_TEMPLATES
#include <casacore/casa/Utilities/Template.tcc>
#endif //# CASACORE_NO_AUTO_TEMPLATES
#endif
casacore::Block
Definition Block.h:140
casacore::Regex
Definition Regex.h:201
casacore::String
String: the storage and methods of handling collections of characters.
Definition String.h:223
casacore::Template::elseRE
static const Regex elseRE
Definition Template.h:188
casacore::Template::PATnmax
static const Regex PATnmax[Nnmax]
Definition Template.h:213
casacore::Template::comment
static const Regex comment
Definition Template.h:185
casacore::Template::classprelude
static const Regex classprelude
Tests for finding real templates for duplicate tests.
Definition Template.h:239
casacore::Template::PATcanon20
static const Regex PATcanon20[Ncanon2]
Definition Template.h:203
casacore::Template::namespaceRE
static const Regex namespaceRE
Definition Template.h:194
casacore::Template::dcount_p
uInt dcount_p
Count the duplicates.
Definition Template.h:147
casacore::Template::nval_p
Block< uInt > nval_p
Data split numeric number.
Definition Template.h:155
casacore::Template::setComment
void setComment(const String &txt, const Bool atstart=False)
Save comment.
casacore::Template::output_p
Block< String > output_p
Each element is a template entry on a single line.
Definition Template.h:133
casacore::Template::stemRE
static const Regex stemRE
Definition Template.h:223
casacore::Template::sauxtemplRE
static const Regex sauxtemplRE
Definition Template.h:230
casacore::Template::Ntypedef
static const uInt Ntypedef
Patterns to make all typedefs comparisons for duplicates possible Note that the first three should be...
Definition Template.h:256
casacore::Template::PATtypedef1
static const Regex PATtypedef1[Ntypedef]
Definition Template.h:258
casacore::Template::read
void read(const Vector< String > &files)
Read the templates file or files into the class.
casacore::Template::REPnmin
static const String REPnmin[Nnmin]
Definition Template.h:210
casacore::Template::templateRE
static const Regex templateRE
Definition Template.h:189
casacore::Template::count_p
uInt count_p
Count the lines.
Definition Template.h:135
casacore::Template::Nnmin
static const uInt Nnmin
Make canonical numbers of 4 digits minimum.
Definition Template.h:208
casacore::Template::PATcanon21
static const Regex PATcanon21[Ncanon2]
Definition Template.h:204
casacore::Template::singlesp
static const String singlesp
Definition Template.h:251
casacore::Template::tdname_p
Block< String > tdname_p
List of comparison names.
Definition Template.h:168
casacore::Template::Nnmax
static const uInt Nnmax
Make canonical numbers of 4 digits maximum.
Definition Template.h:212
casacore::Template::comptr_p
Block< Int > comptr_p
And where they originated.
Definition Template.h:141
casacore::Template::getTDline
const uInt & getTDline(uInt n)
Definition Template.h:111
casacore::Template::canonical
void canonical(const Bool tmplonly=False)
Canonicalise the template entries in the object.
casacore::Template::isSplit_p
Bool isSplit_p
Indicate data split.
Definition Template.h:145
casacore::Template::splitName
void splitName()
Split the entries in number, name id, rest.
casacore::Template::sortName
void sortName(const Bool renumber=False)
Sort the data on name and number and fill in missing number.
casacore::Template::sretRE4
static const Regex sretRE4
Definition Template.h:228
casacore::Template::getTCount
uInt getTCount() const
Get the number of templates found after all processing.
Definition Template.h:102
casacore::Template::getDCount
uInt getDCount()
Get the number of duplicates found.
Definition Template.h:104
casacore::Template::reset
void reset()
Clear the object for a re-use.
casacore::Template::sretRE2
static const Regex sretRE2
Definition Template.h:226
casacore::Template::setOutput
void setOutput(const String &txt)
Save a line.
casacore::Template::writeDup
void writeDup(ostream &os, const String &userFile, Bool isSys=False)
Write the duplicate list; the userFile gets ***; isSys gives the system switch.
casacore::Template::sifRE
static const Regex sifRE
Patterns to check the template line.
Definition Template.h:222
casacore::Template::PATinif
static const String PATinif[Ninif]
Definition Template.h:235
casacore::Template::operator[]
const String & operator[](uInt n)
Operators.
Definition Template.h:86
casacore::Template::tdlist_p
Block< String > tdlist_p
List of template definitions.
Definition Template.h:162
casacore::Template::mulsp
static const Regex mulsp
Definition Template.h:248
casacore::Template::REPinif
static const String REPinif[Ninif]
Definition Template.h:236
casacore::Template::PATcanon
static const Regex PATcanon[Ncanon]
Definition Template.h:198
casacore::Template::comout_p
Block< String > comout_p
Record comment lines.
Definition Template.h:139
casacore::Template::tdline_p
Block< uInt > tdline_p
Line number in file at which template found.
Definition Template.h:166
casacore::Template::endsp
static const Regex endsp
Definition Template.h:247
casacore::Template::ccount_p
uInt ccount_p
And count the comment lines.
Definition Template.h:143
casacore::Template::endifRE
static const Regex endifRE
Definition Template.h:187
casacore::Template::~Template
~Template()
Destructor.
casacore::Template::operator=
Template & operator=(const Template &other)
Assignment (not implemented).
casacore::Template::contRE
static const Regex contRE
Definition Template.h:190
casacore::Template::getTDlist
const String & getTDlist(uInt n)
Definition Template.h:109
casacore::Template::leadsp
static const Regex leadsp
Data to remove spaces at begin, end, make single, count/remove const.
Definition Template.h:246
casacore::Template::nullsp
static const String nullsp
Definition Template.h:250
casacore::Template::REPcanon
static const String REPcanon[Ncanon]
Definition Template.h:199
casacore::Template::namstring_p
Block< String > namstring_p
Data split name string (first include file).
Definition Template.h:153
casacore::Template::tdflist_p
Block< String > tdflist_p
List of files used.
Definition Template.h:158
casacore::Template::tdcount_p
uInt tdcount_p
Number of template definitions extracted from input.
Definition Template.h:160
casacore::Template::getTDfile
const uInt & getTDfile(uInt n)
Definition Template.h:110
casacore::Template::Template
Template(const String &filename)
Create from the file name given.
casacore::Template::ifRE
static const Regex ifRE
Definition Template.h:186
casacore::Template::snamespaceRE
static const Regex snamespaceRE
Definition Template.h:231
casacore::Template::spaces
static const Regex spaces
Patterns to analyse an input line.
Definition Template.h:184
casacore::Template::getTDname
const String & getTDname(uInt n)
Definition Template.h:112
casacore::Template::PATnmin
static const Regex PATnmin[Nnmin]
Definition Template.h:209
casacore::Template::REPtypedef
static String REPtypedef[Ntypedef]
Definition Template.h:259
casacore::Template::mylistprelude
static const Regex mylistprelude
Definition Template.h:243
casacore::Template::Template
Template(const Template &other)
Copy constructor (not implemented).
casacore::Template::constsp
static const Regex constsp
Definition Template.h:249
casacore::Template::splitnam
static const Regex splitnam
Definition Template.h:219
casacore::Template::Ncanon
static const uInt Ncanon
Simple pattern and replacements to make canonical templates files.
Definition Template.h:197
casacore::Template::tdfile_p
Block< uInt > tdfile_p
Pointers to in which file in list.
Definition Template.h:164
casacore::Template::fileRE
static const Regex fileRE
Definition Template.h:191
casacore::Template::getTDFlist
const String & getTDFlist(uInt n)
Get the various template definition information fields.
Definition Template.h:108
casacore::Template::Template
Template()
Default constructor.
casacore::Template::auxtemplRE
static const Regex auxtemplRE
Definition Template.h:193
casacore::Template::typedefRE
static const Regex typedefRE
Definition Template.h:192
casacore::Template::funcnameprelude
static const Regex funcnameprelude
Definition Template.h:242
casacore::Template::REPnmax
static const Regex REPnmax[Nnmax]
Definition Template.h:214
casacore::Template::forwardprelude
static const Regex forwardprelude
Definition Template.h:241
casacore::Template::functionprelude
static const Regex functionprelude
Definition Template.h:240
casacore::Template::read
void read(const String &filename)
casacore::Template::nstring_p
Block< String > nstring_p
Data split of number string (or empty/spaces).
Definition Template.h:149
casacore::Template::Ncanon2
static const uInt Ncanon2
For canonical change: replacement of pattern with pattern.
Definition Template.h:202
casacore::Template::PATtypedef0
static const Regex PATtypedef0[Ntypedef]
Definition Template.h:257
casacore::Template::reposName
static const String reposName
Name of repository files.
Definition Template.h:262
casacore::Template::stypedefRE
static const Regex stypedefRE
Definition Template.h:229
casacore::Template::sretRE1
static const Regex sretRE1
Definition Template.h:225
casacore::Template::allstring_p
Block< String > allstring_p
Data split all text.
Definition Template.h:151
casacore::Template::Ninif
static const uInt Ninif
Replacement patterns for ifs in saved line.
Definition Template.h:234
casacore::Template::sretRE3
static const Regex sretRE3
Definition Template.h:227
casacore::Template::REPcanon2
static const String REPcanon2[Ncanon2]
Definition Template.h:205
casacore::Template::sconstRE
static const Regex sconstRE
Definition Template.h:224
casacore::Template::Template
Template(const Vector< String > &files)
Create from the file names given.
casacore::Template::getTDCount
uInt getTDCount() const
Get the number of template definition lines found.
Definition Template.h:100
casacore::Template::getCount
uInt getCount() const
Get the number of template entries.
Definition Template.h:98
casacore::Template::writeOut
void writeOut(ostream &os, const Bool warn=False)
Write the data formatted to the specified file.
casacore::Template::tcount_p
uInt tcount_p
Count the templates.
Definition Template.h:137
casacore::Template::splitnum
static const Regex splitnum
Patterns to split off number and name Patterns to split off number and name.
Definition Template.h:218
casacore::Vector
Definition Vector.h:82
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::False
const Bool False
Definition aipstype.h:42
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40