OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Table.h
Go to the documentation of this file.
1#ifndef OPAL_Table_HH
2#define OPAL_Table_HH 1
3
4// ------------------------------------------------------------------------
5// $RCSfile: Table.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.1.1.1 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Class: Table
13//
14// ------------------------------------------------------------------------
15//
16// $Date: 2000/03/27 09:33:35 $
17// $Author: Andreas Adelmann $
18//
19// ------------------------------------------------------------------------
20
21#include <vector>
24
25class Attribute;
26class Beamline;
27class PlaceRep;
28class RangeRep;
29
30// Class Table
31// ------------------------------------------------------------------------
33// It implements the common behaviour of tables, it can also be used via
34// dynamic casting to determine whether an object represents a table.
35// During matching operations, a Table must often be recalculated. This
36// is done by calling its [tt]fill()[/tt] method. To avoid unnecessary
37// filling, the user may define a table as ``static'' in the command
38// creating the table. In this case OPAL assumes that the table never
39// changes.
40
41class Table : public Object {
42public:
44 struct Cell {
46 Cell(Expressions::PtrToScalar<double> expr, int width, int prec)
47 : itsExpr(expr), printWidth(width), printPrecision(prec) {}
48
51
54
57 };
58
60 typedef std::vector<Cell> CellArray;
61
62 virtual ~Table();
63
65 // A table cannot be replaced, thus this method never returns true.
66 virtual bool canReplaceBy(Object* newObject);
67
69 // If [b]refill[/b] is true, call the table algorithm to fill the buffer.
70 virtual void fill() = 0;
71
73 // If a table with name [b]name[/b] exists, return a pointer to that table.
74 // If no such table exists, throw OpalException.
75 static Table* find(const std::string& name);
76
78 // Return the string "TABLE".
79 virtual const std::string getCategory() const;
80
82 // If true, the object's execute() function should be traced.
83 // Always true for tables.
84 virtual bool shouldTrace() const;
85
87 // If true, the data structure should be updated before calling execute().
88 // Always true for tables.
89 virtual bool shouldUpdate() const;
90
92 // Return the value stored in the table cell identified by the row
93 // at [b]row[/b] and the column name [b]col[/b].
94 virtual double getCell(const PlaceRep& row, const std::string& col) = 0;
95
97 virtual std::vector<double> getColumn(const RangeRep& range, const std::string& col) = 0;
98
100 // Returns an array of column descriptors, which, when applied to a
101 // row of the table, gives the default print columns for this table.
102 virtual CellArray getDefault() const = 0;
103
105 // Returns the geometric length of the underlying beam line.
106 virtual double getLength() = 0;
107
109 // Returns the OPALX beamline representing the table.
110 // The data of the table are attached to each position in the line.
111 virtual const Beamline* getLine() const = 0;
112
114 // Returns the values stored in the row specified by the first argument,
115 // with columns selected by the names stored in the second argument.
116 virtual std::vector<double> getRow(const PlaceRep&, const std::vector<std::string>&) = 0;
117
119 virtual void invalidate();
120
122 // Must be overridden in derived classes.
123 virtual bool isDependent(const std::string& name) const = 0;
124
125 virtual Expressions::PtrToScalar<double> makeColumnExpression(const std::string&) const = 0;
126
128 virtual bool matches(Table* rhs) const = 0;
129
131 virtual void printTable(std::ostream&, const CellArray&) const = 0;
132
133protected:
135 Table(int size, const char* name, const char* help);
136
138 Table(const std::string& name, Table* parent);
139
141 // If true, the table is dynamic. If it is also invalidated,
142 // it will be refilled when fill() is called.
144
146 // If true, the table has been invalidated. If it is also dynammic,
147 // it will be refilled when fill() is called.
148 bool refill;
149
150private:
151 // Not implemented.
153 Table(const Table&);
154 void operator=(const Table&);
155};
156
157#endif // OPAL_Table_HH
A representation of an Object attribute.
Definition Attribute.h:52
An abstract sequence of beam line components.
Definition Beamline.h:34
A pointer to a scalar expression.
The base class for all OPAL objects.
Definition Object.h:45
Representation of a place within a beam line or sequence.
Definition PlaceRep.h:40
Representation of a range within a beam line or sequence.
Definition RangeRep.h:33
The base class for all OPAL tables.
Definition Table.h:41
virtual double getCell(const PlaceRep &row, const std::string &col)=0
Return value in selected table cell.
virtual void invalidate()
Mark this table as invalid, if it is dynamic.
Definition Table.cpp:50
virtual void printTable(std::ostream &, const CellArray &) const =0
Print list for the table.
virtual CellArray getDefault() const =0
Return the default print columns.
virtual std::vector< double > getRow(const PlaceRep &, const std::vector< std::string > &)=0
Return a table row.
virtual bool shouldUpdate() const
Update flag.
Definition Table.cpp:48
virtual const std::string getCategory() const
Return the object category as a string.
Definition Table.cpp:44
virtual Expressions::PtrToScalar< double > makeColumnExpression(const std::string &) const =0
virtual bool canReplaceBy(Object *newObject)
Test if object can be replaced.
Definition Table.cpp:34
virtual std::vector< double > getColumn(const RangeRep &range, const std::string &col)=0
Return column [b]col[/b] of this table, limited by [b]range[/b].
virtual bool matches(Table *rhs) const =0
Check that [b]rhs[/b] is of same type as [b]this[/b].
virtual double getLength()=0
Return the length of the table.
virtual void fill()=0
Refill the buffer.
virtual bool isDependent(const std::string &name) const =0
Find out if table depends on the object identified by [b]name[/b].
virtual ~Table()
Definition Table.cpp:29
void operator=(const Table &)
std::vector< Cell > CellArray
An array of cell descriptors.
Definition Table.h:60
Table(const Table &)
bool refill
Refill flag.
Definition Table.h:148
static Table * find(const std::string &name)
Find named Table.
Definition Table.cpp:36
virtual const Beamline * getLine() const =0
Return embedded OPALX beamline.
virtual bool shouldTrace() const
Trace flag.
Definition Table.cpp:46
bool dynamic
Flag dynamic table.
Definition Table.h:143
Descriptor for printing a table cell.
Definition Table.h:44
Cell(Expressions::PtrToScalar< double > expr, int width, int prec)
Constructor.
Definition Table.h:46
int printWidth
The cell width in print characters.
Definition Table.h:53
int printPrecision
The number of digits printed for this cell.
Definition Table.h:56
Expressions::PtrToScalar< double > itsExpr
The expression generating the values for this Cell.
Definition Table.h:50