File: ExprNodeRep.h

package info (click to toggle)
casacore 3.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,912 kB
  • sloc: cpp: 471,569; fortran: 16,372; ansic: 7,416; yacc: 4,714; lex: 2,346; sh: 1,865; python: 629; perl: 531; sed: 499; csh: 201; makefile: 32
file content (768 lines) | stat: -rw-r--r-- 26,984 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
//# ExprNodeRep.h: Abstract base class for a node in a table column expression tree
//# Copyright (C) 1994,1995,1996,1997,1998,2000,2001,2003
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library 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 Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; 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 TABLES_EXPRNODEREP_H
#define TABLES_EXPRNODEREP_H

//# Includes
#include <casacore/casa/aips.h>
#include <casacore/tables/Tables/Table.h>
#include <casacore/tables/TaQL/TableExprId.h>
#include <casacore/tables/TaQL/ExprRange.h>
#include <casacore/tables/TaQL/MArray.h>
#include <casacore/casa/Containers/Record.h>
#include <casacore/casa/BasicSL/Complex.h>
#include <casacore/casa/Quanta/MVTime.h>
#include <casacore/casa/Quanta/Unit.h>
#include <casacore/casa/Utilities/DataType.h>
#include <casacore/casa/Utilities/Regex.h>
#include <casacore/casa/Utilities/StringDistance.h>
#include <casacore/casa/iosfwd.h>
#include <vector>

namespace casacore { //# NAMESPACE CASACORE - BEGIN

//# Forward Declarations
class TableExprNode;
class TableExprNodeColumn;
class TableExprGroupFuncBase;
template<class T> class Block;

//# Define a shared pointer to the Rep class.
class TableExprNodeRep;
typedef std::shared_ptr<TableExprNodeRep> TENShPtr;


// <summary>
// Class to handle a Regex or StringDistance.
// </summary>

// <use visibility=local>

// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
// </reviewed>

// <prerequisite>
//# Classes you should understand before using this one.
//   <li> <linkto class=Regex>Regex</linkto>
//   <li> <linkto class=StringDistance>StringDistance</linkto>
// </prerequisite>

// <synopsis> 
// A StringDistance (Levensthein distance) in TaQL is given in the same way
// as a Regex. This class is needed to have a single object in the parse tree
// objects containing them (in class TableExprNodeConstRegex).
// </synopsis> 

class TaqlRegex
{
public:
    // Construct from a regex.
  explicit TaqlRegex (const Regex& regex)
    : itsRegex(regex)
  {}

  // Construct from a StringDistance.
  explicit TaqlRegex (const StringDistance& dist)
    : itsDist(dist)
  {}

  // Does the regex or maximum string distance match?
  Bool match (const String& str) const
    { return itsRegex.regexp().empty()  ?
        itsDist.match(str) : str.matches(itsRegex);
    }

  // Return the regular expression.
  const Regex& regex() const
    { return itsRegex; }

private:
  Regex          itsRegex;
  StringDistance itsDist;
};



  // <summary>
// Class to connect a Table and its alias name
// </summary>

// <use visibility=local>

// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
// </reviewed>

// <synopsis> 
// This class connects a Table object to its alias name used in a TaQL command.
// If no alias is given, the table name is used as such.
// It also tells if the Table is used as a join table.
// </synopsis> 

class TableExprInfo
{
public:
    // Construct from a table and its alias.
  explicit TableExprInfo (const Table& table = Table(),
                          const String& alias = String(),
                          Bool isJoinTable = False);

  // Get the Table object.
  const Table& table() const
    { return itsTable; }

  // Get the alias.
  const String& alias() const
    { return itsAlias; }

  // Is the table a join table?
  Bool isJoinTable() const
    { return itsIsJoinTable; }

