Open Inventor Reference
|
00001 /* 00002 * 00003 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * Further, this software is distributed without any warranty that it is 00016 * free of the rightful claim of any third person regarding infringement 00017 * or the like. Any license provided herein, whether implied or 00018 * otherwise, applies only to this software file. Patent licenses, if 00019 * any, provided herein do not apply to combinations of this program with 00020 * other software, or any other product whatsoever. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 * 00026 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 00027 * Mountain View, CA 94043, or: 00028 * 00029 * http://www.sgi.com 00030 * 00031 * For further information regarding this notice, see: 00032 * 00033 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 00034 * 00035 */ 00036 00037 00038 /* 00039 * Copyright (C) 1990,91,92 Silicon Graphics, Inc. 00040 * 00041 _______________________________________________________________________ 00042 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00043 | 00044 | $Revision: 1.1.1.1 $ 00045 | 00046 | Description: 00047 | Definition of SoBase, the base class for several other Inventor 00048 | classes. This class handles reference counting and 00049 | notification and is the main entry point for reading and 00050 | writing derived classes. 00051 | 00052 | Author(s) : Paul S. Strauss, Nick Thompson, Gavin Bell 00053 | 00054 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00055 _______________________________________________________________________ 00056 */ 00057 00058 #ifndef _SO_BASE_ 00059 #define _SO_BASE_ 00060 00061 #include <Inventor/system/SbSystem.h> 00062 #include <Inventor/misc/SoBasic.h> 00063 #include <Inventor/misc/SoAuditorList.h> 00064 #include <Inventor/SbString.h> 00065 #include <Inventor/SoType.h> 00066 00067 class SoBaseList; 00068 class SoInput; 00069 class SoNode; 00070 class SoNotList; 00071 class SoOutput; 00072 class SoPath; 00073 00074 00077 00087 00088 00089 class INVENTOR_API SoBase { 00090 public: 00091 00113 void ref() const; 00114 00116 void unref() const; 00117 00119 void unrefNoDelete() const; 00120 00124 void touch() { startNotify(); } 00125 00127 static SoType getClassTypeId() { return classTypeId; } 00128 00130 virtual SoType getTypeId() const = 0; 00131 00139 SbBool isOfType(SoType type) const; 00140 00146 virtual SbName getName() const; 00147 00159 virtual void setName(const SbName &name); 00160 00161 protected: 00163 SoBase(); 00164 00166 virtual ~SoBase(); 00167 00170 virtual void destroy(); 00171 00173 static uint32_t getCurrentWriteCounter() 00174 { return currentWriteCounter; } 00175 00177 SbBool hasMultipleWriteRefs() const 00178 { return writeStuff.multWriteRef; } 00179 00186 SbBool writeHeader(SoOutput *out, 00187 SbBool isGroup, SbBool isEngine) const; 00188 void writeFooter(SoOutput *out) const; 00189 00193 virtual const char *getFileFormatName() const; 00194 00198 enum BaseFlags { 00199 IS_ENGINE = 1, 00200 IS_GROUP = 2 00201 }; 00202 00207 virtual SbBool readInstance(SoInput *in, unsigned short flags) = 0; 00208 00209 SoINTERNAL public: 00210 00212 static void initClass(); 00213 00215 static void incrementCurrentWriteCounter() 00216 { currentWriteCounter++; } 00217 00220 static void decrementCurrentWriteCounter() 00221 { currentWriteCounter--; } 00222 00226 virtual void startNotify(); 00227 00233 virtual void notify(SoNotList *list); 00234 00236 void addAuditor(void *auditor, SoNotRec::Type type); 00237 void removeAuditor(void *auditor, SoNotRec::Type type); 00238 00241 const SoAuditorList &getAuditors() { return auditors; } 00242 00244 static SbBool traceRefs; 00245 00247 static void addName(SoBase *, const char *); 00248 static void removeName(SoBase *, const char *); 00249 00251 static SoBase *getNamedBase(const SbName &, SoType); 00252 static int getNamedBases(const SbName &, SoBaseList &, 00253 SoType); 00254 00256 int getRefCount() const { return refCount; } 00257 00263 static SbBool read(SoInput *in, SoBase *&base, 00264 SoType expectedType); 00265 00269 virtual void addWriteReference(SoOutput *out, 00270 SbBool isFromField = FALSE); 00271 00274 SbBool shouldWrite(); 00275 00279 static void setInstancePrefix(const SbString &c) { instancePrefix = c; } 00280 00281 private: 00282 00283 static SoType classTypeId; 00284 00285 static SbString instancePrefix; 00286 00289 static uint32_t currentWriteCounter; 00290 00292 int refCount; 00293 00295 SoAuditorList auditors; 00296 00298 struct { 00299 00302 unsigned int writeCounter : 29; 00303 00305 unsigned int hasName : 1; 00306 00309 unsigned int multWriteRef : 1; 00310 00313 unsigned int writeRefFromField : 1; 00314 00315 } writeStuff; 00316 00318 void writeDef(SoOutput *, int) const; 00319 void writeRef(SoOutput *, int) const; 00320 void writeAnnotation(SoOutput *) const; 00321 00323 static SbBool readReference(SoInput *in, SoBase *&base); 00324 static SbBool readBase(SoInput *in, SbName &className, 00325 SoBase *&base); 00326 static SbBool readBaseInstance(SoInput *in, const SbName &className, 00327 const SbName &refName, SoBase *&base); 00328 static SoBase *createInstance(SoInput *in, SbName className, 00329 unsigned short ioFlags); 00330 static void flushInput(SoInput *in); 00331 00336 static SbDict *nameObjDict; 00337 00340 static SbDict *objNameDict; 00341 }; 00342 00343 #endif /* _SO_BASE_ */