1 /***************************************************************************
2                           objects.hpp  -  global structures
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 OBJECTS_HPP_
19 #define OBJECTS_HPP_
20 
21 //#include<deque>
22 #include<string>
23 
24 #include "datatypes.hpp"
25 
26 #include "dvar.hpp"
27 #include "dpro.hpp"
28 #include "dcommon.hpp"
29 #include "envt.hpp"
30 #include "io.hpp"
31 
32 #ifdef USE_PYTHON
33 #include "gdlpython.hpp"
34 #endif
35 
36 // class DInterpreter;
37 // extern DInterpreter* interpreter;
38 
39 const std::string GDL_OBJECT_NAME("GDL_OBJECT");
40 const std::string GDL_CONTAINER_NAME("GDL_CONTAINER");
41 
42 extern VarListT      sysVarList;
43 extern VarListT      obsoleteSysVarList;
44 extern VarListT      sysVarRdOnlyList;
45 extern VarListT      sysVarNoSaveList;
46 
47 extern FunListT      funList;
48 extern ProListT      proList;
49 extern LibFunListT   libFunList;
50 extern LibProListT   libProList;
51 
52 extern CommonListT   commonList;   // common blocks
53 extern StructListT   structList;
54 
55 extern GDLFileListT  fileUnits;
56 
57 // for OpenMP
58 const SizeT DefaultTPOOL_MIN_ELTS = 100000;
59 const SizeT DefaultTPOOL_MAX_ELTS = 0;
60 extern DLong CpuTPOOL_NTHREADS;
61 extern DLong64 CpuTPOOL_MIN_ELTS;
62 extern DLong64 CpuTPOOL_MAX_ELTS;
63 
64 //extern DeviceListT   deviceList;
65 //extern Graphics*     actDevice;
66 
67 // signals if control-c was pressed
68 extern volatile bool sigControlC;
69 
70 extern volatile bool iAmANotebook;
71 // tells if wxwidgets is to be used at all...
72 extern volatile bool useWxWidgets;
73 // tells if wxwidgets backend for graphics is to be used...
74 extern volatile bool useWxWidgetsForGraphics;
75 // do we force fonts to be the ugly IDL fonts?
76 extern volatile bool forceWxWidgetsUglyFonts;
77 //do we favor SIMD-accelerated random number generation?
78 extern volatile bool useDSFMTAcceleration;
79 extern volatile bool usePlatformDeviceName;
80 extern          int  debugMode;
81 
82 enum DebugCode {
83   DEBUG_CLEAR=0,
84   DEBUG_STOP = 1,
85   DEBUG_PROCESS_STOP = 2,
86   DEBUG_STEP = 3,
87   DEBUG_STEPOVER= 4
88 };
89 
PurgeContainer(Container & s)90 template< class Container> void PurgeContainer( Container& s)
91 {
92   typename Container::iterator i;
93   for(i = s.begin(); i != s.end(); ++i)
94     { delete *i;}// *i = NULL;}
95   s.clear();
96 }
97 
98 void InitGDL(); // defined in gdl.cpp
99 
100 void InitObjects();
101 void ResetObjects();
102 
103 DLong GetLUN();
104 
105 int ProIx(const std::string& n);
106 int FunIx(const std::string& n);
107 
108 int LibProIx(const std::string& n);
109 int LibFunIx(const std::string& n);
110 
111 bool IsFun(antlr::RefToken); // used by Lexer and Parser
112 bool IsRelaxed(); //tells if syntax is not strict (i.e. parenthesis for array indexes).
113 void SetStrict(bool value);
114 
115 bool BigEndian();
116 
117 int get_suggested_omp_num_threads();
118 int currentNumberOfThreads();
119 int currentThreadNumber();
120 
121 template <typename T> class RefHeap {
122   private:
123     T* ptr;
124     SizeT count;
125     // 2016.05.13 GJ:
126     bool doSave; // IDL 6.1 flag whether to include in a SAVE operation (HEAP_SAVE)
127     // access via HEAP_SAVE( Heapvars) and HEAP_NOSAVE( Heapvars [,SET=[0/1]])
128     bool enableGC;   // IDL 8.0 flag whether to perform automatic garbage collection
129     // access via HEAP_REFCOUNT([,/ENABLE] [,/DISABLE] [,IS_ENABLED=])
130     // prevent usage
operator =(const RefHeap<T> & other)131     RefHeap<T>& operator=(const RefHeap<T>& other) {	return *this;}
operator RefHeap<newType>()132     template<class newType> operator RefHeap<newType>() {return RefHeap<newType>(ptr);}
133 
134 
135   public:
136 
Count() const137     SizeT Count() const { return count;}
138 
IsEnabledGC() const139 	bool IsEnabledGC() const {	return enableGC; }
EnableGC(bool set=true)140 	void EnableGC( bool set=true) { enableGC = set; }
141 
IsEnabledSave() const142 	bool IsEnabledSave() const { return doSave; }
EnableSave(bool set=true)143 	void EnableSave( bool set=true) { doSave = set; }
144 
Inc()145     void Inc() {++count;}
Add(SizeT add)146     void Add( SizeT add) {count += add;}
Dec()147     bool Dec() {assert(count > 0); return (--count==0);}
148 
RefHeap(T * p=0)149     RefHeap(T* p = 0)
150     : ptr(p), count(1), doSave(false), enableGC(true)
151     {}
152 
RefHeap(const RefHeap<T> & other)153     RefHeap( const RefHeap<T>& other)
154     : ptr( other.ptr), count( other.count),  doSave( other.doSave), enableGC( other.enableGC)
155     {}
156 
~RefHeap()157     ~RefHeap()
158     {}
159 
operator T*() const160     operator T* () const
161     {
162       return ptr;
163     }
164 
operator ->() const165     T* operator->() const
166     {
167       return ptr;
168     }
169 
get()170     T*& get()
171     {
172       return ptr;
173     }
174 };
175 
176 namespace structDesc {
177 
178   // these are used mainly in list.cpp and hash.cpp
179   // as for .RESET_SESSION the pointers change
180   // one can still use these as they get updated on every new creation in InitStructs()
181   extern DStructDesc* LIST;
182   extern DStructDesc* HASH;
183   extern DStructDesc* GDL_CONTAINER;
184   extern DStructDesc* GDL_CONTAINER_NODE;
185   extern DStructDesc* GDL_HASHTABLEENTRY;
186 
187 }
188 
189 #endif
190