OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
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 "AbstractObjects/Object.h"
23 #include <vector>
24 
25 class Attribute;
26 class Beamline;
27 class PlaceRep;
28 class RangeRep;
29 
30 
31 // Class Table
32 // ------------------------------------------------------------------------
34 // It implements the common behaviour of tables, it can also be used via
35 // dynamic casting to determine whether an object represents a table.
36 // During matching operations, a Table must often be recalculated. This
37 // is done by calling its [tt]fill()[/tt] method. To avoid unnecessary
38 // filling, the user may define a table as ``static'' in the command
39 // creating the table. In this case OPAL assumes that the table never
40 // changes.
41 
42 class Table: public Object {
43 
44 public:
45 
47  struct Cell {
49  Cell(Expressions::PtrToScalar<double> expr, int width, int prec):
50  itsExpr(expr), printWidth(width), printPrecision(prec) {}
51 
54 
57 
60  };
61 
63  typedef std::vector<Cell> CellArray;
64 
65  virtual ~Table();
66 
68  // A table cannot be replaced, thus this method never returns true.
69  virtual bool canReplaceBy(Object *newObject);
70 
72  // If [b]refill[/b] is true, call the table algorithm to fill the buffer.
73  virtual void fill() = 0;
74 
76  // If a table with name [b]name[/b] exists, return a pointer to that table.
77  // If no such table exists, throw OpalException.
78  static Table *find(const std::string &name);
79 
81  // Return the string "TABLE".
82  virtual const std::string getCategory() const;
83 
85  // If true, the object's execute() function should be traced.
86  // Always true for tables.
87  virtual bool shouldTrace() const;
88 
90  // If true, the data structure should be updated before calling execute().
91  // Always true for tables.
92  virtual bool shouldUpdate() const;
93 
94 
96  // Return the value stored in the table cell identified by the row
97  // at [b]row[/b] and the column name [b]col[/b].
98  virtual double getCell(const PlaceRep &row, const std::string &col) = 0;
99 
101  virtual std::vector<double> getColumn
102  (const RangeRep &range, const std::string &col) = 0;
103 
105  // Returns an array of column descriptors, which, when applied to a
106  // row of the table, gives the default print columns for this table.
107  virtual CellArray getDefault() const = 0;
108 
110  // Returns the geometric length of the underlying beam line.
111  virtual double getLength() = 0;
112 
114  // Returns the CLASSIC beamline representing the table.
115  // The data of the table are attached to each position in the line.
116  virtual const Beamline *getLine() const = 0;
117 
119  // Returns the values stored in the row specified by the first argument,
120  // with columns selected by the names stored in the second argument.
121  virtual std::vector<double>
122  getRow(const PlaceRep &, const std::vector<std::string> &) = 0;
123 
125  virtual void invalidate();
126 
128  // Must be overridden in derived classes.
129  virtual bool isDependent(const std::string &name) const = 0;
130 
132  makeColumnExpression(const std::string &) const = 0;
133 
135  virtual bool matches(Table *rhs) const = 0;
136 
138  virtual void printTable(std::ostream &, const CellArray &) const = 0;
139 
140 
141 protected:
142 
144  Table(int size, const char *name, const char *help);
145 
147  Table(const std::string &name, Table *parent);
148 
149 
151  // If true, the table is dynamic. If it is also invalidated,
152  // it will be refilled when fill() is called.
153  bool dynamic;
154 
156  // If true, the table has been invalidated. If it is also dynammic,
157  // it will be refilled when fill() is called.
158  bool refill;
159 
160 private:
161 
162  // Not implemented.
163  Table();
164  Table(const Table &);
165  void operator=(const Table &);
166 };
167 
168 #endif // OPAL_Table_HH
std::vector< Cell > CellArray
An array of cell descriptors.
Definition: Table.h:63
virtual bool shouldTrace() const
Trace flag.
Definition: Table.cpp:55
virtual void fill()=0
Refill the buffer.
void operator=(const Table &)
bool refill
Refill flag.
Definition: Table.h:158
Expressions::PtrToScalar< double > itsExpr
The expression generating the values for this Cell.
Definition: Table.h:53
Cell(Expressions::PtrToScalar< double > expr, int width, int prec)
Constructor.
Definition: Table.h:49
virtual Expressions::PtrToScalar< double > makeColumnExpression(const std::string &) const =0
virtual ~Table()
Definition: Table.cpp:30
virtual const std::string getCategory() const
Return the object category as a string.
Definition: Table.cpp:50
bool dynamic
Flag dynamic table.
Definition: Table.h:153
int printPrecision
The number of digits printed for this cell.
Definition: Table.h:59
Representation of a place within a beam line or sequence.
Definition: PlaceRep.h:41
A representation of an Object attribute.
Definition: Attribute.h:55
virtual bool matches(Table *rhs) const =0
Check that [b]rhs[/b] is of same type as [b]this[/b].
virtual const Beamline * getLine() const =0
Return embedded CLASSIC beamline.
virtual void invalidate()
Mark this table as invalid, if it is dynamic.
Definition: Table.cpp:65
static Table * find(const std::string &name)
Find named Table.
Definition: Table.cpp:41
virtual bool shouldUpdate() const
Update flag.
Definition: Table.cpp:60
virtual bool isDependent(const std::string &name) const =0
Find out if table depends on the object identified by [b]name[/b].
Representation of a range within a beam line or sequence.
Definition: RangeRep.h:34
An abstract sequence of beam line components.
Definition: Beamline.h:37
virtual void printTable(std::ostream &, const CellArray &) const =0
Print list for the table.
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 double getCell(const PlaceRep &row, const std::string &col)=0
Return value in selected table cell.
The base class for all OPAL objects.
Definition: Object.h:48
const std::string name
Descriptor for printing a table cell.
Definition: Table.h:47
virtual CellArray getDefault() const =0
Return the default print columns.
The base class for all OPAL tables.
Definition: Table.h:42
virtual bool canReplaceBy(Object *newObject)
Test if object can be replaced.
Definition: Table.cpp:36
int printWidth
The cell width in print characters.
Definition: Table.h:56
virtual std::vector< double > getRow(const PlaceRep &, const std::vector< std::string > &)=0
Return a table row.
virtual double getLength()=0
Return the length of the table.