Main Page Modules Class Hierarchy Alphabetical List Compound List File List Compound Members

# 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-2003 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 <URL:http://www.coin3d.org> for  more information.
    00021  *
    00022  *  Systems in Motion, Teknobyen, Abels Gate 5, 7030 Trondheim, NORWAY.
    00023  *  <URL:http://www.sim.no>.
    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   // Note: these are bitflags.
    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     // The number of bits should sum up to 32, so we don't allocate
    00126     // more than one machine word on a 32-bit platform.
    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