  // Apply a selection of row numbers to the Table.
  void apply (const Vector<rownr_t>& rownrs);
  
private:
  Table  itsTable;
  String itsAlias;
  Bool   itsIsJoinTable;
};



// <summary>
// Abstract base class for a node in a table column expression tree
// </summary>

// <use visibility=local>

// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
// </reviewed>

// <prerequisite>
//# Classes you should understand before using this one.
//   <li> <linkto class=TableExprNode>TableExprNode</linkto>
// </prerequisite>

// <etymology>
// TableExprNodeRep is the (abstract) REPresentation of a node in a table
// expression tree.
// </etymology>

// <synopsis> 
// TableExprNodeRep is the base class for all nodes in a table
// expression tree. It is used by the handle class TableExprNode.
// <p>
// The objects of this class are reference-counted to make it possible
// that the same object is reused.
// </synopsis> 

// <motivation>
// TableExprNodeRep and its derivations store a table select expression
// before actually evaluating it. It is also possible that the classes
// are used by the table expression parser defined in TableParse and
// TableGram.
// <br>
// For each operator a special derived class is implemented.
// Another approach could have been to store the operator as
// a flag and switch on that. However, that causes extra overhead
// and the C++ virtual function mechanism is designed for
// these purposes.
// </motivation>

// <todo asof="$DATE:$">
//# A List of bugs, limitations, extensions or planned refinements.
//   <li> add selection by comparing with a set of values
// </todo>


class TableExprNodeRep
{
public:
    // Define the data types of a node.
    enum NodeDataType {
        NTBool,
        NTInt,
        NTDouble,
        NTComplex,
        NTString,
        NTRegex,
        NTDate,
        NTReal,                //# NTInt or NTDouble
        NTDouCom,              //# NTDouble or NTComplex
        NTNumeric,             //# NTInt, NTDouble, or NTComplex
        NTAny                  //# Any data type
    };

    // Define the value types.
    enum ValueType {
        VTScalar,
        VTArray,
        VTRecord,
        VTSetElem,
        VTSet,
        VTIndex
    };

    // Define the operator types.
    // LE and LT are handled as GE and GT with swapped operands.
    enum OperType {OtPlus, OtMinus, OtTimes, OtDivide, OtModulo,
                   OtBitAnd, OtBitOr, OtBitXor, OtBitNegate,
                   OtEQ, OtGE, OtGT, OtNE, OtIN,
                   OtAND, OtOR, OtNOT, OtMIN,
                   OtColumn, OtField, OtLiteral, OtFunc, OtSlice, OtUndef,
                   OtRownr, OtRandom
    };

    // Define the value types of the 2 arguments when arrays are involved.
    enum ArgType {
        NoArr, ArrArr, ArrSca, ScaArr
    };

    // Define (sub-)expression type
    enum ExprType {
        // A constant subexpression which can be evaluated immediately.
        Constant,
        // A variable (i.e. row dependent) subexpression which
        // has to be evaluated for each table row.
        Variable
        // An expensive constant subexpression which should only be
        // evaluated when needed (e.g. a subquery).
//        Lazy
    };

    // Construct a node.
    TableExprNodeRep (NodeDataType, ValueType, OperType, ArgType, ExprType,
                      Int ndim, const IPosition& shape);

    // This constructor is called from the derived TableExprNodeRep.
    TableExprNodeRep (NodeDataType, ValueType, OperType, ExprType);

    // Copy constructor.
    TableExprNodeRep (const TableExprNodeRep&) = default;

    // Assign to a TableExprNodeRep cannot be done.
    TableExprNodeRep& operator= (const TableExprNodeRep&) = delete;

    // The destructor deletes all the underlying TableExprNode objects.
    virtual ~TableExprNodeRep() = default;

    // Is the node an aggegation node.
    // The default implementation returns False.
    virtual Bool isAggregate() const;

    // Get the table info.
    // The default implementation returns an info object with a null table.
    virtual TableExprInfo getTableInfo() const;
  
    // Try to optimize the node (meant for the right hand of the IN operator).
    // The default implementation does nothing.
    virtual void optimize();
  
    // Do not apply the selection.
    virtual void disableApplySelection();

    // Re-create the column object for a selection of rows.
    // The default implementation does nothing.
    virtual void applySelection (const Vector<rownr_t>& rownrs);

    // Get the unit conversion factor.
    // Default 1 is returned.
    virtual Double getUnitFactor() const;

    // Flatten the node tree by adding the node and its children to the vector.
    virtual void flattenTree (std::vector<TableExprNodeRep*>&);
  
