1 /***************************************************************************
2                           basegdl.hpp  -  base class for all data types
3                              -------------------
4     begin                : July 22 2002
5     copyright            : (C) 2002 by Marc Schellens
6     email                : m_schellens@users.sf.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef BASEGDL_HPP_
19 #define BASEGDL_HPP_
20 
21 #include "includefirst.hpp"
22 
23 //#include <list>
24 #if defined(__CYGWIN__) || defined(_WIN32)
25 #  include <rpc/xdr.h>
26 #else
27 #  include <rpc/rpc.h>
28 #endif
29 
30 #include <algorithm>
31 #include "dimension.hpp"
32 #include "gdlexception.hpp"
33 
34 #ifdef HAVE_MALLOC_H
35 #  include <malloc.h>
36 #endif
37 #ifdef HAVE_MALLOC_MALLOC_H
38 #  include <malloc/malloc.h>
39 #endif
40 #if (!defined(HAVE_MALLINFO) && !defined(HAVE_MALLINFO2))
41 #  if (!defined(HAVE_MALLOC_ZONE_STATISTICS) || !defined(HAVE_MALLOC_MALLOC_H))
42 #    if defined(HAVE_SBRK)
43 #      include <unistd.h>
44 #    endif
45 #  endif
46 #endif
47 
48 // GDL typecodes
49 enum DType {  // Object types (IDL type numbers)
50   GDL_UNDEF=0,    // 0 Undefined value, the default for new symbols
51   GDL_BYTE=1,     // 1 byte
52   GDL_INT,	      // 2 Integer scalar
53   GDL_LONG,	      // 3 long Integer scalar
54   GDL_FLOAT,      // 4 Real scalar
55   GDL_DOUBLE,     // 5 Double scalar
56   GDL_COMPLEX,    // 6 Complex scalar
57   GDL_STRING,     // 7 String
58   GDL_STRUCT,     // 8 Struct
59   GDL_COMPLEXDBL, // 9 Complex double
60   GDL_PTR,	      // 10 Pointer
61   GDL_OBJ,     // 11 Object reference
62   GDL_UINT,       // 12 unsigned int
63   GDL_ULONG,      // 13 unsigned long int
64   GDL_LONG64,     // 14 64 bit integer
65   GDL_ULONG64     // 15 unsigned 64 bit integer
66 
67   // not yet implemented
68 //  , GDL_LONG128  // 128 bit integer
69 //  , GDL_ULONG128 // unsigned 128 bit integer
70 
71 //  , GDL_LONGABI // arbitrary length int
72   //, GDL_ULONGABI // arbitrary length unsigned int (pointless)
73 
74 //  , GDL_LDOUBLE // long double  precision float (80 or 128bit)
75 //  , GDL_COMPLEXLDBL // Complex long double
76 //
77 //  , GDL_ARBITRARY // arbitrary precision float
78 //  , GDL_COMPLEXABI // Complex arbitrary
79 //
80 //  , GDL_RATIONAL // arbitrary length rational
81 //  , GDL_COMPLEXRAT // Complex arbitrary length rational
82 };
83 
84 // order of conversion precedence if two types are the same,
85 // the first type is used // used also by ArrayIndexT
86 const int DTypeOrder[]={
87   -1, 	//GDL_UNDEF
88   2, 	//GDL_BYTE
89   3, 	//GDL_INT
90   4, 	//GDL_LONG,
91   8, 	//GDL_FLOAT,
92   9, 	//GDL_DOUBLE,
93   20, 	//GDL_COMPLEX,
94   1, 	//GDL_STRING,
95   101, 	//GDL_STRUCT,
96   21, 	//GDL_COMPLEXDBL,
97   102, 	//GDL_PTR,
98   103, 	//GDL_OBJ, // must be highest number (see AdjustTypes... functions)
99   3, 	//GDL_UINT,
100   4, 	//GDL_ULONG,
101   5, 	//GDL_LONG64,
102   5 	//GDL_ULONG64
103 
104   // not yet implemented
105   ,6  //   , GDL_LONG128  // 128 bit integer
106   ,6  //   , GDL_ULONG128 // unsigned 128 bit integer
107     //
108   ,7  //   , GDL_LONGAB // arbitrary length int
109   // ,7  //   , GDL_ULONGAR // arbitrary length unsigned int (pointless)
110     //
111   ,10  //   , GDL_LDOUBLE // quad precision float (80 or 128bit)
112   ,22  //   , GDL_COMPLEXLDBL // Complex quad
113     //
114   ,11  //   , GDL_ARBITRARY // arbitrary precision float
115   ,23  //   , GDL_COMPLEXAR // Complex arbitrary
116     //
117   ,12  //   , GDL_RATIONAL // arbitrary length rational
118   ,24  //   , GDL_COMPLEXRAT // Complex arbitrary length rational
119 };
120 
121 
PromoteMatrixOperands(DType aTy,DType bTy)122 inline DType PromoteMatrixOperands( DType aTy, DType bTy)
123 {
124   DType maxTy=(DTypeOrder[aTy] >= DTypeOrder[bTy])? aTy: bTy;
125   if( maxTy == GDL_BYTE || maxTy == GDL_INT)
126     return GDL_LONG;
127   else if( maxTy == GDL_UINT)
128     return GDL_ULONG;
129   return maxTy;
130 }
131 
PromoteComplexOperand(DType aTy,DType bTy)132 inline DType PromoteComplexOperand( DType aTy, DType bTy)
133 {
134   if((aTy == GDL_COMPLEX && bTy == GDL_DOUBLE) ||
135      (bTy == GDL_COMPLEX && aTy == GDL_DOUBLE) )
136     return GDL_COMPLEXDBL;
137   return GDL_UNDEF;
138 }
139 
140 namespace gdl_type_lookup {
141 
142 const bool IsConvertableType[]={
143   false, 	//GDL_UNDEF
144   true, 	//GDL_BYTE
145   true, 	//GDL_INT
146   true, 	//GDL_LONG,
147   true, 	//GDL_FLOAT,
148   true, 	//GDL_DOUBLE,
149   true, 	//GDL_COMPLEX,
150   true, 	//GDL_STRING,
151   false, 	//GDL_STRUCT,
152   true, 	//GDL_COMPLEXDBL,
153   false, 	//GDL_PTR,
154   false, 	//GDL_OBJ,
155   true, 	//GDL_UINT,
156   true, 	//GDL_ULONG,
157   true, 	//GDL_LONG64,
158   true  	//GDL_ULONG64
159 };
160 const bool IsNumericType[]={
161   false, 	//GDL_UNDEF
162   true, 	//GDL_BYTE
163   true, 	//GDL_INT
164   true, 	//GDL_LONG,
165   true, 	//GDL_FLOAT,
166   true, 	//GDL_DOUBLE,
167   true, 	//GDL_COMPLEX,
168   false, 	//GDL_STRING,
169   false, 	//GDL_STRUCT,
170   true, 	//GDL_COMPLEXDBL,
171   false, 	//GDL_PTR,
172   false, 	//GDL_OBJ,
173   true, 	//GDL_UINT,
174   true, 	//GDL_ULONG,
175   true, 	//GDL_LONG64,
176   true  	//GDL_ULONG64
177 };
178 const bool IsIntType[]={
179   false, 	//GDL_UNDEF
180   true, 	//GDL_BYTE
181   true, 	//GDL_INT
182   true, 	//GDL_LONG,
183   false, 	//GDL_FLOAT,
184   false, 	//GDL_DOUBLE,
185   false, 	//GDL_COMPLEX,
186   false, 	//GDL_STRING,
187   false, 	//GDL_STRUCT,
188   false, 	//GDL_COMPLEXDBL,
189   false, 	//GDL_PTR,
190   false, 	//GDL_OBJ,
191   true, 	//GDL_UINT,
192   true, 	//GDL_ULONG,
193   true, 	//GDL_LONG64,
194   true  	//GDL_ULONG64
195 };
196 const bool IsRealType[]={
197   false, 	//GDL_UNDEF
198   true, 	//GDL_BYTE
199   true, 	//GDL_INT
200   true, 	//GDL_LONG,
201   true, 	//GDL_FLOAT,
202   true, 	//GDL_DOUBLE,
203   false, 	//GDL_COMPLEX,
204   false, 	//GDL_STRING,
205   false, 	//GDL_STRUCT,
206   false, 	//GDL_COMPLEXDBL,
207   false, 	//GDL_PTR,
208   false, 	//GDL_OBJ,
209   true, 	//GDL_UINT,
210   true, 	//GDL_ULONG,
211   true, 	//GDL_LONG64,
212   true  	//GDL_ULONG64
213 };
214 const bool IsNonPODType[]={
215   false, 	//GDL_UNDEF
216   false, 	//GDL_BYTE
217   false, 	//GDL_INT
218   false, 	//GDL_LONG,
219   false, 	//GDL_FLOAT,
220   false, 	//GDL_DOUBLE,
221   true, 	//GDL_COMPLEX,
222   true, 	//GDL_STRING,
223   true, 	//GDL_STRUCT,
224   true, 	//GDL_COMPLEXDBL,
225   true, 	//GDL_PTR, nonPOD due to reference counting
226   true, 	//GDL_OBJ, nonPOD due to reference counting
227   false, 	//GDL_UINT,
228   false, 	//GDL_ULONG,
229   false, 	//GDL_LONG64,
230   false 	//GDL_ULONG64
231 };
232  const bool IsLongLongType[] = {
233   false, //GDL_UNDEF
234   false, //GDL_BYTE
235   false, //GDL_INT
236   false, //GDL_LONG,
237   false, //GDL_FLOAT,
238   true, //GDL_DOUBLE,
239   false, //GDL_COMPLEX,
240   false, //GDL_STRING,
241   false, //GDL_STRUCT,
242   true, //GDL_COMPLEXDBL,
243   false, //GDL_PTR,
244   false, //GDL_OBJ,
245   false, //GDL_UINT,
246   false, //GDL_ULONG,
247   true, //GDL_LONG64,
248   true //GDL_ULONG64
249  };
250 
251 } //namespace gdl_type_lookup
252 
NonPODType(DType t)253 inline bool NonPODType( DType t)
254 {
255   return gdl_type_lookup::IsNonPODType[ t];
256 //   return (t == GDL_COMPLEX) || (t == GDL_COMPLEXDBL) || (t == GDL_STRING) || (t == GDL_STRUCT);
257 }
IntType(DType t)258 inline bool IntType( DType t)
259 {
260   return gdl_type_lookup::IsIntType[ t];
261 //   int o = DTypeOrder[ t];
262 //   return (o >= 2 && o <= 5);
263 }
FloatType(DType t)264 inline bool FloatType( DType t)
265 {
266   return (t == GDL_FLOAT || t == GDL_DOUBLE);
267 }
RealType(DType t)268 inline bool RealType( DType t) // Float or Int
269 {
270   return gdl_type_lookup::IsRealType[ t];
271 //   int o = DTypeOrder[ t];
272 //   return (o >= 2 && o <= 9);
273 }
ComplexType(DType t)274 inline bool ComplexType( DType t)
275 {
276   return (t == GDL_COMPLEX || t == GDL_COMPLEXDBL);
277 }
NumericType(DType t)278 inline bool NumericType( DType t) // Float or Int or Complex
279 {
280   return gdl_type_lookup::IsNumericType[ t];
281 //   int o = DTypeOrder[ t];
282 //   return (o >= 2 && o <= 11);
283 }
ConvertableType(DType t)284 inline bool ConvertableType( DType t) // everything except Struct, Ptr, Obj
285 {
286   return gdl_type_lookup::IsConvertableType[ t];
287 }
LongLongType(DType t)288 inline bool LongLongType( DType t) // POD but 64 bits
289 {
290   return gdl_type_lookup::IsLongLongType[ t];
291 }
292 class   BaseGDL;
293 class   ArrayIndexListT;
294 //class   ExprListT;
295 
296 //struct SpDULong;
297 //template<class> class Data_;
298 
299 struct ForLoopInfoT;
300 
301 void breakpoint();
302 
303 // --- SA: MemStats stuff
304 
305 class MemStats
306 {
307 
308 private:
309 
310   // SizeT has architecture-dependant size (32/64 bit)
311   static SizeT NumAlloc, NumFree, HighWater, Current;
312 
313 #if (!defined(HAVE_MALLINFO) && !defined(HAVE_MALLINFO2))
314 #  if (!defined(HAVE_MALLOC_ZONE_STATISTICS) || !defined(HAVE_MALLOC_MALLOC_H))
315 #    if defined(HAVE_SBRK)
316   static char* StartOfMemory;
317 #    endif
318 #  endif
319 #endif
320 
321 public:
322 
~MemStats()323   ~MemStats()
324   {
325     NumFree++;
326 #if defined(HAVE_MALLOC_ZONE_STATISTICS) && defined(HAVE_MALLOC_MALLOC_H)
327 // - the sbrk(0) does not give any meaningfull info for HIGHWATER
328 // - using mallinfo() frequently gives a large performace loss
329     UpdateCurrent(); // updates the highwater mark
330 #endif
331   }
332 
MemStats()333   MemStats() { NumAlloc++; }
334 
GetNumAlloc()335   static SizeT GetNumAlloc() { return NumAlloc; }
GetNumFree()336   static SizeT GetNumFree() { return NumFree; }
337 
GetCurrent()338   static SizeT GetCurrent()
339   {
340     UpdateCurrent(); // updates the highwater mark
341     return Current;
342   }
343 
344   // returns and resets the highwater mark (called from HELP and MEMORY())
GetHighWater()345   static SizeT GetHighWater()
346   {
347     // Current can be safely used as a temporary variable here
348     Current = HighWater;
349     HighWater = 0;
350     return Current;
351   }
352 
353   // returns current memory usage and updates the highwater mark
354   static void UpdateCurrent() ;
355 
356 
357 };
358 
359 // ---
360 class AllIxBaseT;
361 
362 class BaseGDL: private MemStats
363 {
364 public:
365   static DInterpreter* interpreter;
366 
367 protected:
368   dimension dim;
369 
370 public:
371   // type of initalization
372   enum InitType {
373     ZERO=0,
374     NOZERO,
375     INDGEN,
376     INIT,
377     NOALLOC
378   };
379 
380   enum Convert2Mode {
381     CONVERT=1,
382     COPY=2,
383     COPY_BYTE_AS_INT=(4|2),    // for GDL_STRING function
384     THROWIOERROR=8,            // for DStringGDL::Convert2()
385     COPY_THROWIOERROR=(8|2),   // for DStringGDL::Convert2()
386     CONVERT_THROWIOERROR=(8|1) // for DStringGDL::Convert2() (SA: used in NEWTON())
387   };
388 
389   enum IOMode {
390     FIXED=0,
391     SCIENTIFIC,
392     BIN=2,
393     OCT=8,
394     DEC=10,
395     HEX=16,
396     HEXL, // lower case characters
397     AUTO
398   };
399 
400   enum Cal_IOMode {
401       WRITE=-2,
402       COMPUTE=-1,
403       DEFAULT=0,
404       CMOA,
405       CMoA,
406       CmoA,
407       CMOI,
408       CDI,
409       CYI,
410       CHI,
411       ChI,
412       CMI,
413       CSI,
414       CSF,
415       CDWA,
416       CDwA,
417       CdwA,
418       CAPA,
419       CApA,
420       CapA,
421       STRING
422   };
423   // FIRST VIRTUAL FUNCTION'S GDL_OBJ FILE CONTAINS ALSO THE VTABLE
424   // therefore it must be defined non-inline (g++)
425   virtual ~BaseGDL(); // defined in basegdl.cpp
426 
427   BaseGDL();//: dim() {}
428   explicit BaseGDL(const dimension& dim_);//: dim(dim_) {}
429 
430 
431   // provide access to dim member
Dim() const432   inline const dimension& Dim()   const      { return dim;}
Dim(SizeT d) const433   inline SizeT    Dim(SizeT d)    const      { return dim[d];}
434 //   inline SizeT*   Dim0Address()              { return dim.Dim0Address();}
Stride(SizeT d) const435   inline SizeT    Stride(SizeT d) const      { return dim.Stride(d);}
Purge()436   inline void     Purge()                    { dim.Purge();}
Rank() const437   inline SizeT    Rank()          const      { return dim.Rank();}
EquivalentRank() const438   inline SizeT    EquivalentRank()          const      { return dim.EquivalentRank();}
SetDim(const dimension & d)439   inline void     SetDim(const dimension& d) { dim=d;}
MakeArrayFromScalar()440   inline void     MakeArrayFromScalar()      { dim.MakeArrayFromScalar();}
441 
operator >>(std::istream & i,BaseGDL & data_)442   friend std::istream& operator>>(std::istream& i, BaseGDL& data_)
443   {
444     throw GDLException("Variable is of type UNDEF.");
445     return i;
446   }
447 
448 //  private:
449   virtual BaseGDL& operator=(const BaseGDL& right);
450 //  public:
451 
452   virtual void InitFrom(const BaseGDL& right); // for structs
453 
454   // virtual functions
455   virtual bool IsAssoc() const;
456   virtual BaseGDL* AssocVar( int, SizeT);
457 
458   virtual SizeT N_Elements() const; // number of elements
459   virtual SizeT Size() const;       // size (= N_Elements, but 0 for BaseGDL)
460   virtual SizeT NBytes() const;     // total bytes of data
461   virtual SizeT ToTransfer() const; // elements to transfer
462   virtual SizeT Sizeof() const;     // size of scalar data
463 
464   virtual int HashCompare( BaseGDL* p2) const;
465 
466   virtual BaseGDL* Transpose( DUInt* perm);
467   virtual BaseGDL* Rotate( DLong dir);
468   virtual void Reverse( DLong dim);
469   virtual BaseGDL* DupReverse( DLong dim);
470 
471   virtual void MinMax( DLong* minE, DLong* maxE,
472 		       BaseGDL** minVal, BaseGDL** maxVal, bool omitNaN,
473                SizeT start = 0, SizeT stop = 0, SizeT step = 1, DLong valIx = -1, bool useAbs = false);
474 
475   virtual void Clear();
476   virtual void Construct();
477   virtual void ConstructTo0();
478   virtual void Destruct();
479   virtual std::ostream& Write( std::ostream& os, bool swapEndian,
480 			       bool compress, XDR *xdrs);
481   virtual std::istream& Read( std::istream& os, bool swapEndian,
482 			      bool compress, XDR *xdrs);
483 
484   virtual std::ostream& ToStream(std::ostream& o, SizeT width = 0,
485 			    SizeT* actPosPtr = NULL);
486   virtual std::istream& FromStream(std::istream& i);
487 
488   virtual bool Greater(SizeT i1, SizeT i2) const; // comp 2 elements
489   virtual bool Equal(SizeT i1, SizeT i2) const; // comp 2 elements
490 
491   virtual BaseGDL* CShift( DLong d) const; // circular shift
492   virtual BaseGDL* CShift( DLong d[MAXRANK]) const; // circular shift multi dim
493 
494 //  virtual bool OutOfRangeOfInt() const;
495 
496   virtual bool Scalar() const;
497   virtual bool StrictScalar() const;
498   virtual DType   Type() const;
499   virtual const std::string& TypeStr() const;
500   virtual bool          EqType( const BaseGDL*) const;
501   virtual void* DataAddr();// SizeT elem=0);
502   virtual BaseGDL* New( const dimension& dim_, InitType noZero=ZERO) const;
503   virtual BaseGDL* NewResult() const;
504   virtual BaseGDL* Dup() const;
505 //   virtual BaseGDL* Dup( char*) const;
506   virtual BaseGDL* Convert2( DType destTy, Convert2Mode mode=CONVERT);
507   virtual BaseGDL* GetTag() const;
508   virtual BaseGDL* GetInstance() const;
509   virtual BaseGDL* GetEmptyInstance() const;
510   virtual BaseGDL* SetBuffer( const void* b);
511   virtual void     SetBufferSize( SizeT s);
512   virtual int Scalar2Index(SizeT& ret) const;
513   virtual int Scalar2RangeT(RangeT& ret) const;
514   virtual SizeT GetAsIndex( SizeT i) const;
515   virtual SizeT GetAsIndexStrict( SizeT i) const;
516   virtual RangeT LoopIndex() const;
517   virtual DDouble HashValue() const;
518 
519   virtual bool True();
520   virtual bool False();
521   virtual bool LogTrue();
522   virtual bool LogTrue( SizeT ix);
523   virtual void Where(DLong* &ret, SizeT &passed_count, bool comp, DLong* &comp_ret) ;
524   virtual void Where(DLong64* &ret, SizeT &passed_count, bool comp, DLong64* &comp_ret) ;
525   virtual BaseGDL* LogNeg();
526   virtual int Sgn(); // -1,0,1
527   virtual bool Equal( BaseGDL*) const;
528   virtual bool EqualNoDelete( const BaseGDL*) const;
529   virtual bool ArrayEqual( BaseGDL*);
530   virtual bool ArrayNeverEqual( BaseGDL*);
531 
532   // for statement compliance (int types , float types scalar only)
533   virtual bool ForCheck( BaseGDL**, BaseGDL** = NULL);
534   virtual bool ForCondUp( BaseGDL*);
535   virtual bool ForCondDown( BaseGDL*);
536   virtual bool ForAddCondUp( BaseGDL* loopInfo);
537 //   virtual bool ForAddCondUp( ForLoopInfoT& loopInfo);
538 //  virtual bool ForAddCondDown( ForLoopInfoT& loopInfo);
539 //   virtual bool ForCondUpDown( BaseGDL*);
540   virtual void ForAdd( BaseGDL* add=NULL);
541   virtual BaseGDL* CatArray( ExprListT& exprList,
542 			     const SizeT catRank,
543 			     const SizeT rank);
544   virtual BaseGDL* Index( ArrayIndexListT* ixList);
545   //  virtual BaseGDL* Abs() const;
546 
547   // return a new type of itself
548   virtual BaseGDL* NewIx( SizeT ix);
549   virtual BaseGDL* NewIx( BaseGDL* ix, bool strict);
550   virtual BaseGDL* NewIx( AllIxBaseT* ix, const dimension* dIn);
551   virtual BaseGDL* NewIxFrom( SizeT s);
552   virtual BaseGDL* NewIxFrom( SizeT s, SizeT e);
553   virtual BaseGDL* NewIxFromStride( SizeT s, SizeT stride);
554   virtual BaseGDL* NewIxFromStride( SizeT s, SizeT e, SizeT stride);
555 
556   // library functions
557   virtual BaseGDL* Convol( BaseGDL* kIn, BaseGDL* scaleIn, BaseGDL* bias,
558  			   bool center, bool normalize, int edgeMode,
559                                 bool doNan, BaseGDL* missing, bool doMissing,
560                                 BaseGDL* invalid, bool doInvalid);
561   virtual BaseGDL* Smooth( DLong* width, int edgeMode,
562                                 bool doNan, BaseGDL* missing);
563   virtual BaseGDL* Rebin( const dimension& newDim, bool sample);
564   // for STRUCT_ASSIGN
565   virtual void Assign( BaseGDL* src, SizeT nEl);
566 
567   virtual BaseGDL* Log();
568   virtual BaseGDL* LogThis();
569   virtual BaseGDL* Log10();
570   virtual BaseGDL* Log10This();
571 
572   // defined in basic_op.cpp
573   // used in r_expr
574   virtual BaseGDL* UMinus();
575   virtual BaseGDL* NotOp();
576 
577   virtual BaseGDL* AndOp( BaseGDL* r);
578   virtual BaseGDL* AndOpInv( BaseGDL* r);
579   virtual BaseGDL* OrOp( BaseGDL* r);
580   virtual BaseGDL* OrOpInv( BaseGDL* r);
581   virtual BaseGDL* XorOp( BaseGDL* r);
582   virtual BaseGDL* EqOp( BaseGDL* r);
583   virtual BaseGDL* NeOp( BaseGDL* r);
584   virtual BaseGDL* LeOp( BaseGDL* r);
585   virtual BaseGDL* GeOp( BaseGDL* r);
586   virtual BaseGDL* LtOp( BaseGDL* r);
587   virtual BaseGDL* GtOp( BaseGDL* r);
588   virtual BaseGDL* Add( BaseGDL* r);
589   virtual BaseGDL* AddInv( BaseGDL* r);
590   virtual BaseGDL* Sub( BaseGDL* r);
591   virtual BaseGDL* SubInv( BaseGDL* r);
592   virtual BaseGDL* LtMark( BaseGDL* r);
593   virtual BaseGDL* GtMark( BaseGDL* r);
594   virtual BaseGDL* Mult( BaseGDL* r);
595   virtual BaseGDL* Div( BaseGDL* r);
596   virtual BaseGDL* DivInv( BaseGDL* r);
597   virtual BaseGDL* Mod( BaseGDL* r);
598   virtual BaseGDL* ModInv( BaseGDL* r);
599   virtual BaseGDL* Pow( BaseGDL* r);
600   virtual BaseGDL* PowInv( BaseGDL* r);
601   virtual BaseGDL* PowInt( BaseGDL* r);
602 
603   virtual BaseGDL* AndOpS( BaseGDL* r);
604   virtual BaseGDL* AndOpInvS( BaseGDL* r);
605   virtual BaseGDL* OrOpS( BaseGDL* r);
606   virtual BaseGDL* OrOpInvS( BaseGDL* r);
607   virtual BaseGDL* XorOpS( BaseGDL* r);
608   virtual BaseGDL* AddS( BaseGDL* r);
609   virtual BaseGDL* AddInvS( BaseGDL* r);
610   virtual BaseGDL* SubS( BaseGDL* r);
611   virtual BaseGDL* SubInvS( BaseGDL* r);
612   virtual BaseGDL* LtMarkS( BaseGDL* r);
613   virtual BaseGDL* GtMarkS( BaseGDL* r);
614   virtual BaseGDL* MultS( BaseGDL* r);
615   virtual BaseGDL* DivS( BaseGDL* r);
616   virtual BaseGDL* DivInvS( BaseGDL* r);
617   virtual BaseGDL* ModS( BaseGDL* r);
618   virtual BaseGDL* ModInvS( BaseGDL* r);
619   virtual BaseGDL* PowS( BaseGDL* r);
620   virtual BaseGDL* PowInvS( BaseGDL* r);
621 
622 
623 
624 
625 
626 // the New functions
627 // defined in basic_op_new.cpp
628 // results go into a new DataT
629 
630   virtual BaseGDL* AndOpNew( BaseGDL* r);
631   virtual BaseGDL* AndOpInvNew( BaseGDL* r);
632   virtual BaseGDL* OrOpNew( BaseGDL* r);
633   virtual BaseGDL* OrOpInvNew( BaseGDL* r);
634   virtual BaseGDL* XorOpNew( BaseGDL* r);
635 //   virtual BaseGDL* EqOpNew( BaseGDL* r);
636 //   virtual BaseGDL* NeOpNew( BaseGDL* r);
637 //   virtual BaseGDL* LeOpNew( BaseGDL* r);
638 //   virtual BaseGDL* GeOpNew( BaseGDL* r);
639 //   virtual BaseGDL* LtOpNew( BaseGDL* r);
640 //   virtual BaseGDL* GtOpNew( BaseGDL* r);
641   virtual BaseGDL* AddNew( BaseGDL* r);      // implemented
642   virtual BaseGDL* AddInvNew( BaseGDL* r);      // implemented
643   virtual BaseGDL* SubNew( BaseGDL* r);
644   virtual BaseGDL* SubInvNew( BaseGDL* r);
645   virtual BaseGDL* LtMarkNew( BaseGDL* r);
646   virtual BaseGDL* GtMarkNew( BaseGDL* r);
647   virtual BaseGDL* MultNew( BaseGDL* r);   // implemented
648   virtual BaseGDL* DivNew( BaseGDL* r);
649   virtual BaseGDL* DivInvNew( BaseGDL* r);
650   virtual BaseGDL* ModNew( BaseGDL* r);
651   virtual BaseGDL* ModInvNew( BaseGDL* r);
652   virtual BaseGDL* PowNew( BaseGDL* r);
653   virtual BaseGDL* PowInvNew( BaseGDL* r);
654   virtual BaseGDL* PowIntNew( BaseGDL* r);   // implemented
655 
656   virtual BaseGDL* AndOpSNew( BaseGDL* r);
657   virtual BaseGDL* AndOpInvSNew( BaseGDL* r);
658   virtual BaseGDL* OrOpSNew( BaseGDL* r);
659   virtual BaseGDL* OrOpInvSNew( BaseGDL* r);
660   virtual BaseGDL* XorOpSNew( BaseGDL* r);
661   virtual BaseGDL* AddSNew( BaseGDL* r);         // implemented
662   virtual BaseGDL* AddInvSNew( BaseGDL* r);    // implemented
663   virtual BaseGDL* SubSNew( BaseGDL* r);
664   virtual BaseGDL* SubInvSNew( BaseGDL* r);
665   virtual BaseGDL* LtMarkSNew( BaseGDL* r);
666   virtual BaseGDL* GtMarkSNew( BaseGDL* r);
667   virtual BaseGDL* MultSNew( BaseGDL* r);      // implemented
668   virtual BaseGDL* DivSNew( BaseGDL* r);
669   virtual BaseGDL* DivInvSNew( BaseGDL* r);
670   virtual BaseGDL* ModSNew( BaseGDL* r);
671   virtual BaseGDL* ModInvSNew( BaseGDL* r);
672   virtual BaseGDL* PowSNew( BaseGDL* r);
673   virtual BaseGDL* PowInvSNew( BaseGDL* r);
674 
675 
676 
677   //  virtual BaseGDL* PowInvNew( BaseGDL* r);
678   virtual BaseGDL* MatrixOp( BaseGDL* r, bool atranspose=false, bool btranspose=false);
679   virtual void AssignAt( BaseGDL* srcIn, ArrayIndexListT* ixList, SizeT offset);
680   virtual void AssignAt( BaseGDL* srcIn, ArrayIndexListT* ixList);
681   virtual void AssignAt( BaseGDL* srcIn);
682 
683   virtual void AssignAtIx( RangeT ix, BaseGDL* srcIn);
684 
685   virtual void DecAt( ArrayIndexListT* ixList);
686   virtual void IncAt( ArrayIndexListT* ixList);
687   virtual void Dec();
688   virtual void Inc();
689   virtual void InsertAt(  SizeT offset, BaseGDL* srcIn, ArrayIndexListT* ixList);
690 
691   // virtual formatting output functions
692   virtual SizeT OFmtA( std::ostream* os, SizeT offset, SizeT num, int width, int code);
693   virtual SizeT OFmtF( std::ostream* os, SizeT offs, SizeT num, int width, int prec, const int code=0, const BaseGDL::IOMode oM = FIXED);
694   virtual SizeT OFmtI( std::ostream* os, SizeT offs, SizeT num, int width, int minN, int code=0, BaseGDL::IOMode oM = DEC);
695   virtual SizeT OFmtCal( std::ostream* os, SizeT offs, SizeT num, int width, int minN, char *fill, int code=0, BaseGDL::Cal_IOMode oM = DEFAULT);
696   virtual SizeT IFmtA( std::istream* is, SizeT offset, SizeT num, int width);
697   virtual SizeT IFmtF( std::istream* is, SizeT offs, SizeT num, int width);
698   virtual SizeT IFmtI( std::istream* is, SizeT offs, SizeT num, int width,
699 			BaseGDL::IOMode oM = DEC);
700   virtual SizeT IFmtCal( std::istream* is, SizeT offs, SizeT r, int width, BaseGDL::Cal_IOMode cMode);
701 
702 #if defined(USE_PYTHON) || defined(PYTHON_MODULE)
703 
704   virtual PyObject* ToPython();
705 #endif
706 
Test2()707   virtual bool Test2() {return false;}
708 
709 };
710 
711 
712 // ExprListT deletes all members upon own destruction
713 
714 // old slow version (up to GDL 0.9.1):
715 // class ExprListT: public std::vector<BaseGDL*>
716 // {
717 // public:
718 // 	ExprListT()
719 // 	{
720 // 	this->reserve(ExprListDefaultLength);
721 // 	}
722 // 	~ExprListT()
723 // 	{
724 // 	for( ExprListT::iterator i=this->begin(); i!=this->end(); ++i)
725 // 		delete *i;
726 // 	}
727 // };
728 
729 
730 struct ForLoopInfoT
731 {
732   BaseGDL*  endLoopVar; // the source for foreach as well
733   BaseGDL*  loopStepVar;
734   DLong     foreachIx;
735 //   bool      isHash; // only used in FOREACH_INDEXNode::Run() and FOREACH_INDEX_LOOPNode::Run()
736 
ForLoopInfoTForLoopInfoT737   ForLoopInfoT()
738   : endLoopVar(NULL)
739   , loopStepVar(NULL)
740   , foreachIx(-1)
741   {}
~ForLoopInfoTForLoopInfoT742   ~ForLoopInfoT()
743   {
744 	  delete endLoopVar;
745 	  delete loopStepVar;
746   }
InitForLoopInfoT747   void Init()
748   {
749 	  endLoopVar = NULL;
750 	  loopStepVar = NULL;
751 	  foreachIx = -1;
752   }
ClearForLoopInfoT753   void Clear()
754   {
755 	  delete endLoopVar;
756 	  delete loopStepVar;
757   }
ClearInitForLoopInfoT758   void ClearInit()
759   {
760 	  delete endLoopVar;
761 	  endLoopVar = NULL;
762 	  delete loopStepVar;
763 	  loopStepVar = NULL;
764   }
765 };
766 
767 // before NullGDL instance must not be deleted, now this is fine (overloaded operators new and delete)
768 // inline void GDLDelete( BaseGDL* toDelete) { delete toDelete;}
769 void GDLDelete( BaseGDL* toDelete);
770 
771 #endif
772 
773