00001 #ifndef COIN_SOBASE_H
00002 #define COIN_SOBASE_H
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 #include <Inventor/SoType.h>
00028 #include <Inventor/lists/SoAuditorList.h>
00029 #include <Inventor/C/base/rbptree.h>
00030
00031 class SbString;
00032 class SoBaseList;
00033 class SoInput;
00034 class SoOutput;
00035
00036 class COIN_DLL_API SoBase {
00037
00038 public:
00039 static void initClass(void);
00040
00041 void ref(void) const;
00042 void unref(void) const;
00043 void unrefNoDelete(void) const;
00044 int32_t getRefCount(void) const;
00045
00046 void touch(void);
00047
00048 virtual SoType getTypeId(void) const = 0;
00049 SbBool isOfType(SoType type) const;
00050 static SoType getClassTypeId(void);
00051
00052 virtual SbName getName(void) const;
00053 virtual void setName(const SbName & newname);
00054
00055 static void addName(SoBase * const base, const char * const name);
00056 static void removeName(SoBase * const base, const char * const name);
00057
00058 virtual void startNotify(void);
00059 virtual void notify(SoNotList * l);
00060
00061 void addAuditor(void * const auditor, const SoNotRec::Type type);
00062 void removeAuditor(void * const auditor, const SoNotRec::Type type);
00063 const SoAuditorList & getAuditors(void) const;
00064
00065 virtual void addWriteReference(SoOutput * out, SbBool isfromfield = FALSE);
00066 SbBool shouldWrite(void);
00067
00068 static void incrementCurrentWriteCounter(void);
00069 static void decrementCurrentWriteCounter(void);
00070
00071 static SoBase * getNamedBase(const SbName & name, SoType type);
00072 static int getNamedBases(const SbName & name, SoBaseList & baselist,
00073 SoType type);
00074
00075 static SbBool read(SoInput * in, SoBase *& base, SoType expectedtype);
00076 static void setInstancePrefix(const SbString & c);
00077
00078 static void setTraceRefs(SbBool trace);
00079 static SbBool getTraceRefs(void);
00080
00081 static SbBool connectRoute(SoInput * in,
00082 const SbName & fromnodename, const SbName & fromfieldname,
00083 const SbName & tonodename, const SbName & tofieldname);
00084
00085 void assertAlive(void) const;
00086 static SbBool readRoute(SoInput * in);
00087
00088 protected:
00089
00090 enum BaseFlags { IS_ENGINE = 0x01, IS_GROUP = 0x02 };
00091
00092 SoBase(void);
00093 virtual ~SoBase();
00094
00095 virtual void destroy(void);
00096
00097 SbBool hasMultipleWriteRefs(void) const;
00098 SbBool writeHeader(SoOutput * out, SbBool isgroup, SbBool isengine) const;
00099 void writeFooter(SoOutput * out) const;
00100 virtual const char * getFileFormatName(void) const;
00101
00102 virtual SbBool readInstance(SoInput * in, unsigned short flags) = 0;
00103
00104 static uint32_t getCurrentWriteCounter(void);
00105
00106
00107 private:
00108 static SbBool readReference(SoInput * in, SoBase *& base);
00109 static SbBool readBase(SoInput * in, SbName & classname, SoBase *& base);
00110 static SbBool readBaseInstance(SoInput * in, const SbName & classname,
00111 const SbName & refname, SoBase *& base);
00112
00113 static SoBase * createInstance(SoInput * in, const SbName & classname);
00114 static void flushInput(SoInput * in);
00115
00116 static void cleanClass(void);
00117 static void freeLists(unsigned long, void * value);
00118
00119 static SoType classTypeId;
00120
00121 struct {
00122 int32_t referencecount : 27;
00123 unsigned int ingraph : 1;
00124 unsigned int alive : 4;
00125
00126
00127 } objdata;
00128
00129 void doNotify(SoNotList * l, const void * auditor, const SoNotRec::Type type);
00130 static void rbptree_notify_cb(void * auditor, void * type, void * closure);
00131 cc_rbptree auditortree;
00132
00133 static SbDict * name2obj;
00134 static SbDict * obj2name;
00135
00136 static SbString * refwriteprefix;
00137
00138 static SbBool tracerefs;
00139 static uint32_t writecounter;
00140 };
00141
00142 #endif // !COIN_SOBASE_H