    // Create the correct immediate aggregate function object.
    // The default implementation throws an exception, because it should
    // only be called for TableExprAggrNode(Array).
    virtual std::shared_ptr<TableExprGroupFuncBase> makeGroupAggrFunc();

    // Is the aggregate function a lazy or an immediate one?
    // The default implementation returns True
    // (because all UDF aggregate functions have to be lazy).
    virtual Bool isLazyAggregate() const;

    // Get a scalar value for this node in the given row.
    // The appropriate functions are implemented in the derived classes and
    // will usually invoke the get in their children and apply the
    // operator on the resulting values.
    // <group>
    virtual Bool getBool         (const TableExprId& id);
    virtual Int64 getInt         (const TableExprId& id);
    virtual Double getDouble     (const TableExprId& id);
    virtual DComplex getDComplex (const TableExprId& id);
    virtual String getString     (const TableExprId& id);
    virtual TaqlRegex getRegex   (const TableExprId& id);
    virtual MVTime getDate       (const TableExprId& id);
    // </group>

    // Get an array value for this node in the given row.
    // The appropriate functions are implemented in the derived classes and
    // will usually invoke the get in their children and apply the
    // operator on the resulting values.
    // <group>
    virtual MArray<Bool> getArrayBool         (const TableExprId& id);
    virtual MArray<Int64> getArrayInt         (const TableExprId& id);
    virtual MArray<Double> getArrayDouble     (const TableExprId& id);
    virtual MArray<DComplex> getArrayDComplex (const TableExprId& id);
    virtual MArray<String> getArrayString     (const TableExprId& id);
    virtual MArray<MVTime> getArrayDate       (const TableExprId& id);
    // </group>

    // General get functions for template purposes.
    // <group>
    void get (const TableExprId& id, Bool& value)
      { value = getBool (id); }
    void get (const TableExprId& id, Int64& value)
      { value = getInt (id); }
    void get (const TableExprId& id, Double& value)
      { value = getDouble (id); }
    void get (const TableExprId& id, DComplex& value)
      { value = getDComplex (id); }
    void get (const TableExprId& id, MVTime& value)
      { value = getDate (id); }
    void get (const TableExprId& id, String& value)
      { value = getString (id); }
    void get (const TableExprId& id, MArray<Bool>& value)
      { value = getArrayBool (id); }
    void get (const TableExprId& id, MArray<Int64>& value)
      { value = getArrayInt (id); }
    void get (const TableExprId& id, MArray<Double>& value)
      { value = getArrayDouble (id); }
    void get (const TableExprId& id, MArray<DComplex>& value)
      { value = getArrayDComplex (id); }
    void get (const TableExprId& id, MArray<MVTime>& value)
      { value = getArrayDate (id); }
    void get (const TableExprId& id, MArray<String>& value)
      { value = getArrayString (id); }
    // </group>

    // Get a value as an array, even it it is a scalar.
    // This is useful if one could give an argument as scalar or array.
    // <group>
    MArray<Bool> getBoolAS         (const TableExprId& id);
    MArray<Int64> getIntAS         (const TableExprId& id);
    MArray<Double> getDoubleAS     (const TableExprId& id);
    MArray<DComplex> getDComplexAS (const TableExprId& id);
    MArray<String> getStringAS     (const TableExprId& id);
    MArray<MVTime> getDateAS       (const TableExprId& id);
    // </group>

    // Does a set or array contain the value?
    // The default implementation assumes the set is a single scalar,
    // thus tests if it is equal to the given value.
    // <group>
    virtual Bool contains (const TableExprId& id, Bool value);
    virtual Bool contains (const TableExprId& id, Int64 value);
    virtual Bool contains (const TableExprId& id, Double value);
    virtual Bool contains (const TableExprId& id, DComplex value);
    virtual Bool contains (const TableExprId& id, String value);
    virtual Bool contains (const TableExprId& id, MVTime value);
    virtual MArray<Bool> contains (const TableExprId& id,
                                   const MArray<Bool>& value);
    virtual MArray<Bool> contains (const TableExprId& id,
                                   const MArray<Int64>& value);
    virtual MArray<Bool> contains (const TableExprId& id,
                                   const MArray<Double>& value);
    virtual MArray<Bool> contains (const TableExprId& id,
                                   const MArray<DComplex>& value);
    virtual MArray<Bool> contains (const TableExprId& id,
                                   const MArray<String>& value);
    virtual MArray<Bool> contains (const TableExprId& id,
                                   const MArray<MVTime>& value);
    // </group>

