Coin: SoBase.h Source File

| Coin3D is Free Software, published under the BSD 3-clause license. | https://coin3d.github.io https://www.kongsberg.com/en/kogt/

SoBase.h
1#ifndef COIN_SOBASE_H
2#define COIN_SOBASE_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <Inventor/SoType.h>
37#include <Inventor/lists/SoAuditorList.h>
38#include <Inventor/C/base/rbptree.h>
39
40class SbString;
41class SoBaseList;
42class SoInput;
43class SoOutput;
44
45 class COIN_DLL_API SoBase {
46public:
47 static void initClass(void);
48
49 void ref(void) const;
50 void unref(void) const;
51 void unrefNoDelete(void) const;
52 int32_t getRefCount(void) const;
53
54 void touch(void);
55
56 virtual SoType getTypeId(void) const = 0;
57 SbBool isOfType(SoType type) const;
58 static SoType getClassTypeId(void);
59
60 virtual SbName getName(void) const;
61 virtual void setName(const SbName & newname);
62
63 static void addName(SoBase * const base, const char * const name);
64 static void removeName(SoBase * const base, const char * const name);
65
66 virtual void startNotify(void);
67 virtual void notify(SoNotList * l);
68
69 void addAuditor(void * const auditor, const SoNotRec::Type type);
70 void removeAuditor(void * const auditor, const SoNotRec::Type type);
71 const SoAuditorList & getAuditors(void) const;
72
73 virtual void addWriteReference(SoOutput * out, SbBool isfromfield = FALSE);
74 SbBool shouldWrite(void);
75
76 static void incrementCurrentWriteCounter(void);
77 static void decrementCurrentWriteCounter(void);
78
79 static SoBase * getNamedBase(const SbName & name, SoType type);
80 static int getNamedBases(const SbName & name, SoBaseList & baselist,
81 SoType type);
82
83 static SbBool read(SoInput * input, SoBase *& base, SoType expectedtype);
84 static void setInstancePrefix(const SbString & c);
85
86 static void setTraceRefs(SbBool trace);
87 static SbBool getTraceRefs(void);
88
89 static SbBool connectRoute(SoInput * input,
90 const SbName & fromnodename, const SbName & fromfieldname,
91 const SbName & tonodename, const SbName & tofieldname);
92
93 void assertAlive(void) const;
94 static SbBool readRoute(SoInput * input);
95
96protected:
97 // Note: these are bitflags.
98 enum BaseFlags { IS_ENGINE = 0x01, IS_GROUP = 0x02 };
99
100 SoBase(void);
101 virtual ~SoBase();
102
103 virtual void destroy(void);
104
105 SbBool hasMultipleWriteRefs(void) const;
106 SbBool writeHeader(SoOutput * out, SbBool isgroup, SbBool isengine) const;
107 void writeFooter(SoOutput * out) const;
108 virtual const char * getFileFormatName(void) const;
109
110 virtual SbBool readInstance(SoInput * input, unsigned short flags) = 0;
111
112 static uint32_t getCurrentWriteCounter(void);
113 static void staticDataLock(void);
114 static void staticDataUnlock(void);
115
116 virtual SoNotRec createNotRec(void);
117
118private:
119 static void cleanClass(void);
120
121 static SoType classTypeId;
122
123 struct {
124 mutable signed int referencecount : 28;
125 mutable unsigned int alive : 4;
126 } objdata;
127
128 void doNotify(SoNotList * l, const void * auditor, const SoNotRec::Type type);
129 cc_rbptree auditortree;
130
131 class PImpl;
132 friend class PImpl; // MSVC6
133};
134
135// support for boost::intrusive_ptr<SoBase>
136inline void intrusive_ptr_add_ref(SoBase * obj) { obj->ref(); }
137inline void intrusive_ptr_release(SoBase * obj) { obj->unref(); }
138
139#endif // !COIN_SOBASE_H
SbName
The SbName class stores strings by reference.
Definition SbName.h:40
SbString
The SbString class is a string class with convenience functions for string operations.
Definition SbString.h:52
SoAuditorList
The SoAuditorList class is used to keep track of auditors for certain object classes.
Definition lists/SoAuditorList.h:52
SoBaseList
The SoBaseList class is a container for pointers to SoBase derived objects.
Definition SoBaseList.h:41
SoBase
The SoBase class is the top-level superclass for a number of class-hierarchies.
Definition SoBase.h:45
SoBase::unref
void unref(void) const
Definition SoBase.cpp:530
SoBase::BaseFlags
BaseFlags
Definition SoBase.h:98
SoBase::getTypeId
virtual SoType getTypeId(void) const =0
Returns the type identification of an object derived from a class inheriting SoBase....
SoBase::ref
void ref(void) const
Definition SoBase.cpp:478
SoBase::readInstance
virtual SbBool readInstance(SoInput *input, unsigned short flags)=0
SoInput
The SoInput class is an abstraction of file import functionality.
Definition SoInput.h:61
SoNotList
The SoNotList class is a list of SoNotRec notification records.
Definition SoNotification.h:43
SoNotRec
The SoNotRec class specifies records for notification lists.
Definition SoNotRec.h:42
SoNotRec::Type
Type
Definition SoNotRec.h:44
SoOutput
The SoOutput class is an abstraction of an output stream.
Definition SoOutput.h:51
SoType
The SoType class is the basis for the runtime type system in Coin.
Definition SoType.h:59
cc_rbptree
Definition rbptree.h:47