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
40 class SbString;
41 class SoBaseList;
42 class SoInput;
43 class SoOutput;
44
45 class COIN_DLL_API SoBase {
46 public:
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
96 protected:
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
118 private:
119 static void cleanClass(void);
120
121 static SoType classTypeId;
122
123 struct {
124 mutable 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>
intrusive_ptr_add_ref(SoBase * obj)136 inline void intrusive_ptr_add_ref(SoBase * obj) { obj->ref(); }
intrusive_ptr_release(SoBase * obj)137 inline void intrusive_ptr_release(SoBase * obj) { obj->unref(); }
138
139 #endif // !COIN_SOBASE_H
140