    // Get the number of rows in the table associated with this expression.
    // One is returned if the expression is a constant or no table is
    // associated with it.
    rownr_t nrow();

    // Get the data type of the column.
    // It returns True when it could set the data type (which it can
    // if the expression is a scalar column or a constant array column pixel).
    // Otherwise it returns False.
    virtual Bool getColumnDataType (DataType&) const;

    // Get the value of the expression evaluated for the entire column.
    // The data of function called should match the data type as
    // returned by function <src>getColumnDataType</src>.
    // <group>
    virtual Array<Bool>     getColumnBool (const Vector<rownr_t>& rownrs);
    virtual Array<uChar>    getColumnuChar (const Vector<rownr_t>& rownrs);
    virtual Array<Short>    getColumnShort (const Vector<rownr_t>& rownrs);
    virtual Array<uShort>   getColumnuShort (const Vector<rownr_t>& rownrs);
    virtual Array<Int>      getColumnInt (const Vector<rownr_t>& rownrs);
    virtual Array<uInt>     getColumnuInt (const Vector<rownr_t>& rownrs);
    virtual Array<Int64>    getColumnInt64 (const Vector<rownr_t>& rownrs);
    virtual Array<Float>    getColumnFloat (const Vector<rownr_t>& rownrs);
    virtual Array<Double>   getColumnDouble (const Vector<rownr_t>& rownrs);
    virtual Array<Complex>  getColumnComplex (const Vector<rownr_t>& rownrs);
    virtual Array<DComplex> getColumnDComplex (const Vector<rownr_t>& rownrs);
    virtual Array<String>   getColumnString (const Vector<rownr_t>& rownrs);
    // </group>

    // Convert the tree to a number of range vectors which at least
    // select the same things.
    // This function is very useful to convert the expression to
    // some intervals covering the select expression. This can
    // be used to do a rough fast selection via an index and do the
    // the slower final selection on that much smaller subset.
    // The function can only convert direct comparisons of columns
    // with constants (via ==, !=, >, >=, < or <=) and their combinations
    // using && or ||.
    virtual void ranges (Block<TableExprRange>&);

    // Get the data type of the derived TableExprNode object.
    // This is the data type of the resulting value. E.g. a compare
    // of 2 numeric values results in a Bool, thus the data type
    // of, say, TableExprNodeEQ<T> is always Bool.
    // Function getInternalDT gives the internal data type, thus in
    // the example above the data type of T.
    NodeDataType dataType() const;

    // Is the data type real (i.e., integer or double)?
    Bool isReal() const;

    // Get the value type.
    ValueType valueType() const;

    // Set the value type.
    void setValueType (ValueType vtype);

    // Get the operator type.
    OperType operType() const;

    // Get the expression type.
    ExprType exprType() const;

    // Is the expression a constant?
    Bool isConstant() const;

    // Get the unit.
    const Unit& unit() const;

    // Set the unit.
    // It also sets the datatype to NTDouble if it is NTInt.
    void setUnit (const Unit& unit);

    // Get the attributes.
    const Record& attributes() const;

    // Set the attributes.
    void setAttributes (const Record&);
  
    // Get the fixed dimensionality (same for all rows).
    Int ndim() const;

    // Get the fixed shape (same for all rows).
    const IPosition& shape() const;

    // Get the shape for the given row.
    // It returns the fixed shape if defined, otherwise getShape(id).
    const IPosition& shape (const TableExprId& id);

    // Is the value in the given row defined?
    // The default implementation returns True.
    virtual Bool isDefined (const TableExprId& id);

    // Show the expression tree.
    virtual void show (ostream&, uInt indent) const;

