00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef _SO_BASE_
00053 #define _SO_BASE_
00054
00055 #include <Inventor/misc/SoBasic.h>
00056 #include <Inventor/misc/SoAuditorList.h>
00057 #include <Inventor/misc/SoRefCounter.h>
00058 #include <Inventor/SbString.h>
00059 #include <Inventor/SoTypedObject.h>
00060 #include <Inventor/threads/SbThreadLocalStorage.h>
00061 #include <Inventor/threads/SbThreadSpinlock.h>
00062
00063 class SoBaseList;
00064 class SoInput;
00065 class SoNode;
00066 class SoNotList;
00067 class SoOutput;
00068 class SoPath;
00069 class SoVRMLPROTODef;
00070 class SoVRMLEXTERNPROTODef;
00071 class SoVRMLISRef;
00072
00073 #ifdef _WIN32
00074 #pragma warning(push)
00075 #pragma warning(disable:4251)
00076 #endif
00077
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00091
00092
00116 class SoBase: public SoRefCounter, public SoTypedObject {
00117 public:
00118
00124 virtual void touch() { startNotify(); }
00125
00129 static SoType getClassTypeId();
00130
00136 virtual SbName getName() const;
00137
00159 virtual void setName(const SbName &name);
00160
00165 inline void setSynchronizable( const bool b );
00166
00170 inline bool isSynchronizable() const ;
00171
00175 static SoVRMLPROTODef * getPROTO(const SbName &name) ;
00176
00181 static SoVRMLEXTERNPROTODef * getEXTERNPROTO(const SbName &name) ;
00182
00183 private:
00184
00185
00186 SoBase();
00187
00188
00189 virtual ~SoBase();
00190
00195 virtual bool notifyDelete() const;
00196
00197
00198
00199 virtual void destroy();
00200
00201
00202 static uint32_t getCurrentWriteCounter();
00203
00204
00205 SbBool hasMultipleWriteRefs() const
00206 { return writeStuff.multWriteRef; }
00207
00208
00209
00210
00211 virtual const char* getFileFormatName() const;
00212
00213
00214
00215
00216 enum BaseFlags {
00217 IS_ENGINE = 1,
00218 IS_GROUP = 2
00219 };
00220
00221
00222
00223
00224
00225 virtual SbBool readInstance(SoInput *in, unsigned short flags) = 0;
00226
00227 private:
00228
00229
00230 static void initClass();
00231 static void exitClass();
00232
00233 SB_THREAD_TLS_HEADER();
00234
00235 static SbBool addToISDict(SoVRMLISRef *isRef, SoNode *node);
00236 static SbBool addToDEFDict(const SbName &name, SoBase *base);
00237 static SbBool addToPROTODict(const SbName &name, SoBase *base);
00238 static SbBool addToEXTERNPROTODict(const SbName &name, SoBase *base);
00239 static SoBase* findReferenceInProto(const SbName &name) ;
00240 static SoBase* findPROTO(const SbName &name) ;
00241 static SoBase* findEXTERNPROTO(const SbName &name) ;
00242
00243 static void resetWriteCounter();
00244
00245
00246 static void incrementCurrentWriteCounter();
00247
00248
00249
00250 static void decrementCurrentWriteCounter();
00251
00252
00253
00254
00255 virtual void startNotify();
00256
00257
00258
00259
00260
00261
00262 virtual void notify(SoNotList *list);
00263
00264
00265 void addAuditor(void *auditor, SoNotRec::Type type);
00266 void removeAuditor(void *auditor, SoNotRec::Type type);
00267
00268
00269
00270 const SoAuditorList &getAuditors() const { return auditors; }
00271
00272
00273 static void addName(SoBase *, const char *);
00274 static void removeName(SoBase *, const char *);
00275
00276
00277 static SoBase *getNamedBase(const SbName &, const SoType&);
00278 static int getNamedBases(const SbName &, SoBaseList &, const SoType&);
00279
00280
00281 virtual void setNetName( const SbName &netName);
00282
00283
00284 virtual SbName getNetName() const;
00285
00286
00287 virtual void generateNetName();
00288
00289
00290 inline void setSynchronized( const bool b );
00291
00292
00293 inline bool isSynchronized() const;
00294
00303 SbBool writeHeader(SoOutput* , SbBool , SbBool ) const;
00304 void writeFooter(SoOutput* ) const;
00305
00306 virtual bool isGroup() { return false; }
00307
00308
00309
00310
00311
00312
00313 static SbBool read(SoInput *in, SoBase *&base, const SoType &expectedType, SbBool createAndRead = TRUE);
00314
00315
00316
00317
00318 virtual void addWriteReference(SoOutput *out, SbBool isFromField = FALSE);
00319
00320
00321
00322 SbBool shouldWrite();
00323
00324
00325
00326
00327 static void setInstancePrefix(const SbString &c);
00328
00329 static SbBool topLevel;
00330 static int readingEXTERNPROTO;
00331 static SoVRMLPROTODef *protoDefSave;
00332 static SbDict *EXTERNPROTODict;
00333
00334 static SoVRMLPROTODef * getActualProtoDef() {return SoBase::protoDefSave;}
00335
00336
00337 static int readingPROTO;
00338
00339
00340 static SbPList *PROTOStack;
00341 static SbDict *PROTODictionary;
00342 static int PROTODepth;
00343 static void pushCurPROTODict(SbDict *dict) ;
00344 static SbDict * popCurPROTODict() ;
00345
00346
00347 static SbPList *EXTERNPROTOStack;
00348 static int EXTERNPROTODepth;
00349 static void pushCurEXTERNPROTODict(SbDict *dict);
00350 static SbDict * popCurEXTERNPROTODict();
00351
00352
00353 static SbPList *ISStack;
00354 static SbDict *ISDict;
00355 static int ISDepth;
00356 static void pushCurISDict(SbDict *dict) ;
00357 static SbDict * popCurISDict() ;
00358
00359
00360 static SbPList *DEFStack;
00361 static SbDict *DEFDictionary;
00362 static int DEFDepth;
00363 static void pushCurDEFDict(SbDict *dict) ;
00364 static SbDict * popCurDEFDict() ;
00365 static SbPList *ROUTEList;
00366 static SbPList *EXPORTList;
00367 static SbPList *IMPORTList;
00368 static SbPList *METAList;
00369 static SbPList *COMPONENTList;
00370
00371
00372 struct WriteStuff {
00373
00374
00375 unsigned int writeCounter : 26;
00376
00377
00378 unsigned int hasName : 1;
00379 unsigned int hasNetName : 1;
00380
00381
00382
00383 unsigned int multWriteRef : 1;
00384
00385
00386
00387 unsigned int writeRefFromField : 1;
00388
00389
00390
00391 unsigned int isSynchronized : 1;
00392
00393
00394
00395 unsigned int isSynchronizable : 1;
00396
00397
00398 WriteStuff();
00399 };
00400
00401 WriteStuff writeStuff;
00402
00403 private:
00404
00405 static SoType classTypeId;
00406
00407 #if defined(sun)
00408 static SbString instancePrefix;
00409 #else
00410 static SbString instancePrefix;
00411 #endif
00412
00413 struct MTstruct
00414 {
00415
00416
00417 uint32_t currentWriteCounter;
00418 };
00419
00420
00421 SoAuditorList auditors;
00422
00423
00424 void writeDef(SoOutput *, int) const;
00425 void writeRef(SoOutput *, int) const;
00426 void writeAnnotation(SoOutput *) const;
00427 void writeAnnotation1(SoOutput *) const;
00428
00429
00430 static SbBool readROUTEInstance(SoInput *in, SbName &className, SoBase *&base);
00431 static SbBool readEXPORTInstance(SoInput *in, SbName &className, SoBase *&base);
00432 static SbBool readIMPORTInstance(SoInput *in, SbName &className, SoBase *&base);
00433 static SbBool readMETA(SoInput *in, SbName &className, SoBase *&base);
00434 static SbBool readCOMPONENT(SoInput *in, SbName &className, SoBase *&base);
00435 static SbBool readPROTO(SoInput *in, SbName &className, SoBase *&base);
00436 static SbBool protoRead(SoInput *in, SoBase *&base, SoType expectedType, SoVRMLPROTODef *protoDef);
00437 static SoBase* createPROTOInstance(SoVRMLPROTODef *protoDef);
00438 static SoBase* createEXTERNPROTOInstance( SoVRMLEXTERNPROTODef *externprotoDef);
00439
00440 static SbBool readReference(SoInput *in, SoBase *&base);
00441 static SbBool readBase(SoInput *in, SbName &className, SoBase *&base, SbBool createAndRead = TRUE);
00442 static SbBool readBaseInstance( SoInput *in,
00443 const SbName &className, const SbName &refName,
00444 const SbName &netName, SoBase *&base, SbBool createAndRead = TRUE);
00445 static SoBase* createInstance(SoInput *in, SbName className, unsigned short ioFlags);
00446
00447 static void flushInput(SoInput *in);
00448 static SbBool readPROFILEName(SoInput *in,SbName &className, SoBase *&base);
00449
00450
00451
00452
00453 static SbDict *nameObjDict;
00454
00455
00456
00457 static SbDict *objNameDict;
00458
00459 static SbThreadMutex s_classMutex;
00460 };
00461
00462 #ifdef _WIN32
00463 #pragma warning(pop)
00464 #endif
00465
00469 class SoBaseInitializer
00470 {
00471 public:
00472 SoBaseInitializer(SoBase*);
00473 ~SoBaseInitializer();
00474 static inline bool isActive()
00475 {
00476 s_activeMutex.lock();
00477 bool ret = m_active;
00478 s_activeMutex.unlock();
00479 return ret;
00480 }
00481 private:
00482 SoBase* m_base;
00483 bool m_sync;
00484 bool m_prevActive;
00485 static bool m_active;
00486 static SbThreadSpinlock s_activeMutex;
00487 };
00488
00489
00490 void
00491 SoBase::setSynchronizable( const bool b )
00492 {
00493 writeStuff.isSynchronizable = b;
00494 }
00495
00496 bool
00497 SoBase::isSynchronizable() const
00498 {
00499 return writeStuff.isSynchronizable;
00500 }
00501
00502 void
00503 SoBase::setSynchronized( const bool b )
00504 {
00505 writeStuff.isSynchronized = b;
00506 }
00507
00508 bool
00509 SoBase::isSynchronized() const
00510 {
00511 return writeStuff.isSynchronized;
00512 }
00513
00514 #endif
00515
00516