source: Sophya/trunk/SophyaLib/BaseTools/sophyainit.cc@ 3113

Last change on this file since 3113 was 3016, checked in by ansari, 19 years ago

modification SophyaInitiator avec enregistrement list de modules - pret pour tag V2 Reza 17/7/2006

File size: 9.0 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3
4#include <unistd.h>
5#include <stdlib.h>
6#include <stdio.h>
7#include <complex>
8
9#include "sophyainit.h"
10
11#include "pexceptions.h"
12
13#include "ppersist.h"
14#include "fiondblock.h"
15#include "dvlist.h"
16
17#include "fiosegdb.h"
18#include "ppfwrapstlv.h"
19
20#include "sversion.h"
21
22#include <iostream>
23#include <map>
24
25// --- Classe d'initialisation de SOPHYA, (PPersistMgr en particulier)
26int SophyaInitiator::FgInit = 0;
27// Module version number - 2.0 , Jul 2006
28#define MOD_VERS 2.0
29
30// Pour garder la liste des modules et leurs numeros de version
31map<string, double>* ModListP = NULL;
32
33/*!
34 \namespace SOPHYA
35 \brief This is the namespace for the whole Sophya package
36*/
37
38/*!
39 \class SOPHYA::SophyaInitiator
40 \ingroup BaseTools
41 Each Sophya module may contain an initialiser class which should
42 be a sub-class of SophyaInitiator.
43*/
44
45
46SophyaInitiator::SophyaInitiator()
47{
48#if defined(Darwin)
49 // Il semble y avoir un probleme sous MacOSX ...
50 if (FgInit == 0)
51 cout << " SophyaInitiator::SophyaInitiator() BaseTools Init" << endl;
52#endif
53 FgInit++;
54 if (FgInit > 1) return;
55
56 InitFailNewHandler();
57 ModListP = new map<string, double>;
58
59
60 #ifdef xx__mac__
61 //InitToolBox();
62 //SIOUXSettings.initializeTB = FALSE;
63 SIOUXSettings.autocloseonquit = FALSE;
64 SIOUXSettings.asktosaveonclose = FALSE;
65 SIOUXSettings.showstatusline = TRUE;
66 #endif
67
68 // Initialisation des mecanismes PPF I/O
69 PIOPersist::Initialize();
70 // Enregistrement des handlers PPF pour les NDataBlock<T>
71 PPRegister(FIO_NDataBlock<uint_1>);
72 DObjRegister(FIO_NDataBlock<uint_1>, NDataBlock<uint_1>);
73 PPRegister(FIO_NDataBlock<uint_2>);
74 DObjRegister(FIO_NDataBlock<uint_2>, NDataBlock<uint_2>);
75 PPRegister(FIO_NDataBlock<int_2>);
76 DObjRegister(FIO_NDataBlock<int_2>, NDataBlock<int_2>);
77 PPRegister(FIO_NDataBlock<int_4>);
78 DObjRegister(FIO_NDataBlock<int_4>, NDataBlock<int_4>);
79 PPRegister(FIO_NDataBlock<int_8>);
80 DObjRegister(FIO_NDataBlock<int_8>, NDataBlock<int_8>);
81 PPRegister(FIO_NDataBlock<uint_4>);
82 DObjRegister(FIO_NDataBlock<uint_4>, NDataBlock<uint_4>);
83 PPRegister(FIO_NDataBlock<uint_8>);
84 DObjRegister(FIO_NDataBlock<uint_8>, NDataBlock<uint_8>);
85 PPRegister(FIO_NDataBlock<r_4>);
86 DObjRegister(FIO_NDataBlock<r_4>, NDataBlock<r_4>);
87 PPRegister(FIO_NDataBlock<r_8>);
88 DObjRegister(FIO_NDataBlock<r_8>, NDataBlock<r_8>);
89 PPRegister(FIO_NDataBlock< complex<r_4> >);
90 DObjRegister(FIO_NDataBlock< complex<r_4> >, NDataBlock< complex<r_4> >);
91 PPRegister(FIO_NDataBlock< complex<r_8> >);
92 DObjRegister(FIO_NDataBlock< complex<r_8> >, NDataBlock< complex<r_8> >);
93
94 // Enregistrement des handlers PPF pour les TimeStamp
95 PPRegister(ObjFileIO<TimeStamp>);
96 DObjRegister(ObjFileIO<TimeStamp>, TimeStamp);
97
98 // Enregistrement des handlers PPF pour les DVList
99 PPRegister(ObjFileIO<DVList>);
100 DObjRegister(ObjFileIO<DVList>, DVList);
101
102 // Enregistrement des handlers PPF pour les SegDataBlock<T>
103 PPRegister(FIO_SegDataBlock<uint_2>);
104 DObjRegister(FIO_SegDataBlock<uint_2>, SegDataBlock<uint_2>);
105 PPRegister(FIO_SegDataBlock<int_2>);
106 DObjRegister(FIO_SegDataBlock<int_2>, SegDataBlock<int_2>);
107 PPRegister(FIO_SegDataBlock<int_4>);
108 DObjRegister(FIO_SegDataBlock<int_4>, SegDataBlock<int_4>);
109 PPRegister(FIO_SegDataBlock<int_8>);
110 DObjRegister(FIO_SegDataBlock<int_8>, SegDataBlock<int_8>);
111 PPRegister(FIO_SegDataBlock<uint_4>);
112 DObjRegister(FIO_SegDataBlock<uint_4>, SegDataBlock<uint_4>);
113 PPRegister(FIO_SegDataBlock<uint_8>);
114 DObjRegister(FIO_SegDataBlock<uint_8>, SegDataBlock<uint_8>);
115 PPRegister(FIO_SegDataBlock<r_4>);
116 DObjRegister(FIO_SegDataBlock<r_4>, SegDataBlock<r_4>);
117 PPRegister(FIO_SegDataBlock<r_8>);
118 DObjRegister(FIO_SegDataBlock<r_8>, SegDataBlock<r_8>);
119 PPRegister(FIO_SegDataBlock< complex<r_4> >);
120 DObjRegister(FIO_SegDataBlock< complex<r_4> >, SegDataBlock< complex<r_4> >);
121 PPRegister(FIO_SegDataBlock< complex<r_8> >);
122 DObjRegister(FIO_SegDataBlock< complex<r_8> >, SegDataBlock< complex<r_8> >);
123 PPRegister(FIO_SegDataBlock<string>);
124 DObjRegister(FIO_SegDataBlock<string>, SegDataBlock<string>);
125
126 // Enregistrement des handlers PPF pour les vecteurs de la STL
127 PPRegister(PPFWrapperSTLVector<uint_2>);
128 DObjRegister(PPFWrapperSTLVector<uint_2>, std::vector<uint_2>);
129 PPRegister(PPFWrapperSTLVector<int_2>);
130 DObjRegister(PPFWrapperSTLVector<int_2>, std::vector<int_2>);
131 PPRegister(PPFWrapperSTLVector<int_4>);
132 DObjRegister(PPFWrapperSTLVector<int_4>, std::vector<int_4>);
133 PPRegister(PPFWrapperSTLVector<int_8>);
134 DObjRegister(PPFWrapperSTLVector<int_8>, std::vector<int_8>);
135 PPRegister(PPFWrapperSTLVector<uint_4>);
136 DObjRegister(PPFWrapperSTLVector<uint_4>, std::vector<uint_4>);
137 PPRegister(PPFWrapperSTLVector<uint_8>);
138 DObjRegister(PPFWrapperSTLVector<uint_8>, std::vector<uint_8>);
139 PPRegister(PPFWrapperSTLVector<r_4>);
140 DObjRegister(PPFWrapperSTLVector<r_4>, std::vector<r_4>);
141 PPRegister(PPFWrapperSTLVector<r_8>);
142 DObjRegister(PPFWrapperSTLVector<r_8>, std::vector<r_8>);
143 PPRegister(PPFWrapperSTLVector< complex<r_4> >);
144 DObjRegister(PPFWrapperSTLVector< complex<r_4> >, std::vector< complex<r_4> >);
145 PPRegister(PPFWrapperSTLVector< complex<r_8> >);
146 DObjRegister(PPFWrapperSTLVector< complex<r_8> >, std::vector< complex<r_8> >);
147 PPRegister(PPFWrapperSTLVector< string >);
148 DObjRegister(PPFWrapperSTLVector< string >, std::vector<string>);
149
150 PPRegister(PPFWrapperSTLVector< TimeStamp >);
151 DObjRegister(PPFWrapperSTLVector< TimeStamp >, std::vector<TimeStamp>);
152
153
154#if (!defined(__GNUG__) && !defined(__MWERKS__) && !defined(HPUX))
155 // pas de bufferisation pour printf cmv 18/3/97 selon E.A.
156 // setvbuf(stdout,NULL,_IOLBF,0); setvbuf(stderr,NULL,_IOLBF,0);
157 setlinebuf(stdout);
158 setlinebuf(stderr);
159#endif
160
161 // si var env SOPHYA_NOPRTVER definie pas de print
162 if(!getenv("SOPHYA_NOPRTVER")) PrintVersion(false);
163
164 int pnice;
165 char* snice = getenv("SOPHYA_NICE");
166 if (!snice) pnice=8;
167 else pnice = atoi(snice);
168 nice(pnice);
169
170 SophyaInitiator::RegisterModule("BaseTools", MOD_VERS); // Module name and version number registration
171}
172
173SophyaInitiator::~SophyaInitiator()
174{
175 FgInit--;
176/*
177 if (FgInit == 0)
178 {
179 delete PPersistMgr::classList; PPersistMgr::classList = NULL;
180 delete PShPersist::objList; PShPersist::objList = NULL;
181 }
182 */
183}
184
185/*!
186 \brief Return the SOPHYA version number.
187 \param svers contain the complete in addition the SOPHYA tag, the compiler name
188 and the compilation date
189*/
190double SophyaInitiator::GetVersion(string& svers)
191{
192 char* compiler = 0;
193 #ifdef __GNUG__
194 compiler = "gcc " __VERSION__;
195 #endif
196 #ifdef __DECCXX
197 compiler = "cxx " ;
198 #endif
199 #ifdef __aCC__
200 compiler = const_cast<char *>("HP-aCC ") ;
201 #endif
202 #ifdef __KCC__
203 compiler = const_cast<char *>("KCC ") ;
204 #endif
205 #ifdef __IBMCPP__
206 compiler = const_cast<char *>("IBM-xlC ") ;
207 #endif
208 #ifdef __INTEL_COMPILER
209 compiler = const_cast<char *>("Intel-icc ") ;
210 #endif
211 #ifdef __SGICC__
212 #ifdef SGI_ARCH64
213 compiler = const_cast<char *>("SGI-CC (-64) ") ;
214 #else
215 compiler = const_cast<char *>("SGI-CC ") ;
216 #endif
217 #endif
218 #ifdef __MWERKS__
219 compiler = const_cast<char *>("Codewarrior ");
220 #endif
221
222 char buff[512];
223 sprintf(buff,"SOPHYA Version %4.1f Revision %d (%s) -- %s %s %s",
224 SOPHYA_VERSION, SOPHYA_REVISION, SOPHYA_TAG,
225 __DATE__, __TIME__, compiler);
226 svers = buff;
227
228 return(SOPHYA_VERSION + (SOPHYA_REVISION/1000.));
229}
230
231//! Print the SOPHYA version string and optionaly the list of registered modules
232void SophyaInitiator::PrintVersion(bool fglist)
233{
234 string svers;
235 GetVersion(svers);
236 cout << svers << endl;
237 if (fglist) ListModules(cout);
238}
239
240//! Should be called by sub-classes to register module name and version
241int SophyaInitiator::RegisterModule(const char * name, double version)
242{
243 if (ModListP == NULL)
244 throw NullPtrError("SophyaInitiator::RegisterModule() ModListP= NULL !");
245 map<string, double>& modlist = *ModListP;
246 modlist[string(name)] = version;
247 return modlist.size();
248}
249
250//! List of registered module names and version number
251int SophyaInitiator::ListModules(ostream& os)
252{
253 if (ModListP == NULL)
254 throw NullPtrError("SophyaInitiator::ListModules() ModListP= NULL !");
255 os << "--- SophyaInitiator::ListModules() Name / VersionNumber --- " << endl;
256 map<string, double>& modlist = *ModListP;
257 int k = 1;
258 for(map<string, double>::iterator it = modlist.begin(); it != modlist.end(); it++, k++)
259 os << k << " : " << (*it).first << " V= " << (*it).second << endl;
260 os << " ----------------------------------------------------------- " << endl;
261 return modlist.size();
262}
263
264//! Return the SOPHYA version number: VERS + REV/1000
265double SOPHYA::SophyaVersion()
266{
267return(SOPHYA_VERSION + (SOPHYA_REVISION/1000.));
268}
269
270// On met un objet initiator en statique, pour les loaders qui savent
271// appeler le constructeur des objets statiques Reza 08/98
272// La presence de l'objet statique psophyainit semble poserun probleme
273// sur MacOSX 10.2 qui se plante a l'initialisation avec les shared-libs
274// Suppression de #if !defined(Darwin) en Juil 2006
275static SophyaInitiator psophyainit;
276
Note: See TracBrowser for help on using the repository browser.