    // Replace a node with a constant expression by node with its value.
    static TENShPtr replaceConstNode (const TENShPtr& node);

    // Let a set node convert itself to the given unit.
    // The default implementation does nothing.
    virtual void adaptSetUnits (const Unit&);

    // Create a range object from a column and an interval.
    static void createRange (Block<TableExprRange>&,
                             TableExprNodeColumn*, Double start, Double end);

    // Create a empty range object.
    static void createRange (Block<TableExprRange>&);

    // Convert a NodeDataType to a string.
    static String typeString (NodeDataType);

    // Convert a ValueType to a string.
    static String typeString (ValueType);

protected:
    NodeDataType      dtype_p;       //# data type of the operation
    ValueType         vtype_p;       //# value type of the result
    OperType          optype_p;      //# operator type
    ArgType           argtype_p;     //# argument types
    ExprType          exprtype_p;    //# Constant or Variable
    Int               ndim_p;        //# Fixed dimensionality of node values
                                     //# -1 = variable dimensionality
    IPosition         shape_p;       //# Fixed shape of node values
    Unit              unit_p;        //# Unit of the values
    Record            attributes_p;  //# Possible attributes (for UDFs)

    // Get the shape for the given row.
    virtual const IPosition& getShape (const TableExprId& id);

    // Set expression type to Variable if node is Variable.
    void fillExprType (const TableExprNodeRep* node);

    // If the node is constant, it is evaluated and replaced by
    // the appropriate TableExprNodeConst object.
    // If not constant, it calls the virtual ConvertConstChild function
    // which can convert a constant child if appropriate.
    static TENShPtr convertNode (const TENShPtr& thisNode,
                                 Bool convertConstType);
};





// <summary>
// Abstract base class for a node having 0, 1, or 2 child nodes.
// </summary>

// <use visibility=local>

// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
// </reviewed>

// <prerequisite>
//# Classes you should understand before using this one.
//   <li> <linkto class=TableExprNodeRep>TableExprNodeRep</linkto>
// </prerequisite>

// <etymology>
// TableExprNodeBinary is a node in the table expression tree
// representing a binary node (i.e. having up to 2 operands).
// </etymology>

// <synopsis> 
// TableExprNodeBinary is the abstract base class for all nodes in a table
// expression tree using up to 2 operands.
// It is used as the base class for the node classes representing
// operator +, -, etc..
// </synopsis> 

// <motivation>
// This class contains the common functionality for the classes
// representing a binary (or unary) operator.
// </motivation>

//# <todo asof="$DATE:$">
//# A List of bugs, limitations, extensions or planned refinements.
//#   <li> to be filled in
//# </todo>


class TableExprNodeBinary : public TableExprNodeRep
{
public:
    // Constructor
    TableExprNodeBinary (NodeDataType, ValueType, OperType, ExprType);
    TableExprNodeBinary (NodeDataType, const TableExprNodeRep&, OperType);

    // Destructor
    ~TableExprNodeBinary() override = default;
    
    // Show the expression tree.
    void show (ostream&, uInt indent) const override;

    // Flatten the node tree by adding the node and its children to the vector.
    void flattenTree (std::vector<TableExprNodeRep*>&) override;
  
    // Check the data types and get the common one.
    static NodeDataType getDT (NodeDataType leftDtype,
                               NodeDataType rightDype,
                               OperType operType);

    // Check the data and value types and get the common one.
    static TableExprNodeRep getCommonTypes (const TENShPtr& left,
                                            const TENShPtr& right,
                                            OperType operType);

    // Set the children.
    // If needed, their properties like data type and unit are adapted.
    void setChildren (const TENShPtr& left, const TENShPtr& right,
                      Bool adapt=True);

    // Handle the units of the children and possibly set the parent's unit.
    // The default implementation make the units of the children equal and
    // set the parent unit to that unit if the parent is not a Bool value.
    virtual void handleUnits();

    // If one of the children is a constant, convert its data type
    // to that of the other operand. This avoids that conversions are
    // done for each get.
    void adaptDataTypes();

