source: Sophya/trunk/SophyaPI/PIext/nobjmgr.cc@ 3366

Last change on this file since 3366 was 3366, checked in by ansari, 18 years ago

Tentative pour regler le probleme de blocage de piapp suite a affichage de la fefenetre de gestion d'objets.

1/ Protection dans NamedObjMgr() pour eviter deadlock de mutex (ds NamedObjMgr::UpdateObjMgrWindow() en particulier)
2/ Introduction de la classe SOpExObj (fichier piacmd.h .cc) pour execution d'operations sur objets, initiees depuis la boucle d'evts, dans un thread separe.

Reza , 30/10/2007

File size: 47.6 KB
RevLine 
[165]1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
[295]5#include <typeinfo>
[2322]6#include <iostream>
[165]7#include <string>
8#include <list>
9#include <map>
10
[2615]11#include "sopnamsp.h"
[165]12#include "strutil.h"
13#include "datatypes.h"
14
15#include "nobjmgr.h"
16#include "servnobjm.h"
[330]17#include "nomgadapter.h"
[165]18#include "pistdimgapp.h"
19
[1164]20#include "dvlist.h"
[165]21
[293]22// EVOL-PLANCK
23#ifdef SANS_EVOLPLANCK
24#include "fitsimage.h"
[1321]25#else
[1525]26#include "tvector.h"
27#include "pitvmaad.h"
[1905]28#include "piyfxdrw.h"
[293]29#endif
30
[295]31#include "pisurfdr.h"
[165]32#include "pipodrw.h"
[333]33
[165]34#include "pintuple.h"
35#include "pintup3d.h"
36#include "pigfd1.h"
37#include "pigfd2.h"
38
[2491]39#include "zthread.h"
[165]40
[2491]41
[165]42//++
43// Class NamedObjMgr
44// Lib PI
45// include nobjmgr.h
46//
[344]47// Cette classe fournit les services nécéssaires à la gestion des objets
[165]48// (l'ensemble des objets PPersist de PEIDA++) au sein du programme
49// d'analyse interactive *piapp* . Elle constitue en outre l'interface
50// entre les fonctions utilisateur et l'application graphique.
51//--
52//++
53// Links Voir aussi
54// PIStdImgApp
55// Services2NObjMgr
56// PIACmd
57//--
58
59
60// ..................................................................
61// ...... Gestion des objets nommes, variables globales ............
[331]62struct nobj_diritem {
[344]63 int id; // Directory Id
64 int nobj; // Number of objects in directory
65 bool lock; // True -> directory locked, No Add, del or rename
66 bool keepold; // True -> When duplicate object name, old object moved to /old
[331]67};
68
69typedef map<string, nobj_diritem, less<string> > NObjDirList;
70
[165]71struct nobj_item {
[344]72 AnyDataObj* obj; // Object pointer
73 NObjMgrAdapter* obja; // Object adapter pointer
74 int oid; // object Id
75 int dirid; // Directory Id
76 list<int> wrsid; // List of Window Resource Id (Drawer, PIBaseWdg, ...)
77 // (for PIStdImgApp)
[165]78 bool operator==(nobj_item const& b) const
79 { return (this->obj == b.obj); }
80};
81
82typedef map<string, nobj_item, less<string> > NObjList;
83
[331]84static NObjDirList* myDirs = NULL;
85static NObjList* myObjs = NULL;
[165]86static int fgOInit = 0;
87static int myNObj = 0;
[331]88static int myDirId = 0;
89static string* currDir;
[165]90
91static PIStdImgApp* myImgApp=NULL;
92static Services2NObjMgr* servnobjm=NULL;
93
[1164]94static DVList* myVars = NULL; // Pour stocker les variables
95
[2755]96static string* TmpDir = NULL; // Repertoire pour les compilations / link dynamique
[165]97
[2491]98// Pour gestion multithread
[2755]99static ZMutex* myMutex = NULL;
[3366]100static bool myMtxLocked = false; // if myMutex has been locked
101static bool obmWvis = false; // true -> ObjMgrWindow() is active/visible
102static bool obmWUpdReq = false; // true -> ObjMgrWindow Update requested
[333]103// ..................................................................
[3366]104// .... Classe NObjMgrSync ....
105class NObjMgrSync {
106public:
107 explicit NObjMgrSync(int sigbr)
108 {
109 myMtxLocked = true;
110 myMutex->lock();
111 _sigbr = sigbr;
112 }
113 ~NObjMgrSync()
114 {
115 if (_sigbr == 1) myMutex->signal();
116 else if (_sigbr == 2) myMutex->broadcast();
117 myMutex->unlock();
118 myMtxLocked = false;
119 if (obmWUpdReq) {
120 NamedObjMgr _momg;
121 _momg.UpdateObjMgrWindow(-1);
122 }
123 }
124 inline int NOp() { return _sigbr; }
[333]125
[3366]126 int _sigbr;
127};
128//.............................
129
[165]130//++
131// Titre Constructeurs
132//--
133//++
134// NamedObjMgr()
135// Constructeur. Les différents instantiation de la classe "NamedObjMgr"
136// dans une même application créent des objets qui travaillent sur la même
137// liste d'objets. Les objets de cette classe ne possedent en effet pas
138// de variables membres.
139//--
140
141/* --Methode-- */
[2490]142NamedObjMgr::NamedObjMgr(bool fgimgapp)
[165]143{
[2490]144_fgimgapp = fgimgapp;
[165]145if (fgOInit == 0) {
[333]146 myNObj = 0;
147 myDirId = 0;
[331]148 myDirs = new NObjDirList;
[165]149 myObjs = new NObjList;
[1164]150 myVars = new DVList;
[2755]151 myMutex = new ZMutex;
[331]152 currDir = new string("home");
[333]153 string dirn = "home";
[2491]154 CreateDir_P(dirn);
[2132]155 SetKeepOldDirAtt(dirn, false);
[333]156 dirn = "tmp";
[2491]157 CreateDir_P(dirn);
[344]158 SetKeepOldDirAtt(dirn, false);
[466]159 dirn = "autoc";
[2491]160 CreateDir_P(dirn);
[368]161 SetKeepOldDirAtt(dirn, false);
[333]162 dirn = "old";
[2491]163 CreateDir_P(dirn);
[344]164 SetKeepOldDirAtt(dirn, false);
[333]165 dirn = "home";
166 SetCurrentDir(dirn);
167 myDirId = 50;
[165]168 char* varenv;
169 TmpDir = new string("");
[1276]170 if ( (varenv=getenv("TMPDIR")) != NULL ) (*TmpDir) = varenv;
[165]171 int l = (*TmpDir).length();
172 if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
[2491]173 servnobjm = new Services2NObjMgr(*TmpDir);
[165]174 }
175fgOInit++;
176}
177
178
179/* --Methode-- */
180NamedObjMgr::~NamedObjMgr()
181{
182fgOInit--;
[1164]183if (fgOInit == 0) {
184 string patt = "/*/*";
185 DelObjects(patt, true);
186 delete myObjs;
187 delete myDirs;
188 delete myVars;
[2491]189 delete myMutex;
[165]190}
[1164]191}
[165]192
193//++
194// Titre Méthodes
195//--
196//++
197// void SetImgApp(PIStdImgApp* app)
198// Spécifie l'objet "PIStdImgApp" associé.
199// PIStdImgApp* GetImgApp()
200// Accès à l'objet "PIStdImgApp" associé.
201//--
202
203/* --Methode-- */
204void NamedObjMgr::SetImgApp(PIStdImgApp* app)
205{
206myImgApp = app;
207servnobjm->SetImgApp(app);
[333]208
209NObjDirList::iterator it;
210string cn;
211for(it= myDirs->begin(); it != myDirs->end(); it++) {
212 cn = '/' + (*it).first;
213 (myImgApp->ObjMgrW())->AddDirectory(cn.c_str(), (*it).second.id);
214 }
[165]215}
216
[449]217
218static bool verbeux = false; // true -> plus de message (creation/suppression d'objets)
219void NamedObjMgr::SetVerbose(bool fg)
220{
221verbeux = fg;
222}
223
[165]224/* --Methode-- */
225PIStdImgApp* NamedObjMgr::GetImgApp()
226{
227return(myImgApp);
228}
229
230/* --Methode-- */
231Services2NObjMgr* NamedObjMgr::GetServiceObj()
232{
233return(servnobjm);
234}
235
[331]236/* --Methode-- */
[1268]237string const& NamedObjMgr::GetTmpDir()
[1265]238{
239return *TmpDir;
240}
241
242/* --Methode-- */
[1268]243void NamedObjMgr::SetTmpDir(string const& tmpdir)
[1265]244{
245if(tmpdir.length()<1) return;
246*TmpDir = tmpdir;
[1276]247int l = (*TmpDir).length();
248if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
249servnobjm->SetTmpDir(*TmpDir);
[1265]250}
251
252/* --Methode-- */
[1164]253bool NamedObjMgr::SetVar(string const & key, string const & val)
254{
[2218]255 if ((key.length() < 1) || (! isalpha(key[0])) ) {
256 cout << "NamedObjMgr::SetVar( " << key << " ...) Bad VarName " << endl;
257 return(false);
258 }
[3366]259 NObjMgrSync zs(0); zs.NOp();
[1199]260#ifdef SANS_EVOLPLANCK
261 bool fg = true;
262#else
[1164]263 bool fg = myVars->HasKey(key);
[1199]264#endif
[1164]265 myVars->SetS(key, val);
[1224]266 // cout << " DEBUG::SetVar " << *myVars << endl;
[1164]267 return(fg);
268}
269
270/* --Methode-- */
271bool NamedObjMgr::HasVar(string const & key)
272{
[2218]273 if ((key.length() < 1) || (! isalpha(key[0])) ) {
274 cout << "NamedObjMgr::HasVar( " << key << ") Bad VarName " << endl;
275 return(false);
276 }
[3366]277 NObjMgrSync zs(0); zs.NOp();
[1199]278#ifdef SANS_EVOLPLANCK
[1547]279 DVList::ValList::const_iterator it;
280 for(it=myVars->Begin(); it!= myVars->End(); it++)
281 if ((*it).first == key) return true;
[1199]282 return(false);
283#else
[1164]284 return(myVars->HasKey(key));
[1199]285#endif
[1164]286}
287
288/* --Methode-- */
289bool NamedObjMgr::DeleteVar(string const & key)
290{
[2218]291 if ((key.length() < 1) || (! isalpha(key[0])) ) {
292 cout << "NamedObjMgr::DeleteVar( " << key << ") Bad VarName " << endl;
293 return(false);
294 }
[3366]295 NObjMgrSync zs(0); zs.NOp();
[1199]296#ifdef SANS_EVOLPLANCK
297 return(false);
298#else
[1164]299 return(myVars->DeleteKey(key));
[1199]300#endif
[1164]301}
302
303/* --Methode-- */
304string NamedObjMgr::GetVar(string const & key)
305{
[2218]306 if ((key.length() < 1) || (! isalpha(key[0])) ) {
307 cout << "NamedObjMgr::GetVar( " << key << ") Bad VarName " << endl;
308 return("");
309 }
[3366]310 NObjMgrSync zs(0); zs.NOp();
[1224]311 // cout << " DEBUG::GetVar " << *myVars << endl;
[1164]312 return(myVars->GetS(key));
313}
314
315/* --Methode-- */
316DVList& NamedObjMgr::GetVarList()
317{
[1224]318 // cout << " DEBUG::GetVarList " << *myVars << endl;
[3366]319 NObjMgrSync zs(0); zs.NOp();
[1164]320 return(*myVars);
321}
322
323/* --Methode-- */
[344]324bool NamedObjMgr::CreateDir(string & dirname)
[331]325{
[3366]326 NObjMgrSync zs(0); zs.NOp();
[2491]327 return CreateDir_P(dirname);
328}
329
330/* --Methode-- */
331bool NamedObjMgr::CreateDir_P(string & dirname)
332{
[333]333if ( !CheckDirName(dirname) ) {
334 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl;
[344]335 return(false);
[333]336 }
337NObjDirList::iterator it = myDirs->find(dirname);
338if (it != myDirs->end()) {
339 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl;
[344]340 return(false);
[333]341 }
342myDirId++;
343nobj_diritem di;
344di.id = myDirId;
345di.nobj = 0;
[344]346di.lock = false;
347di.keepold = false;
[333]348(*myDirs)[dirname] = di;
349if (myImgApp) {
350 string str = '/' + dirname;
[2492]351 if ( !_fgimgapp ) myImgApp->LockMutex();
[333]352 (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId);
[2492]353 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
354}
[449]355if (verbeux) cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
[344]356return(true);
[331]357}
358
359/* --Methode-- */
[344]360bool NamedObjMgr::DeleteDir(string & dirname)
[331]361{
[333]362if ( !CheckDirName(dirname) ) {
363 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
[344]364 return(false);
[333]365 }
[3366]366NObjMgrSync zs(0); zs.NOp();
[333]367NObjDirList::iterator it = myDirs->find(dirname);
368if (it == myDirs->end()) {
369 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
[344]370 return(false);
[333]371 }
372if ((*it).second.nobj > 0) {
373 cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
[344]374 return(false);
[333]375 }
[344]376if ((*it).second.lock ) {
377 cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl;
378 return(false);
379 }
[333]380if ((*it).second.id < 50) {
381 cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
[344]382 return(false);
[333]383 }
384
[2490]385if (myImgApp) {
[2492]386 if ( !_fgimgapp ) myImgApp->LockMutex();
[3366]387 if ((myImgApp->ObjMgrW())->GetCurDirId() == (*it).second.id) {
388 (myImgApp->ObjMgrW())->SetCurDir(*currDir);
389 obmWUpdReq = true;
390 }
[333]391 (myImgApp->ObjMgrW())->DelDirectory((*it).second.id);
[3366]392
[2492]393 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[2490]394}
[333]395myDirs->erase(it);
[449]396if (verbeux) cout << "NamedObjMgr::DeleteDir() " << dirname << " deleted " << endl;
[344]397return(true);
[331]398}
399
400/* --Methode-- */
[344]401void NamedObjMgr::LockDir(string & dirname)
[331]402{
[3366]403NObjMgrSync zs(0); zs.NOp();
[344]404if ( !CheckDirName(dirname) ) return;
405NObjDirList::iterator it = myDirs->find(dirname);
406if (it == myDirs->end()) return;
407(*it).second.lock = true;
[449]408if (verbeux) cout << "NamedObjMgr::LockDir() " << dirname << " Locked " << endl;
[344]409return;
410}
411
412/* --Methode-- */
413void NamedObjMgr::UnlockDir(string & dirname)
414{
[3366]415NObjMgrSync zs(0); zs.NOp();
[344]416if ( !CheckDirName(dirname) ) return;
417NObjDirList::iterator it = myDirs->find(dirname);
418if (it == myDirs->end()) return;
419(*it).second.lock = true;
[449]420if (verbeux) cout << "NamedObjMgr::UnlockDir() " << dirname << " Unlocked " << endl;
[344]421return;
422}
423
424/* --Methode-- */
425void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold)
426{
[3366]427NObjMgrSync zs(0); zs.NOp();
[344]428if ( !CheckDirName(dirname) ) return;
429NObjDirList::iterator it = myDirs->find(dirname);
430if (it == myDirs->end()) return;
431(*it).second.keepold = keepold;
[449]432if (!verbeux) return;
[344]433cout << "NamedObjMgr::SetKeepOldDirAtt() " << dirname << " -> ";
434if ( keepold ) cout << " True " << endl;
435else cout << " False " << endl;
436return;
437}
438
439
440/* --Methode-- */
441bool NamedObjMgr::SetCurrentDir(string & dirname)
442{
[3366]443NObjMgrSync zs(0); zs.NOp();
[333]444if ( !CheckDirName(dirname) ) {
445 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
[344]446 return(false);
[333]447 }
448NObjDirList::iterator it = myDirs->find(dirname);
449if (it == myDirs->end()) {
450 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
[344]451 return(false);
[333]452 }
453*currDir = dirname;
[449]454if (verbeux) cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
[344]455return(true);
[331]456}
457
458/* --Methode-- */
[333]459void NamedObjMgr::GetCurrentDir(string & dirname)
460{
[3366]461NObjMgrSync zs(0); zs.NOp();
[333]462dirname = *currDir;
463}
464
465/* --Methode-- */
466void NamedObjMgr::ListDirs(string & patt)
467{
[3366]468NObjMgrSync zs(0); zs.NOp();
[333]469NObjDirList::iterator it;
470string cn;
471cout << "NamedObjMgr::ListDirs( " << patt << " ) " << endl;
472int k = 0;
473for(it= myDirs->begin(); it != myDirs->end(); it++) {
474 cn = (*it).first;
475 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
476 k++;
[344]477 cout << k << "- " << (*it).first;
478 if ( (*it).second.lock ) cout << " Locked " ;
479 if ( (*it).second.keepold ) cout << " KeepOld " ;
480 cout << " (Id= " << (*it).second.id << " NbObj= " << (*it).second.nobj << ")" << endl;
481
[333]482 }
483}
484
485/* --Methode-- */
486void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd)
487{
[3366]488NObjMgrSync zs(0); zs.NOp();
[333]489NObjDirList::iterator it;
490string cn;
491for(it= myDirs->begin(); it != myDirs->end(); it++) {
492 cn = (*it).first;
493 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
494 lstd.push_back(cn);
495 }
496}
497
498/* --Methode-- */
[368]499void NamedObjMgr::CleanDir(string & dirname)
[331]500{
[3366]501NObjMgrSync zs(0); zs.NOp();
[2491]502CleanDir_P(dirname);
503}
504
505/* --Methode-- */
506void NamedObjMgr::CleanDir_P(string & dirname)
507{
[368]508if ( !CheckDirName(dirname) ) {
509 cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - Invalid name !" << endl;
[380]510 // return(false); $CHECK$ illegal return value in void function
[368]511 }
512NObjDirList::iterator itr = myDirs->find(dirname);
513if (itr == myDirs->end()) {
514 cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - No such directory !" << endl;
[380]515 // return(false); $CHECK$ illegal return value in void function
[368]516 }
[331]517
[368]518int did = (*itr).second.id;
519NObjList::iterator it;
520list<int>::iterator iwr;
521bool nodisp = true;
522list<string> odel;
523for(it = myObjs->begin(); it != myObjs->end(); it++) {
524 if ((*it).second.dirid != did) continue;
525 nodisp = true;
526 if (myImgApp)
527 for(iwr=(*it).second.wrsid.begin(); iwr != (*it).second.wrsid.end(); iwr++)
528 if (myImgApp->CheckWRsId(*iwr)) { nodisp = false; break; }
529 if (nodisp) odel.push_back((*it).first);
530 }
531list<string>::iterator ii;
[2757]532for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii,true);
[2762]533
[3366]534if (obmWvis) UpdateObjMgrWindow_P(did); // On met a jour la fenetre de gestion des objets
[331]535}
536
[333]537
[368]538
[165]539//++
540// Titre Gestion de la liste des objets
541//--
542//++
[295]543// void AddObj(AnyDataObj* obj, string& nom)
[165]544// Ajoute l'objet "obj" à la liste, identifié par "nom".
545// Si un objet de même nom existe, l'ancien objet est renommé en concaténant
546// un numéro à son nom.
547// void DelObj(string const& nom, bool fgd=true)
548// Supprime l'objet "nom" de la liste. L'objet est détruit si "fgd==true" ("delete obj")
549// void DelObjects(string const& patt, bool fgd=true)
550// Supprime l'ensemble des objets dont le nom correspond au patron "patt".
551// Le patron peut contenir les caractères "*" et "?" . Les objets sont détruits si "fgd==true"
[295]552// AnyDataObj* GetObj(string const& nom)
[165]553// Retourne l'objet identifié par "nom" dans la liste. Retourne "NULL" si "nom" n'est
554// pas dans la liste.
555// void RenameObj(string const& nom, string& nomnew)
556// Change le nom d'un objet dans la liste.
[463]557// void CopyObj(string const& nom, string& nomcp)
558// Copy l'objet "nom" de la liste dans l'objet "nomcp" de la liste.
[165]559//--
560
561/* --Methode-- */
[344]562bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
[165]563{
[3366]564 NObjMgrSync zs(0); zs.NOp();
[2491]565 return AddObj_P(obj, nom, crd);
566}
[165]567
[2491]568/* --Methode-- */
569bool NamedObjMgr::AddObj_P(AnyDataObj* obj, string & nom, bool crd)
570{
571
[344]572if (obj == NULL) return(false);
[333]573// On verifie si l'objet est deja dans la liste
574NObjList::iterator it;
575for(it = myObjs->begin(); it != myObjs->end(); it++) {
576 if ((*it).second.obj == obj) {
577 cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl;
[344]578 return(false);
[333]579 }
580 }
581string nobj;
582string nrep;
583char buff[32];
584int did = ParseObjectName(nom, nrep, nobj);
585if (did == 0) {
586 if (!crd) {
587 cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl;
[344]588 return(false);
[333]589 }
[2491]590 else { CreateDir_P(nrep); did = myDirId; }
[333]591 }
[165]592
[466]593// Si c'est le repertoire /autoc, on nettoie
594if (nrep == "autoc") {
[2491]595 CleanDir_P(nrep);
[368]596 }
597
[165]598myNObj++;
[2999]599if ( !CheckName(nobj) ) {
[333]600 sprintf(buff,"O%d", myNObj);
[2999]601 cout << "NamedObjMgr::AddObj() Name changed: " << nom << " -> " << buff << endl;
602 nom = buff;
603}
[333]604
605nom = '/' + nrep + '/' + nobj;
[344]606NObjDirList::iterator itr = myDirs->find(nrep);
607if ((*itr).second.lock) {
608 cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl;
609 return(false);
610 }
[333]611it = myObjs->find(nom);
[165]612if (it != myObjs->end()) { // l'objet existe deja
[466]613 if (nrep == "autoc") { // Dans /autoc , on garde les objets affiches, donc del. par Clean
[368]614 sprintf(buff, "%d", (*it).second.oid);
[466]615 string nomnew = "/autoc/" + nobj + buff;
[2491]616 RenameObj_P(nom, nomnew);
[368]617 }
618 else if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old
[333]619 string on,od;
[335]620// ParseObjectName((*it).first, od, on);
[333]621 sprintf(buff, "%d", (*it).second.oid);
[335]622 string nomnew = "/old/" + nobj + buff;
[2491]623 RenameObj_P(nom, nomnew);
[333]624 }
[344]625 else { // Sinon, on remplace l'objet
626 cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
[2491]627 DelObj_P(nom);
[344]628 }
[165]629 }
630
631nobj_item no;
632no.obj = obj;
[295]633no.obja = servnobjm->GetAdapter(obj); // L'adaptateur
[333]634no.oid = myNObj;
635no.dirid = did;
[331]636(*myObjs)[nom] = no;
[333]637
638(*itr).second.nobj++;
639
[3366]640if (obmWvis && (myImgApp != NULL)) {
[2492]641 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]642 if ( (myImgApp->ObjMgrW())->Visible() ) {
643 string oln = nobj + " (T= " + no.obja->GetDataObjType() + ")" ;
644 (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
[685]645 }
[2492]646 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[2490]647}
[449]648if (verbeux) cout << "NamedObjMgr::AddObj() Object " << nom << " ( "
[295]649 << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;
[344]650return(true);
[165]651}
652
[1224]653bool NamedObjMgr::AddObj(AnyDataObj& obj, string & nom, bool crd)
654{
[3366]655NObjMgrSync zs(0); zs.NOp();
[1224]656NObjMgrAdapter* adap = GetServiceObj()->GetAdapter(&obj);
657if (adap == NULL) {
658 cout << "NamedObjMgr::AddObj() No Adapter ! " << nom << endl;
659 return(false);
660}
[1315]661AnyDataObj * cloneobj = adap->CloneDataObj(true);
[1224]662delete adap;
663if (cloneobj == NULL) {
664 cout << "NamedObjMgr::AddObj() Pb cloning object ! " << nom << endl;
665 return(false);
666}
[2491]667return ( AddObj_P(cloneobj , nom, crd) );
[1224]668}
669
[165]670/* --Methode-- */
[344]671bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
[165]672{
[3366]673 NObjMgrSync zs(0); zs.NOp();
[2491]674 return RenameObj_P(nom, nomnew);
675}
676
677/* --Methode-- */
678bool NamedObjMgr::RenameObj_P(string & nom, string& nomnew)
679{
[333]680string n1,r1,n2,r2;
[344]681int dids = ParseObjectName(nom, r1, n1);
682NObjDirList::iterator itr1 = myDirs->find(r1);
[333]683int did = ParseObjectName(nomnew, r2, n2);
[344]684NObjDirList::iterator itr2 = myDirs->find(r2);
685
[333]686if (did == 0) {
687 cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
[344]688 return(false);
[2218]689}
[333]690nom = '/' + r1 + '/' + n1;
691nomnew = '/' + r2 + '/' + n2;
692NObjList::iterator it1 = myObjs->find(nom);
693if (it1 == myObjs->end()) {
694 cout << "NamedObjMgr::RenameObj() Error - No " << nom << " object !" << endl;
[344]695 return(false);
[2218]696}
[2999]697
698if ( !CheckName(n2) ) {
[2218]699 cout << "NamedObjMgr::RenameObj() Error - bad new object name" << n2 << endl;
700 return(false);
701}
[333]702NObjList::iterator it2 = myObjs->find(nomnew);
703if (it2 != myObjs->end()) {
704 cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl;
[344]705 return(false);
[2999]706}
707
[344]708if ( (*itr1).second.lock || (*itr2).second.lock ) {
709 cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !"
710 << endl;
711 return(false);
712 }
713
714
[333]715nobj_item no = (*it1).second;
716no.dirid = did;
717myObjs->erase(it1);
718NObjDirList::iterator itr = myDirs->find(r1);
719(*itr).second.nobj--;
720(*myObjs)[nomnew] = no;
721itr = myDirs->find(r2);
722(*itr).second.nobj++;
[685]723
[3366]724if (obmWvis && (myImgApp != NULL)) {
[2492]725 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]726 if ( (myImgApp->ObjMgrW())->Visible() ) {
727 (myImgApp->ObjMgrW())->DelObjList(dids, no.oid);
728 string oln = n2 + " (T= " + no.obja->GetDataObjType() + ")" ;
729 (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
730 }
[2492]731 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[685]732}
[449]733if (verbeux)
734 cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
[344]735return(true);
[331]736}
737
738/* --Methode-- */
[463]739bool NamedObjMgr::CopyObj(string & nom, string& nomcp)
740{
[3366]741NObjMgrSync zs(0); zs.NOp();
[463]742if(nomcp.length()<=0)
743 {cout<<"NamedObjMgr::CopyObj() Error, copied obj name "<<nomcp<<" not valid"<<endl;
744 return(false);}
[2755]745NObjMgrAdapter* obnom = GetObjAdapter_P(nom);
[463]746if(obnom==NULL)
747 {cout<<"NamedObjMgr::CopyObj() Error - No "<<nom<<" object !"<<endl;
748 return(false);}
[1165]749AnyDataObj* obnomcp = obnom->CloneDataObj();
[463]750if(obnomcp==NULL) return(false);
[2491]751if(! AddObj_P(obnomcp,nomcp,false) ) {delete obnomcp; return(false);}
[463]752return true;
753}
754
755/* --Methode-- */
[344]756bool NamedObjMgr::DelObj(string & nom, bool fgd)
[331]757{
[3366]758 NObjMgrSync zs(0); zs.NOp();
[2491]759 return DelObj_P(nom, fgd);
760}
761
762/* --Methode-- */
763bool NamedObjMgr::DelObj_P(string & nom, bool fgd)
764{
[333]765string n1,r1;
[685]766int did = ParseObjectName(nom, r1, n1);
[333]767nom = '/' + r1 + '/' + n1;
[165]768NObjList::iterator it = myObjs->find(nom);
[344]769if (it == myObjs->end()) return(false);
770NObjDirList::iterator itr = myDirs->find(r1);
771if ( (*itr).second.lock ) {
772 cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl;
773 return(false);
774 }
[165]775list<int>::iterator ii;
776if (myImgApp) {
777//DBG cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
[2492]778// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
779 bool fglock = (_fgimgapp) ? false : true;
780 if (fglock) myImgApp->LockMutex();
[165]781 for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
782 myImgApp->DelWRsId((*ii));
[2492]783 if (fglock) myImgApp->UnlockMutex(true);
[165]784}
[314]785delete (*it).second.obja; // destruction de l'adaptateur
[165]786if (fgd) delete (*it).second.obj;
[333]787
[3366]788if (obmWvis && (myImgApp != NULL)) {
[2492]789 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]790 if ( (myImgApp->ObjMgrW())->Visible() ) {
791 int olid = (*it).second.oid;
792 (myImgApp->ObjMgrW())->DelObjList(did, olid);
793 }
[2492]794 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[685]795}
[165]796myObjs->erase(it);
[333]797(*itr).second.nobj--;
798
[685]799
[449]800if (!verbeux) return(true);
[165]801if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
802else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
[344]803return(true);
[165]804}
805
806/* --Methode-- */
[344]807bool NamedObjMgr::DelObj_Id(int oid)
[165]808{
[3366]809NObjMgrSync zs(0); zs.NOp();
[333]810NObjList::iterator it;
811string nom;
812bool of = false;
813for(it = myObjs->begin(); it != myObjs->end(); it++)
814 if ( (*it).second.oid == oid ) {
815 of = true; nom = (*it).first;
816 break;
817 }
[2757]818if (of) return(DelObj_P(nom, true));
[344]819else return(false);
[331]820}
821
822/* --Methode-- */
823void NamedObjMgr::DelObjects(string & patt, bool fgd)
824{
[3366]825NObjMgrSync zs(0); zs.NOp();
[333]826string n1,r1;
827ParseObjectName(patt, r1, n1);
828patt = '/' + r1 + '/' + n1;
[165]829NObjList::iterator it;
830list<string> odel;
831string cn;
832for(it = myObjs->begin(); it != myObjs->end(); it++) {
833 cn = (*it).first;
834 if (csh_parse(cn.c_str(), patt.c_str()) != 0) odel.push_back(cn);
835 }
836list<string>::iterator ii;
[2491]837for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii, fgd);
[165]838}
839
840/* --Methode-- */
[331]841AnyDataObj* NamedObjMgr::GetObj(string & nom)
[165]842{
[3366]843NObjMgrSync zs(0); zs.NOp();
[2755]844return GetObj_P(nom);
845}
846
847/* --Methode-- */
848AnyDataObj* NamedObjMgr::GetObj_P(string & nom)
849{
[333]850string n1,r1;
851ParseObjectName(nom, r1, n1);
852nom = '/' + r1 + '/' + n1;
[165]853NObjList::iterator it = myObjs->find(nom);
854if (it == myObjs->end()) return(NULL);
855return((*it).second.obj);
856}
857
858/* --Methode-- */
[331]859NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
[295]860{
[3366]861NObjMgrSync zs(0); zs.NOp();
[2755]862return GetObjAdapter_P(nom);
863}
864
865/* --Methode-- */
866NObjMgrAdapter* NamedObjMgr::GetObjAdapter_P(string & nom)
867{
[333]868string n1,r1;
869ParseObjectName(nom, r1, n1);
870nom = '/' + r1 + '/' + n1;
[295]871NObjList::iterator it = myObjs->find(nom);
872if (it == myObjs->end()) return(NULL);
873return((*it).second.obja);
874}
875
876/* --Methode-- */
[331]877void NamedObjMgr::ListObjs(string & patt)
[165]878{
[3366]879NObjMgrSync zs(0); zs.NOp();
[331]880int k;
881AnyDataObj* obj=NULL;
882string ctyp;
883char strg[256];
884
[333]885string n1,r1;
886ParseObjectName(patt, r1, n1);
887patt = '/' + r1 + '/' + n1;
888 cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
[331]889NObjList::iterator it; k = 0;
[333]890string cn;
[331]891for(it = myObjs->begin(); it != myObjs->end(); it++) {
[333]892 cn = (*it).first;
893 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
[331]894 obj = (*it).second.obj;
895 ctyp = typeid(*obj).name();
896 sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str());
897 ctyp = strg;
898 cout << ctyp << "\n" ;
899 k++;
900}
901cout << endl;
[165]902return;
903}
904
905/* --Methode-- */
[333]906void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
[165]907{
[3366]908NObjMgrSync zs(0); zs.NOp();
[333]909string n1,r1;
910if (patt.length() < 1) return;
911bool fgr = (patt[0] == '/') ? true : false;
912ParseObjectName(patt, r1, n1);
913patt = '/' + r1 + '/' + n1;
914NObjList::iterator it;
915string cn;
916for(it = myObjs->begin(); it != myObjs->end(); it++) {
917 cn = (*it).first;
918 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
919 if (fgr) lst.push_back(cn);
920 else {
921 ParseObjectName(cn, r1, n1);
922 lst.push_back(n1);
923 }
924 }
[165]925}
926
927//++
928// Titre Entrées-Sorties (I/O) sur les objets
929//--
930//++
931// void ReadObj(PInPersist& s, int num=-1)
932// Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s"
933// et l'ajoute à la liste. Si "num" est négatif, tous les objets présents
934// sur le flot "s" sont créés et ajoutés à la liste.
935// void ReadObj(string const & nomppf, string nobj="")
936// Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté
937// à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est
938// composé à partir du nom de fichier.
939//--
940
941/* --Methode-- */
[331]942void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
[165]943{
[495]944PPersist* ppobj=NULL;
[165]945bool ok = true;
[495]946#ifdef SANS_EVOLPLANCK
[165]947TRY{
948 PInPersist pis(flnm);
[495]949 ppobj = PPersistMgr::ReadObject(pis);
950 if (ppobj == NULL) ok = false;
[165]951} CATCH(merr)
952 { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
953 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]954#else
955try {
956 PInPersist pis(flnm);
957 ppobj = pis.ReadObject();
958 }
959catch (IOExc iox) {
960 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
961 ok = false;
962 }
963#endif
[165]964if (!ok) return;
965if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
[3366]966AddObj(ppobj->DataObj(), nobj, true);
[685]967cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl;
[165]968return;
969}
[2645]970/* --Methode-- */
971void NamedObjMgr::ReadObj(vector<string> & flnm_objname)
972// flnm_objname[0] = nom du fichier .ppf
973// flnm_objname[1...] = nom des tags des objects a lire
974{
975if(flnm_objname.size()<2) return;
976int nread=0;
977try {
978 PInPersist pis(flnm_objname[0]);
979 for(int i=1;i<flnm_objname.size();i++) {
980 bool ok = pis.GotoNameTag(flnm_objname[i]);
981 if(!ok) {
982 cout<<"NamedObjMgr::ReadObj(...) Unknown object: "<<flnm_objname[i]<<endl;
983 continue;
984 }
985 PPersist *ppobj = pis.ReadObject();;
986 if(ppobj==NULL) {
987 cout<<"NamedObjMgr::ReadObj(...) impossible to read "<<flnm_objname[i]<<endl;
988 continue;
989 }
[3366]990 AddObj(ppobj->DataObj(),flnm_objname[i],true);
[2645]991 nread++;
992 cout<<"NamedObjMgr::ReadObj(...) object "<<flnm_objname[i]<<" read from file "<<endl;
993 }
994} catch (IOExc iox) {
995 cerr<<"NamedObjMgr::ReadObj()/Error Exception - Msg= "<<iox.Msg()<<endl;
996}
997cout<<nread<<" objects have been read"<<endl;
998return;
999}
[165]1000
1001/* --Methode-- */
1002void NamedObjMgr::ReadObj(PInPersist& s, int num)
1003{
[3366]1004NObjMgrSync zs(0); zs.NOp();
[2755]1005ReadObj_P(s, num);
1006}
1007
1008/* --Methode-- */
1009void NamedObjMgr::ReadObj_P(PInPersist& s, int num)
1010{
[2180]1011int_4 i; // $CHECK$ int -> int_4 a cause de TagKey
1012#ifdef SANS_EVOLPLANCK
1013int_4 cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey
1014#endif
[165]1015int n0, n1;
1016bool ok = true;
1017PPersist* obj=NULL;
1018string nom;
1019
[449]1020int nread = 0;
[2460]1021int nbtags = 0;
1022#ifdef SANS_EVOLPLANCK
1023nbtags = s.NbTags();
1024#else
1025nbtags = s.NbNameTags();
1026#endif
1027if ( (nbtags < 1) || (num >= nbtags) ) {
[165]1028 if (num >= 0) {
[495]1029 cerr << "NamedObjMgr::ReadObj(PInPersist, " << num << " Error! NbTags ="
[2460]1030 << nbtags << endl;
[165]1031 return;
1032 }
[495]1033
1034#ifdef SANS_EVOLPLANCK
[165]1035 TRY {
1036 obj = PPersistMgr::ReadObject(s);
1037 if (obj == NULL) ok = false;
1038 } CATCH(merr) {
1039 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
1040 ok = false;
1041 } ENDTRY;
[495]1042#else
1043try {
1044 obj = s.ReadObject();
1045 }
1046catch (IOExc iox) {
1047 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
1048 ok = false;
1049 }
1050#endif
1051
[165]1052 if (!ok) return;
1053 nom = "";
[2491]1054 AddObj_P(obj->DataObj(), nom, false);
[449]1055 nread++;
[165]1056}
1057
[2460]1058if (num < 0) { n0 = 0; n1 = nbtags; }
[165]1059else { n0 = num; n1 = num+1; }
1060for(i=n0; i<n1; i++) {
[495]1061#ifdef SANS_EVOLPLANCK
[165]1062 key = s.TagKey(i, cid, ln);
1063 if (ln <= 0) nom = "";
1064 else nom = s.TagName(i);
1065 s.GotoTag(i);
1066 TRY {
1067 obj = PPersistMgr::ReadObject(s);
1068 if (obj == NULL) ok = false;
1069 } CATCH(merr) {
1070 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
1071 ok = false;
1072 } ENDTRY;
[495]1073#else
[2460]1074 s.GotoNameTagNum(i);
[584]1075 nom = s.GetTagName(i);
[495]1076 try {
1077 obj = s.ReadObject();
1078 }
1079 catch (IOExc iox) {
1080 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
1081 ok = false;
1082 }
1083#endif
[2491]1084 if (ok) { AddObj_P(obj->DataObj(), nom, true); nread++; }
[165]1085}
1086
[449]1087cout << "NamedObjMgr::ReadObj(...) " << nread << " Objects read " << endl;
[165]1088return;
1089}
1090/* --Methode-- */
1091void NamedObjMgr::ReadAll(string const & flnm)
1092{
[2701]1093#ifdef SANS_EVOLPLANCK
[165]1094bool ok = true;
1095PPersist* obj=NULL;
1096
[2180]1097PInPersist* ppin=NULL;
[165]1098TRY{
1099 ppin = new PInPersist(flnm);
1100 if (ppin->NbTags() < 1) obj = PPersistMgr::ReadObject((*ppin));
1101 else obj = NULL;
1102} CATCH(merr)
1103 { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n",
[2701]1104 (long)merr, PeidaExc(merr)); ok = false; }
1105ENDTRY;
[165]1106if (!ok) return;
1107if (obj) {
1108 string nom = servnobjm->FileName2Name(flnm);
[3366]1109 AddObj(obj->DataObj(), nom, false);
[165]1110 }
[3366]1111else ReadObj((*ppin), -1);
[165]1112delete ppin;
[2701]1113#else
1114try {
1115 PInPersist pis(flnm);
1116 if (pis.NbNameTags() >= 1) {
1117 if (pis.NbNameTags() < pis.NbTopLevelObjects()) {
1118 cout << "NamedObjMgr::ReadAll()/Warning File " << flnm << " NbNameTags="
1119 << pis.NbNameTags() << " < NbTopLevelObjects= "
1120 << pis.NbTopLevelObjects() << endl;
1121 cout << " ... Reading " << pis.NbNameTags() << " objects at NameTags " ;
1122 }
[3366]1123 ReadObj(pis, -1);
[2701]1124 return;
1125 }
1126
1127 string nom = servnobjm->FileName2Name(flnm);
1128 int kn = 1;
1129 for(int ii=0; ii<pis.NbTopLevelObjects(); ii++) {
1130 PPersist* obj = pis.ReadObject();
1131 if (!obj) continue;
[3366]1132 AddObj(obj->DataObj(), nom, false);
[2701]1133 kn++;
1134 nom += (string)MuTyV(kn);
1135 }
1136}
1137catch (IOExc& iox) {
1138 cerr << "NamedObjMgr::ReadAll()/Error Exception - Msg= " << iox.Msg() << endl;
1139}
1140#endif
[165]1141return;
1142}
1143
[709]1144
[2491]1145/* --Methode-- */
1146void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
1147{
[3366]1148 NObjMgrSync zs(0); zs.NOp();
[2491]1149 SaveObj_P(nom, s, keeppath);
1150}
[165]1151
1152static int key_for_write = 5000;
1153/* --Methode-- */
[2491]1154void NamedObjMgr::SaveObj_P(string & nom, POutPersist& s, bool keeppath)
[165]1155{
[333]1156if (nom.length() < 1) return;
1157string nob,rep;
1158ParseObjectName(nom, rep, nob);
1159nom = '/' + rep + '/' + nob;
[295]1160NObjMgrAdapter* obja=NULL;
[333]1161string nomf = (keeppath) ? nom : nob;
[2755]1162obja = GetObjAdapter_P(nom);
[295]1163if (obja == NULL) return;
[165]1164printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
[295]1165 nom.c_str(), typeid(*(obja->GetDataObj())).name());
[333]1166obja->SavePPF(s, nomf);
[165]1167return;
1168}
1169
1170/* --Methode-- */
[333]1171void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
1172{
[3366]1173NObjMgrSync zs(0); zs.NOp();
[333]1174string n1,r1;
1175if (patt.length() < 1) return;
1176bool keeppath = (patt[0] == '/') ? true : false;
1177ParseObjectName(patt, r1, n1);
1178patt = '/' + r1 + '/' + n1;
1179
1180bool ok = true;
[2180]1181POutPersist* pout=NULL;
[495]1182#ifdef SANS_EVOLPLANCK
[333]1183TRY{
1184 pout = new POutPersist(flnm);
1185} CATCH(merr)
1186 { printf("NamedObjMgr::SaveObjects()/Error Exception= %ld (%s) \n",
1187 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]1188#else
1189try {
1190 pout = new POutPersist(flnm);
1191}
1192catch (IOExc iox) {
1193 cerr << "NamedObjMgr::SaveObjects()/Error Exception - Msg= " << iox.Msg() << endl;
1194 ok = false;
1195}
1196#endif
[333]1197if (!ok) return;
1198NObjList::iterator it;
1199string cn;
1200for(it = myObjs->begin(); it != myObjs->end(); it++) {
1201 cn = (*it).first;
1202 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
[2491]1203 SaveObj_P(cn, (*pout), keeppath);
[333]1204 }
1205delete pout;
1206return;
1207}
1208
1209/* --Methode-- */
[2669]1210void NamedObjMgr::SaveListObjects(vector<string> &liste)
1211// Les n-1 premiers elements (liste[0 -> n-2]) contiennent
1212// les noms des objects a mettre dans le fichier ppf
1213// dont le nom est le dernier argument (liste[n-1])
1214{
[3366]1215 NObjMgrSync zs(0); zs.NOp();
[2669]1216
1217 if(liste.size()<2) {
1218 cerr<<"NamedObjMgr::SaveListObjects()/Error not enough argument"<<endl;
1219 return;
1220 }
1221
1222 // open ppf file
1223 string ppfname = liste[liste.size()-1];
1224 POutPersist* pout=NULL;
1225 try {
1226 pout = new POutPersist(ppfname);
1227 } catch(IOExc iox) {
1228 cerr<<"NamedObjMgr::SaveObjects()/Error Exception - Msg= "<<iox.Msg()<<endl;
1229 return;
1230 }
1231
1232 // put objects in ppf file
1233 for(int i=0;i<liste.size()-1;i++) {
1234 bool keeppath = (liste[i][0] == '/') ? true : false;
1235 SaveObj_P(liste[i], (*pout), keeppath);
1236 }
1237
1238 // close ppf file
1239 delete pout;
1240
1241 return;
1242}
1243
1244/* --Methode-- */
[165]1245void NamedObjMgr::SaveAll(string const& flnm)
1246{
[3366]1247NObjMgrSync zs(0); zs.NOp();
[165]1248bool ok = true;
1249
[2180]1250POutPersist* pout=NULL;
[495]1251#ifdef SANS_EVOLPLANCK
[165]1252TRY{
1253 pout = new POutPersist(flnm);
1254} CATCH(merr)
1255 { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n",
1256 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]1257#else
1258try {
1259 pout = new POutPersist(flnm);
1260}
1261catch (IOExc iox) {
1262 cerr << "NamedObjMgr::SaveAll()/Error Exception - Msg= " << iox.Msg() << endl;
1263 ok = false;
1264}
1265#endif
[165]1266if (!ok) return;
[332]1267NObjList::iterator it;
1268string no;
1269for(it = myObjs->begin(); it != myObjs->end(); it++) {
1270 no = (*it).first;
[2491]1271 SaveObj_P(no, (*pout), true);
[332]1272 }
[165]1273delete pout;
1274return;
1275}
1276
[2491]1277
[165]1278
1279/* --Methode-- */
[2975]1280void NamedObjMgr::PrintObj(string& nom, int lev)
[165]1281{
[3366]1282NObjMgrSync zs(0); zs.NOp();
[295]1283NObjMgrAdapter* obja=NULL;
[2755]1284obja = GetObjAdapter_P(nom);
[295]1285if (obja == NULL) return;
[594]1286AnyDataObj* ob = obja->GetDataObj();
1287if (ob == NULL) {
1288 cerr << "NamedObjMgr::PrintObj() / Error - NULL object ! in " << nom << endl;
1289 return;
1290 }
1291string ctyp = typeid(*ob).name();
[295]1292cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
[2975]1293obja->Print(cout, lev);
[165]1294
1295return;
1296}
1297
1298/* --Methode-- */
[331]1299void NamedObjMgr::DisplayObj(string& nom, string dopt)
[165]1300{
[2677]1301// Pas de display si option dopt = nodisp
1302if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1303
[3366]1304NObjMgrSync zs(0); zs.NOp();
[2491]1305
[295]1306NObjMgrAdapter* obja=NULL;
[2755]1307obja = GetObjAdapter_P(nom);
[295]1308if (obja == NULL) {
[594]1309 cout << "NamedObjMgr::DisplayObj() Error , No object with name " << nom << endl;
[165]1310 return;
1311}
[594]1312if (obja->GetDataObj() == NULL) {
1313 cerr << "NamedObjMgr::DisplayObj() / Error - NULL object ! in " << nom << endl;
1314 return;
1315 }
[165]1316if (!myImgApp) return;
1317
[295]1318PIDrawer * dr = NULL;
1319P2DArrayAdapter* arr = NULL;
1320dr = obja->GetDrawer(dopt);
1321if (!dr) arr = obja->Get2DArray(dopt);
[165]1322
[295]1323if (!dr && !arr) {
1324 string ctyp = typeid(*(obja->GetDataObj())).name();
[594]1325 cout << "NamedObjMgr::DisplayObj() Error , No display for " << ctyp << endl;
[295]1326 return;
1327 }
1328
[165]1329int wrsid = 0;
1330
[344]1331string n1,r1;
1332ParseObjectName(nom, r1, n1);
1333
[2491]1334// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1335bool fglock = (_fgimgapp) ? false : true;
1336
[295]1337if (dr) {
1338 PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
[2491]1339 if(dr3) wrsid = myImgApp->Disp3DDrawer(dr3, n1, dopt, "", 0, fglock);
1340 else wrsid = myImgApp->DispScDrawer( dr, n1, dopt, "", 0, fglock);
[295]1341 }
[2651]1342else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt, false, 0, fglock);
[165]1343
[2762]1344AddWRsId_P(nom, wrsid);
[295]1345return;
1346}
[165]1347
[295]1348/* --Methode-- */
[2651]1349void NamedObjMgr::DisplayImage(string& nom, string dopt, bool fgimagnav)
[295]1350{
[2677]1351// Pas de display si option dopt = nodisp
1352if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1353
[3366]1354NObjMgrSync zs(0); zs.NOp();
[2491]1355
[295]1356NObjMgrAdapter* obja=NULL;
[2755]1357obja = GetObjAdapter_P(nom);
[295]1358if (obja == NULL) {
[449]1359 cout << "NamedObjMgr::DisplayImage() Error , No such object " << nom << endl;
[295]1360 return;
1361}
[594]1362if (obja->GetDataObj() == NULL) {
1363 cerr << "NamedObjMgr::DisplayImage() / Error - NULL object ! in " << nom << endl;
1364 return;
1365 }
[295]1366if (!myImgApp) return;
1367
1368P2DArrayAdapter* arr = obja->Get2DArray(dopt);
[165]1369
[295]1370if (!arr) {
1371 string ctyp = typeid(*(obja->GetDataObj())).name();
[449]1372 cout << "NamedObjMgr::DisplayImage() Error , Not supported for " << ctyp << endl;
[295]1373 return;
1374 }
[165]1375
[344]1376string n1,r1;
1377ParseObjectName(nom, r1, n1);
1378
[2491]1379// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1380bool fglock = (_fgimgapp) ? false : true;
1381
[295]1382int wrsid = 0;
[2651]1383wrsid = myImgApp->DispImage(arr, n1, dopt, fgimagnav, 0, fglock);
[165]1384
[2762]1385AddWRsId_P(nom, wrsid);
[295]1386return;
1387}
1388/* --Methode-- */
[331]1389void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
[295]1390{
[2677]1391// Pas de display si option dopt = nodisp
1392if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1393
[3366]1394NObjMgrSync zs(0); zs.NOp();
[2491]1395
[295]1396NObjMgrAdapter* obja=NULL;
[2755]1397obja = GetObjAdapter_P(nom);
[295]1398if (obja == NULL) {
[449]1399 cout << "NamedObjMgr::DisplaySurf3D() Error , No such object " << nom << endl;
[295]1400 return;
1401}
[594]1402if (obja->GetDataObj() == NULL) {
1403 cerr << "NamedObjMgr::DisplaySurf3D() / Error - NULL object ! in " << nom << endl;
1404 return;
1405 }
[295]1406if (!myImgApp) return;
1407
1408P2DArrayAdapter* arr = obja->Get2DArray(dopt);
[165]1409
[295]1410if (!arr) {
1411 string ctyp = typeid(*(obja->GetDataObj())).name();
[449]1412 cout << "NamedObjMgr::DisplaySurf3D() Error , Not supported " << ctyp << endl;
[295]1413 return;
1414 }
[165]1415
[295]1416if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
1417 cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
[449]1418 << "x" << arr->YSize() << ") too big (max=250x250)" << endl;
[295]1419 delete arr;
1420 return;
[165]1421 }
1422
[344]1423string n1,r1;
1424ParseObjectName(nom, r1, n1);
1425
[2491]1426// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1427bool fglock = (_fgimgapp) ? false : true;
1428
[295]1429int wrsid = 0;
1430PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
[2491]1431wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt, "", 0, fglock);
[2762]1432AddWRsId_P(nom, wrsid);
[295]1433return;
[165]1434}
1435
1436/* --Methode-- */
[331]1437void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
[486]1438 string& erx, string& ery, string& erz, string& wt,
[3269]1439 string& label, string& colornm, bool coloridx, string dopt, bool fg3d)
[165]1440{
[2677]1441// Pas de display si option dopt = nodisp
1442if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1443
[3366]1444NObjMgrSync zs(0); zs.NOp();
[2491]1445
[2755]1446AnyDataObj* obj=GetObj_P(nom);
[165]1447if (obj == NULL) {
[449]1448 cout << "NamedObjMgr::DisplayNT() Error , No such object " << nom << endl;
[165]1449 return;
1450}
1451if (!myImgApp) return;
1452
[326]1453NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
1454if (nt == NULL) {
1455// if (typeid(*obj) != typeid(NTupleInterface)) {
[295]1456 string ctyp = typeid(*obj).name();
[449]1457 cout << "NamedObjMgr::DisplayNT() Error , Object not an NTuple " << ctyp << endl;
[165]1458 return;
1459 }
1460
1461int wrsid = 0;
[1971]1462dopt = "defline " + dopt;
[165]1463
[344]1464string n1,r1;
1465ParseObjectName(nom, r1, n1);
1466
[2491]1467// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1468bool fglock = (_fgimgapp) ? false : true;
1469
[333]1470if ( fg3d && (nmz.length()>0) ) { // Display 3D
[326]1471 PINTuple3D* pin = new PINTuple3D(nt, false);
[165]1472 pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
[486]1473 pin->SelectWt(wt.c_str());
1474 pin->SelectLabel(label.c_str());
[165]1475 pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
1476 string titre = nmz + "%" + nmy + "%" + nmz;
[2491]1477 wrsid = myImgApp->Disp3DDrawer(pin, n1, dopt, titre, 0, fglock);
[165]1478}
1479else {
[326]1480 PINTuple* pin = new PINTuple(nt, false);
[165]1481 pin->SelectXY(nmx.c_str(), nmy.c_str());
[486]1482 pin->SelectWt(wt.c_str());
1483 pin->SelectLabel(label.c_str());
[165]1484 pin->SelectErrBar(erx.c_str(), ery.c_str());
[3269]1485 if (colornm.length() > 0) { // Juin 2007 : gestion de nom de colonne pour la couleur
1486 if (coloridx) pin->SelectColorByIndex(colornm.c_str());
1487 else pin->SelectColorByName(colornm.c_str());
1488 }
[333]1489 string titre = nmy + "%" + nmx;
[2491]1490 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, dopt, titre, 0, fglock);
[165]1491 }
1492
[2762]1493AddWRsId_P(nom, wrsid);
[165]1494return;
1495}
1496
[339]1497/* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */
[331]1498void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt)
[165]1499// Pour le display 2D ou 3D d'un ``GeneralFitData''.
1500//| nom = nom de l'objet GeneralFitData a representer.
1501//| numvarx = numero (nombre entier) de la 1ere variable d'abscisse.
1502//| numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D).
1503//| Pour le display 2D, numvary="" string vide.
1504//| err = qu'elles erreurs faut il representer ?
1505//| - 2D : x y xy (display y=f(x))
1506//| - 3D : x y z xy xz yz xzy (display z=f(x,y))
1507//| Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes
1508//| les barres d'erreurs sont representees.
1509//| opt = options generales pour le display.
1510{
[2677]1511// Pas de display si option dopt = nodisp
1512if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1513
[3366]1514NObjMgrSync zs(0); zs.NOp();
[2491]1515
[2755]1516AnyDataObj* obj=GetObj_P(nom);
[165]1517if(obj == NULL)
[449]1518 {cout << "NamedObjMgr::DisplayGFD() Error , No such object " << nom << endl;
[165]1519 return;}
1520if(!myImgApp) return;
[295]1521if(typeid(*obj) != typeid(GeneralFitData))
1522 {string ctyp = typeid(*obj).name();
[449]1523 cout<<"NamedObjMgr::DisplayGFD() Error , Object not a GeneralFitData "<<ctyp<<endl;
[165]1524 return;}
1525
1526// Decodage des erreurs a representer
1527bool errx=false, erry=false, errz=false;
1528if(err.length()>0) {
[2180]1529 for(int i=0;i<(int_4)err.length();i++)
[165]1530 if (err[i]=='x' || err[i]=='X') errx = true;
1531 else if(err[i]=='y' || err[i]=='Y') erry = true;
1532 else if(err[i]=='z' || err[i]=='Z') errz = true;
1533}
1534// Decodage des numeros de variables en abscisse
[339]1535 int numvx=-1, numvy=-1;
1536 if(numvarx.length()>0) numvx = atoi(numvarx.c_str());
1537 if(numvary.length()>0) numvy = atoi(numvary.c_str());
1538
[344]1539 string n1,r1;
1540 ParseObjectName(nom, r1, n1);
[2491]1541 // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1542 bool fglock = (_fgimgapp) ? false : true;
[344]1543
[339]1544 int wrsid = 0;
1545 if(numvy>=0) { // display 3D
[165]1546 PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
1547 pigfd->SelectXY(numvx,numvy);
1548 pigfd->SelectErrBar(errx,erry,errz);
[2491]1549 wrsid = myImgApp->Disp3DDrawer(pigfd,n1,dopt,"",0,fglock);
[339]1550} else { // display 2D
[165]1551 PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
1552 pigfd->SelectX(numvx);
1553 pigfd->SelectErrBar(errx,erry);
[2491]1554 wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,dopt,"",0,fglock);
[165]1555}
1556
[2762]1557AddWRsId_P(nom, wrsid);
[1971]1558
[165]1559return;
1560}
1561
[1525]1562/* --Methode-- */
1563void NamedObjMgr::DisplayVector(string & nomvx, string& nomvy, string dopt)
1564// Pour l'affichage 2-D de points avec coordonnees definies par deux vecteurs
1565// nomvx et nomvy
1566{
[2677]1567// Pas de display si option dopt = nodisp
1568if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1569
[3366]1570NObjMgrSync zs(0); zs.NOp();
[2491]1571
[1525]1572#ifdef SANS_EVOLPLANCK
1573 cerr << " NamedObjMgr::DisplayVector() Error: Not implemented with PEIDA " << endl;
1574#else
1575
1576if(!myImgApp) return;
1577
1578AnyDataObj* obj;
[2755]1579obj = GetObj_P(nomvx);
[1525]1580if(obj == NULL) {
1581 cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvx << endl;
1582 return;
1583}
[2263]1584//Vector * vx = dynamic_cast<Vector *>(obj);
1585BaseArray* bax = dynamic_cast<BaseArray *>(obj);
1586if (bax == NULL) {
1587 cout << "NamedObjMgr::DisplayVector() Error " << nomvx << " not a BaseArray ! " << endl;
[1525]1588 return;
1589}
1590
[2755]1591obj = GetObj_P(nomvy);
[1525]1592if(obj == NULL) {
1593 cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvy << endl;
1594 return;
1595}
[2263]1596BaseArray* bay = dynamic_cast<BaseArray *>(obj);
1597if (bay == NULL) {
1598 cout << "NamedObjMgr::DisplayVector() Error " << nomvy << " not a BaseArray ! " << endl;
[1525]1599 return;
1600}
1601
[2263]1602Vector vx = *bax;
1603Vector vy = *bay;
[1525]1604Vector * cvx, * cvy;
1605
[2263]1606if (vx.Size() != vy.Size()) {
[1525]1607 cout << "NamedObjMgr::DisplayVector() Warning / Vx.Size() != Vy.Size() " << endl;
[2263]1608 if (vx.Size() < vy.Size()) {
1609 cvx = new Vector(vx);
1610 cvy = new Vector(vy.SubVector(Range(0, 0, vx.Size()-1)));
[1525]1611 }
1612 else {
[2263]1613 cvx = new Vector(vx.SubVector(Range(0, 0, vy.Size()-1)));
1614 cvy = new Vector(vy);
[1525]1615 }
1616}
1617else {
[2263]1618 cvx = new Vector(vx);
1619 cvy = new Vector(vy);
[1525]1620}
1621
1622POVectorAdapter * avx = new POVectorAdapter(cvx, true);
1623POVectorAdapter * avy = new POVectorAdapter(cvy, true);
1624PIYfXDrawer * vxydrw = new PIYfXDrawer(avx, avy, true);
1625
1626string nx,rx;
1627ParseObjectName(nomvx, rx, nx);
1628string ny,ry;
1629ParseObjectName(nomvy, ry, ny);
1630
[2491]1631// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1632bool fglock = (_fgimgapp) ? false : true;
1633
[1525]1634string title = ny + " (Y) vs. " + nx + " (X)";
1635// display 2D
[2491]1636myImgApp->DispScDrawer(vxydrw, title, dopt, "", 0, fglock);
[1525]1637
1638return;
1639
1640#endif
1641}
1642
[165]1643/* --Methode--
[331]1644void NamedObjMgr::DisplayImage(string& nom, string dopt)
[165]1645{
1646 cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
1647}
1648*/
1649
1650
1651
1652
[1971]1653/* --Methode--
[165]1654void NamedObjMgr::SetGraphicAttributes(string gratt)
1655{
1656bool fg = false;
1657servnobjm->DecodeDispOption(gratt, fg);
[546]1658Services2NObjMgr::SetDefaultStatsOption(Services2NObjMgr::GetStatsOption(gratt));
[165]1659}
[333]1660
[165]1661void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
1662{
1663if (!myImgApp) return;
1664if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
1665else myImgApp->SetZone(nzx, nzy);
1666}
[1971]1667*/
[165]1668
1669/* --Methode-- */
[3355]1670int NamedObjMgr::NameToOId(string & nom)
1671{
[3366]1672NObjMgrSync zs(0); zs.NOp();
[3355]1673return NameToOId_P(nom);
1674}
1675
1676/* --Methode-- */
1677int NamedObjMgr::NameToOId_P(string & nom)
1678{
1679string n1,r1;
1680ParseObjectName(nom, r1, n1);
1681nom = '/' + r1 + '/' + n1;
1682NObjList::iterator it = myObjs->find(nom);
1683if (it == myObjs->end()) return(-1);
1684else return((*it).second.oid);
1685}
1686
1687
1688/* --Methode-- */
[333]1689void NamedObjMgr::AddWRsId(string & nom, int wrsid)
[165]1690{
[3366]1691NObjMgrSync zs(0); zs.NOp();
[2762]1692AddWRsId_P(nom, wrsid);
1693}
1694
1695/* --Methode-- */
1696void NamedObjMgr::AddWRsId_P(string & nom, int wrsid)
1697{
[333]1698if(wrsid != 0) {
1699 NObjList::iterator it = myObjs->find(nom);
1700 if (it == myObjs->end()) return;
1701 (*it).second.wrsid.push_back(wrsid);
[295]1702 }
[165]1703return;
1704}
1705
1706/* --Methode-- */
[333]1707void NamedObjMgr::UpdateObjMgrWindow(int did)
[165]1708{
[333]1709if (!myImgApp) return;
[3366]1710if (myMtxLocked) {
1711 obmWUpdReq = true;
1712 obmWvis = false;
1713 (myImgApp->ObjMgrW())->SetUnSensitive();
1714 return;
1715}
1716NObjMgrSync zs(0); zs.NOp();
1717if (did < 0) {
1718 string cdir = *currDir;
1719 cdir = '/' + cdir;
1720 (myImgApp->ObjMgrW())->SetCurDir(cdir);
1721 did = (myImgApp->ObjMgrW())->GetCurDirId();
1722}
1723
[2762]1724UpdateObjMgrWindow_P(did);
[3366]1725(myImgApp->ObjMgrW())->SetSensitive();
1726obmWUpdReq = false;
1727obmWvis = true;
[2762]1728}
1729
1730/* --Methode-- */
[3366]1731void NamedObjMgr::SetObjMgrWindowVisibility(bool fgvis)
1732{
1733obmWvis = fgvis;
1734}
1735
1736/* --Methode-- */
[2762]1737void NamedObjMgr::UpdateObjMgrWindow_P(int did)
1738{
1739if (!myImgApp) return;
[2492]1740if ( !_fgimgapp ) myImgApp->LockMutex();
[2762]1741if ( !(myImgApp->ObjMgrW())->Visible() ||
1742 ( (myImgApp->ObjMgrW())->GetCurDirId() != did) ) {
1743 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
1744 return;
1745 }
[2490]1746
[685]1747(myImgApp->ObjMgrW())->ClearObjList();
[165]1748
[333]1749NObjList::iterator it;
1750string cn;
1751for(it = myObjs->begin(); it != myObjs->end(); it++) {
1752 if ((*it).second.dirid != did) continue;
1753 cn = (*it).first.substr(1);
[1321]1754 // cn = cn.substr(cn.find('/')+1) + " (T= " + typeid(*((*it).second.obj)).name() + ")" ;
1755 cn = cn.substr(cn.find('/')+1) + " (T= " + (*it).second.obja->GetDataObjType() + ")" ;
[685]1756 (myImgApp->ObjMgrW())->AddObj(cn.c_str(), (*it).second.oid);
[165]1757 }
[2492]1758if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[2762]1759return;
[333]1760}
[165]1761
1762
[333]1763/* Nouvelle-Fonction */
[1207]1764void NamedObjMgr::RemoveSpacesFromName(string & nom)
[165]1765{
[333]1766// on supprime les blancs de debut et de fin
1767size_t p = nom.find_first_not_of(" ");
1768if(p>nom.length()) { nom = ""; return; }
1769nom = nom.substr(p);
1770p = nom.find(' ');
1771if(p>nom.length()) p=nom.length();
1772nom = nom.substr(0, p);
[165]1773}
1774
[333]1775/* Nouvelle-Fonction */
[1207]1776bool NamedObjMgr::CheckDirName(string & nom)
[165]1777{
[333]1778RemoveSpacesFromName(nom);
1779if (nom.length() < 1) return(false);
1780if (nom[0] == '/') nom = nom.substr(1) ;
1781size_t p = nom.find('/');
1782if (p < nom.length()) nom = nom.substr(0,p);
[2218]1783if ((nom.length() < 1) || (! isalpha(nom[0]) ) ) return(false);
[333]1784return(true);
[165]1785}
1786
[333]1787/* Nouvelle-Fonction */
[1207]1788int NamedObjMgr::ParseObjectName(string & nom, string & nomrep, string & nomobj)
[165]1789{
[333]1790RemoveSpacesFromName(nom);
1791// Si le nom ne commence pas par un slash, c'est le repertoire courant
1792if (nom[0] != '/') { nomrep = *currDir; nomobj = nom; }
[165]1793else {
[333]1794 string xx = nom.substr(1);
1795 size_t p = xx.find('/');
1796 if (p < xx.length()) {
1797 nomrep = xx.substr(0,p);
1798 nomobj = xx.substr(p+1);
[165]1799 }
[333]1800 else {
1801 nomrep = xx;
1802 nomobj = "";
[165]1803 }
1804 }
[333]1805int rc = 0;
1806NObjDirList::iterator it = myDirs->find(nomrep);
1807if (it != myDirs->end()) rc = (*it).second.id;
1808return(rc);
[165]1809}
1810
[2999]1811/* Nouvelle-Fonction */
1812bool NamedObjMgr::CheckName(string const & nom)
1813{
1814if (nom.length() < 1) return false;
1815if (! isalpha(nom[0]) ) return false;
1816for(int k=0; k<nom.length(); k++)
1817 if ((!isalnum(nom[k])) && (nom[k] != '_')) return false;
1818return true;
1819}
Note: See TracBrowser for help on using the repository browser.