Open Inventor Reference
SoBase.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37
38/*
39 * Copyright (C) 1990,91,92 Silicon Graphics, Inc.
40 *
41 _______________________________________________________________________
42 ______________ S I L I C O N G R A P H I C S I N C . ____________
43 |
44 | $Revision: 1.1.1.1 $
45 |
46 | Description:
47 | Definition of SoBase, the base class for several other Inventor
48 | classes. This class handles reference counting and
49 | notification and is the main entry point for reading and
50 | writing derived classes.
51 |
52 | Author(s) : Paul S. Strauss, Nick Thompson, Gavin Bell
53 |
54 ______________ S I L I C O N G R A P H I C S I N C . ____________
55 _______________________________________________________________________
56 */
57
58#ifndef _SO_BASE_
59#define _SO_BASE_
60
64#include <Inventor/SbString.h>
65#include <Inventor/SoType.h>
66#include <Inventor/misc/SoRef.h>
67
68class SoBaseList;
69class SoInput;
70class SoNode;
71class SoNotList;
72class SoOutput;
73class SoPath;
74
75
78
89
91 public:
92
114 void ref() const;
115
117 void unref() const;
118
120 void unrefNoDelete() const;
121
125 void touch() { startNotify(); }
126
128 static SoType getClassTypeId() { return classTypeId; }
129
131 virtual SoType getTypeId() const = 0;
132
140 bool isOfType(SoType type) const;
141
147 virtual SbName getName() const;
148
160 virtual void setName(const SbName &name);
161
162 protected:
165
167 virtual ~SoBase();
168
171 virtual void destroy();
172
175 { return currentWriteCounter; }
176
179 { return writeStuff.multWriteRef; }
180
188 bool isGroup, bool isEngine) const;
189 void writeFooter(SoOutput *out) const;
190
194 virtual const char *getFileFormatName() const;
195
200 IS_ENGINE = 1,
201 IS_GROUP = 2
202 };
203
208 virtual bool readInstance(SoInput *in, unsigned short flags) = 0;
209
210 SoINTERNAL public:
211
213 static void initClass();
214
217 { currentWriteCounter++; }
218
222 { currentWriteCounter--; }
223
227 virtual void startNotify();
228
234 virtual void notify(SoNotList *list);
235
237 void addAuditor(void *auditor, SoNotRec::Type type);
238 void removeAuditor(void *auditor, SoNotRec::Type type);
239
242 const SoAuditorList &getAuditors() { return auditors; }
243
245 static bool traceRefs;
246
248 static void addName(SoBase *, const char *);
249 static void removeName(SoBase *, const char *);
250
252 static SoBase *getNamedBase(const SbName &, SoType);
253 static int getNamedBases(const SbName &, SoBaseList &,
254 SoType);
255
257 int getRefCount() const { return refCount; }
258
264 static bool read(SoInput *in, SoBase *&base,
265 SoType expectedType);
266
270 virtual void addWriteReference(SoOutput *out,
271 bool isFromField = FALSE);
272
276
280 static void setInstancePrefix(const SbString &c) { instancePrefix = c; }
281
282 private:
283
284 static SoType classTypeId;
285
286 static SbString instancePrefix;
287
290 static uint32_t currentWriteCounter;
291
293 int refCount;
294
296 SoAuditorList auditors;
297
299 struct {
300
303 unsigned int writeCounter : 29;
304
306 unsigned int hasName : 1;
307
310 unsigned int multWriteRef : 1;
311
314 unsigned int writeRefFromField : 1;
315
316 } writeStuff;
317
319 void writeDef(SoOutput *, int) const;
320 void writeRef(SoOutput *, int) const;
321 void writeAnnotation(SoOutput *) const;
322
324 static bool readReference(SoInput *in, SoBase *&base);
325 static bool readBase(SoInput *in, SbName &className,
326 SoBase *&base);
327 static bool readBaseInstance(SoInput *in, const SbName &className,
328 const SbName &refName, SoBase *&base);
329 static SoBase *createInstance(SoInput *in, SbName className,
330 unsigned short ioFlags);
331 static void flushInput(SoInput *in);
332
337 static SbDict *nameObjDict;
338
341 static SbDict *objNameDict;
342};
343
344#endif /* _SO_BASE_ */
#define FALSE
Definition SbBasic.h:79
#define SoINTERNAL
Definition SbBasic.h:155
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
unsigned int uint32_t
Definition SbTypeDefs.h:44
This is a dictionary mapping (size_t) integer keys to (void *) data pointers.
Definition SbDict.h:101
Character string stored in a hash table.
Definition SbString.h:264
Class for smart character strings.
Definition SbString.h:85
SoAuditorList class.
Subclasses of the SbPList class which hold lists of pointers of a specific type.
Definition SoLists.h:117
Base class for all nodes, paths, and engines.
Definition SoBase.h:90
void unrefNoDelete() const
static void removeName(SoBase *, const char *)
void addAuditor(void *auditor, SoNotRec::Type type)
Adds/removes an auditor to/from list.
bool shouldWrite()
Returns TRUE if the instance should be written, based on the write-reference info already accumulated...
void removeAuditor(void *auditor, SoNotRec::Type type)
static uint32_t getCurrentWriteCounter()
Returns current write counter.
Definition SoBase.h:174
static void addName(SoBase *, const char *)
Internal methods used to maintain the global name dictionary.
virtual void setName(const SbName &name)
Sets the name of an instance.
virtual void startNotify()
Initiates notification from an instance.
const SoAuditorList & getAuditors()
Returns auditor list– used by SoField and SoEngineOutput to trace forward connections.
Definition SoBase.h:242
virtual bool readInstance(SoInput *in, unsigned short flags)=0
Reads stuff into instance of subclass.
unsigned int hasName
This is TRUE if the object is named.
Definition SoBase.h:306
unsigned int writeCounter
This contains the value of the counter the last time the instance was written.
Definition SoBase.h:303
void touch()
Marks an instance as modified, simulating a change to it.
Definition SoBase.h:125
SoBase()
Constructor is protected - this is an abstract class.
static void setInstancePrefix(const SbString &c)
This defaults to "+" and is used when naming nodes that are DEF's and USE'd.
Definition SoBase.h:280
BaseFlags
This set of enums is used when reading and writing the base.
Definition SoBase.h:199
unsigned int writeRefFromField
This is TRUE if the instance was referenced via a field-to-field connection, which is not a "real" re...
Definition SoBase.h:314
static void decrementCurrentWriteCounter()
Decrements the current write counter after a write operation, in some rare cases.
Definition SoBase.h:221
virtual void notify(SoNotList *list)
Propagates modification notification through an instance.
virtual const char * getFileFormatName() const
Unknown nodes and engines write a different name for themselves than their typeId; this virtual metho...
virtual SoType getTypeId() const =0
Returns the type identifier for a specific instance.
bool hasMultipleWriteRefs() const
Returns TRUE if the instance has multiple write references.
Definition SoBase.h:178
virtual void destroy()
Actually deletes an instance.
void unref() const
void ref() const
Adds and removes a reference to an instance.
static bool traceRefs
Turns on/off reference count tracing (for debugging)
Definition SoBase.h:245
virtual SbName getName() const
Returns the name of an instance.
bool isOfType(SoType type) const
Returns TRUE if this object is of the type specified in type or is derived from that type.
unsigned int multWriteRef
This is TRUE if more than one reference is made to the instance for writing, meaning that we need to ...
Definition SoBase.h:310
static bool read(SoInput *in, SoBase *&base, SoType expectedType)
Reads one instance of some subclass of SoBase.
static void incrementCurrentWriteCounter()
Increments the current write counter at the start of a write operation.
Definition SoBase.h:216
bool writeHeader(SoOutput *out, bool isGroup, bool isEngine) const
Writes a header (name, open brace) or footer (close brace) to file defined by SoOutput.
void writeFooter(SoOutput *out) const
static void initClass()
Setup type information.
virtual ~SoBase()
Virtual destructor so that subclasses are deleted properly.
static SoBase * getNamedBase(const SbName &, SoType)
Helper routines used to get stuff out of nameDict.
virtual void addWriteReference(SoOutput *out, bool isFromField=FALSE)
Adds a reference to the instance when writing.
static SoType getClassTypeId()
Returns type identifier for this class.
Definition SoBase.h:128
static int getNamedBases(const SbName &, SoBaseList &, SoType)
int getRefCount() const
Returns current reference count.
Definition SoBase.h:257
Used to read Inventor data files.
Definition SoInput.h:128
Abstract base class for all database nodes.
Definition SoNode.h:103
Holds a list of SoNotRec notification records.
Type
Notification types (what receives notification).
Used to write Inventor data files.
Definition SoOutput.h:90
Path that points to a list of hierarchical nodes.
Definition SoPath.h:109
SoType has no virtual functions to keep it small...
Definition SoType.h:103