Coin Logo http://www.sim.no
http://www.coin3d.org

SoBase.h

00001 #ifndef COIN_SOBASE_H
00002 #define COIN_SOBASE_H
00003 
00004 /**************************************************************************\
00005  *
00006  *  This file is part of the Coin 3D visualization library.
00007  *  Copyright (C) 1998-2007 by Systems in Motion.  All rights reserved.
00008  *
00009  *  This library is free software; you can redistribute it and/or
00010  *  modify it under the terms of the GNU General Public License
00011  *  ("GPL") version 2 as published by the Free Software Foundation.
00012  *  See the file LICENSE.GPL at the root directory of this source
00013  *  distribution for additional information about the GNU GPL.
00014  *
00015  *  For using Coin with software that can not be combined with the GNU
00016  *  GPL, and for taking advantage of the additional benefits of our
00017  *  support services, please contact Systems in Motion about acquiring
00018  *  a Coin Professional Edition License.
00019  *
00020  *  See http://www.coin3d.org/ for more information.
00021  *
00022  *  Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
00023  *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
00024  *
00025 \**************************************************************************/
00026 
00027 #include <Inventor/SoType.h>
00028 #include <Inventor/lists/SoAuditorList.h>
00029 #include <Inventor/C/base/rbptree.h>
00030 
00031 // *************************************************************************
00032 
00033 class SbDict;
00034 class SbString;
00035 class SoBaseList;
00036 class SoInput;
00037 class SoOutput;
00038 
00039 // *************************************************************************
00040 
00041 class COIN_DLL_API SoBase {
00042 
00043 public:
00044   static void initClass(void);
00045 
00046   void ref(void) const;
00047   void unref(void) const;
00048   void unrefNoDelete(void) const;
00049   int32_t getRefCount(void) const;
00050 
00051   void touch(void);
00052 
00053   virtual SoType getTypeId(void) const = 0;
00054   SbBool isOfType(SoType type) const;
00055   static SoType getClassTypeId(void);
00056 
00057   virtual SbName getName(void) const;
00058   virtual void setName(const SbName & newname);
00059 
00060   static void addName(SoBase * const base, const char * const name);
00061   static void removeName(SoBase * const base, const char * const name);
00062 
00063   virtual void startNotify(void);
00064   virtual void notify(SoNotList * l);
00065 
00066   void addAuditor(void * const auditor, const SoNotRec::Type type);
00067   void removeAuditor(void * const auditor, const SoNotRec::Type type);
00068   const SoAuditorList & getAuditors(void) const;
00069 
00070   virtual void addWriteReference(SoOutput * out, SbBool isfromfield = FALSE);
00071   SbBool shouldWrite(void);
00072 
00073   static void incrementCurrentWriteCounter(void);
00074   static void decrementCurrentWriteCounter(void);
00075 
00076   static SoBase * getNamedBase(const SbName & name, SoType type);
00077   static int getNamedBases(const SbName & name, SoBaseList & baselist,
00078                            SoType type);
00079 
00080   static SbBool read(SoInput * in, SoBase *& base, SoType expectedtype);
00081   static void setInstancePrefix(const SbString & c);
00082 
00083   static void setTraceRefs(SbBool trace);
00084   static SbBool getTraceRefs(void);
00085 
00086   static SbBool connectRoute(SoInput * in,
00087                              const SbName & fromnodename, const SbName & fromfieldname,
00088                              const SbName & tonodename, const SbName & tofieldname);
00089 
00090   void assertAlive(void) const;
00091   static SbBool readRoute(SoInput * in);
00092 
00093 protected:
00094   // Note: these are bitflags.
00095   enum BaseFlags { IS_ENGINE = 0x01, IS_GROUP = 0x02 };
00096 
00097   SoBase(void);
00098   virtual ~SoBase();
00099 
00100   virtual void destroy(void);
00101 
00102   SbBool hasMultipleWriteRefs(void) const;
00103   SbBool writeHeader(SoOutput * out, SbBool isgroup, SbBool isengine) const;
00104   void writeFooter(SoOutput * out) const;
00105   virtual const char * getFileFormatName(void) const;
00106 
00107   virtual SbBool readInstance(SoInput * in, unsigned short flags) = 0;
00108 
00109   static uint32_t getCurrentWriteCounter(void);
00110   static void staticDataLock(void);
00111   static void staticDataUnlock(void);
00112 
00113 private:
00114   static SbBool readReference(SoInput * in, SoBase *& base);
00115   static SbBool readBase(SoInput * in, SbName & classname, SoBase *& base);
00116   static SbBool readBaseInstance(SoInput * in, const SbName & classname,
00117                                  const SbName & refname, SoBase *& base);
00118 
00119   static SoBase * createInstance(SoInput * in, const SbName & classname);
00120   static void flushInput(SoInput * in);
00121 
00122   static void cleanClass(void);
00123 
00124 // OBSOLETE! Just kept around for Coin 2.x ABI compatibility.
00125   static void freeLists(unsigned long, void * value);
00126 
00127   static SoType classTypeId;
00128 
00129   struct {
00130     int32_t referencecount  : 27;
00131     unsigned int ingraph    :  1;
00132     unsigned int alive      :  4;
00133     // The number of bits should sum up to 32, so we don't allocate
00134     // more than one machine word on a 32-bit platform.
00135   } objdata;
00136 
00137   void doNotify(SoNotList * l, const void * auditor, const SoNotRec::Type type);
00138   static void rbptree_notify_cb(void * auditor, void * type, void * closure);
00139   cc_rbptree auditortree;
00140 
00141   // OBSOLETE! Just kept around for Coin 2.x ABI compatibility.
00142   static SbDict * name2obj;
00143   static SbDict * obj2name;
00144 
00145   static SbString * refwriteprefix;
00146 
00147   static SbBool tracerefs;
00148   static uint32_t writecounter;
00149 };
00150 
00151 #endif // !COIN_SOBASE_H

Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.

Generated on Mon Feb 28 2011 10:11:53 for Coin by Doxygen. 1.7.3