    // Get the child nodes.
    // <group>
    const TENShPtr& getLeftChild() const
        { return lnode_p; }
    const TENShPtr& getRightChild() const
        { return rnode_p; }
    // </group>

protected:
    // Make the units equal.
    // Replace the right node if needed.
    static const Unit& makeEqualUnits (const TENShPtr& left,
                                       TENShPtr& right);

    TENShPtr lnode_p;     //# left operand
    TENShPtr rnode_p;     //# right operand
};




// <summary>
// Abstract base class for a node having multiple child nodes.
// </summary>

// <use visibility=local>

// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
// </reviewed>

// <prerequisite>
//# Classes you should understand before using this one.
//   <li> <linkto class=TableExprNodeRep>TableExprNodeRep</linkto>
// </prerequisite>

// <etymology>
// TableExprNodeMulti is a node in the table expression tree
// which can have MULTIple child nodes.
// </etymology>

// <synopsis> 
// TableExprNodeMulti is the abstract base class for all nodes in a table
// expression tree using multiple operands.
// It is used as the base class for the node classes representing
// functions, sets, indices, etc..
// </synopsis> 

// <motivation>
// This class contains the common functionality for the classes
// representing a node with multiple operands.
// </motivation>

//# <todo asof="$DATE:$">
//# A List of bugs, limitations, extensions or planned refinements.
//#   <li> to be filled in
//# </todo>


class TableExprNodeMulti : public TableExprNodeRep
{
public:
    // Constructor
    TableExprNodeMulti (NodeDataType, ValueType, OperType,
                        const TableExprNodeRep& source);

    // Destructor
    ~TableExprNodeMulti() override = default;

    // Show the expression tree.
    void show (ostream&, uInt indent) const override;

    // Flatten the node tree by adding the node and its children to the vector.
    void flattenTree (std::vector<TableExprNodeRep*>&) override;
  
    // Check number of arguments
    // low <= number_of_args <= high
    // It throws an exception if wrong number of arguments.
    static uInt checkNumOfArg (uInt low, uInt high,
                               const std::vector<TENShPtr>& nodes);
    
    // Get the child nodes.
    const std::vector<TENShPtr>& getChildren() const
      { return operands_p; }

    // Check datatype of nodes and return output type.
    // It also sets the expected data type of the operands (from dtIn).
    // Conversion of Int,Double.String to Date is by default possible.
    static NodeDataType checkDT (Block<Int>& dtypeOper,
                                 NodeDataType dtIn, NodeDataType dtOut,
                                 const std::vector<TENShPtr>& nodes,
                                 Bool dateConv=True);

protected:
    std::vector<TENShPtr> operands_p;
};



//# Get the data type of the node.
inline TableExprNodeRep::NodeDataType TableExprNodeRep::dataType() const
    { return dtype_p; }

inline Bool TableExprNodeRep::isReal() const
    { return dtype_p==NTInt || dtype_p==NTDouble; }

//# Get the value type of the node.
inline TableExprNodeRep::ValueType TableExprNodeRep::valueType() const
    { return vtype_p; }

//# Set the value type of the node.
inline void TableExprNodeRep::setValueType (TableExprNodeRep::ValueType vtype)
    { vtype_p = vtype; }

//# Get the operator type of the node.
inline TableExprNodeRep::OperType TableExprNodeRep::operType() const
    { return optype_p; }

//# Get the expression type of the node.
inline TableExprNodeRep::ExprType TableExprNodeRep::exprType() const
    { return exprtype_p; }

//# Is the expression a constant?
inline Bool TableExprNodeRep::isConstant() const
    { return  (exprtype_p == Constant); }

//# Get the unit of the node.
inline const Unit& TableExprNodeRep::unit() const
    { return unit_p; }

inline const Record& TableExprNodeRep::attributes() const
    { return attributes_p; }

inline void TableExprNodeRep::setAttributes (const Record& attributes)
    { attributes_p = attributes; }

//# Get the fixed dimensionality of the node.
inline Int TableExprNodeRep::ndim() const
    { return ndim_p; }

//# Get the fixed shape of the node.
inline const IPosition& TableExprNodeRep::shape() const
    { return shape_p; }


} //# NAMESPACE CASACORE - END

#endif