1 /**************************************************************************\
2  * Copyright (c) Kongsberg Oil & Gas Technologies AS
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32 
33 
34 /*!
35   \class SoNotRec SoNotRec.h Inventor/misc/SoNotification.h
36   \brief The SoNotRec class specifies records for notification lists.
37 
38   \ingroup general
39 
40   \sa SoNotification
41 */
42 
43 /*!
44   \enum SoNotRec::Type
45 
46   This enum is used to specify the type of the notification source
47   within the record.
48 */
49 
50 /*!
51   \enum SoNotRec::OperationType
52 
53   This enum is used to specify the type of the scenegraph operation
54   causing the notification.
55 */
56 
57 #include <Inventor/misc/SoNotRec.h>
58 #include <Inventor/errors/SoDebugError.h>
59 #include <cassert>
60 
61 #if COIN_DEBUG  // for SoNotRec::print() method
62 #include <Inventor/misc/SoBase.h>
63 #include <Inventor/SbName.h>
64 #endif // COIN_DEBUG
65 
66 
67 /*!
68   Constructor. Initializes the record with \a notifbase pointer.
69 */
SoNotRec(SoBase * const notifbase)70 SoNotRec::SoNotRec(SoBase * const notifbase) :
71   type((SoNotRec::Type)-1), base(notifbase), prev(NULL), index(-1),
72   fieldNumIndices(0), operationType(UNSPECIFIED), groupChild(NULL), groupPrevChild(NULL)
73 {
74 }
75 
76 /*!
77   Set the \a type of the notification source of this record.
78 */
79 void
setType(const SoNotRec::Type typearg)80 SoNotRec::setType(const SoNotRec::Type typearg)
81 {
82   this->type = typearg;
83 }
84 
85 /*!
86   Returns the notification source within this record.
87 */
88 SoBase *
getBase(void) const89 SoNotRec::getBase(void) const
90 {
91   return this->base;
92 }
93 
94 /*!
95   Returns the type of the notification source within this record.
96 */
97 SoNotRec::Type
getType(void) const98 SoNotRec::getType(void) const
99 {
100   return this->type;
101 }
102 
103 /*!
104   Returns the previous notification source (i.e. the source that the
105   base within this record was auditing).
106 */
107 const SoNotRec *
getPrevious(void) const108 SoNotRec::getPrevious(void) const
109 {
110 #if 0 // OBSOLETED: see comment on setPrevious(). 20000304 mortene.
111   assert(this != this->prev);
112 #endif // OBSOLETED
113   return this->prev;
114 }
115 
116 /*!
117   Set pointer to the previous notification record.
118 */
119 void
setPrevious(const SoNotRec * const prevptr)120 SoNotRec::setPrevious(const SoNotRec * const prevptr)
121 {
122 #if 0 // OBSOLETED: looks like this can be allowed (and need to be
123       // allowed under the current circumstances, as it hits under certain
124       // conditions). 20000304 mortene
125   assert(this != prevptr);
126 #endif // OBSOLETED
127   this->prev = prevptr;
128 }
129 
130 /*!
131   Prints debug information.
132 */
133 void
print(FILE * const file) const134 SoNotRec::print(FILE * const file) const
135 {
136 #if COIN_DEBUG
137   (void)fprintf(file, "\tSoNotRec %p: type ", this);
138   switch (this->type) {
139   case CONTAINER:  (void)fprintf(file, "CONTAINER"); break;
140   case PARENT:     (void)fprintf(file, "PARENT"); break;
141   case SENSOR:     (void)fprintf(file, "SENSOR"); break;
142   case FIELD:      (void)fprintf(file, "FIELD"); break;
143   case ENGINE:     (void)fprintf(file, "ENGINE"); break;
144   default:         (void)fprintf(file, "UNSET"); break;
145   }
146   if (this->base) {
147     (void)fprintf(file, ", base %p (type %s, \"%s\")\n",
148                   this->base, this->base->getTypeId().getName().getString(),
149                   this->base->getName().getString());
150   }
151   else {
152     (void)fprintf(file," base is NULL\n");
153   }
154 #endif // COIN_DEBUG
155 }
156 
157 SoNotRec::OperationType
getOperationType(void) const158 SoNotRec::getOperationType(void) const
159 {
160   return operationType;
161 }
162 
163 int
getIndex(void) const164 SoNotRec::getIndex(void) const
165 {
166   return index;
167 }
168 
169 int
getFieldNumIndices(void) const170 SoNotRec::getFieldNumIndices(void) const
171 {
172   return fieldNumIndices;
173 }
174 
175 const SoBase *
getGroupChild(void) const176 SoNotRec::getGroupChild(void) const
177 {
178   return groupChild;
179 }
180 
181 const SoBase *
getGroupPrevChild(void) const182 SoNotRec::getGroupPrevChild(void) const
183 {
184   return groupPrevChild;
185 }
186 
187 void
setOperationType(const SoNotRec::OperationType opType)188 SoNotRec::setOperationType(const SoNotRec::OperationType opType)
189 {
190   this->operationType = opType;
191 }
192 
193 void
setIndex(const int idx)194 SoNotRec::setIndex(const int idx)
195 {
196   this->index = idx;
197 }
198 
199 void
setFieldNumIndices(const int fldnumind)200 SoNotRec::setFieldNumIndices(const int fldnumind)
201 {
202   this->fieldNumIndices = fldnumind;
203 }
204 
205 void
setGroupChild(const SoBase * const gc)206 SoNotRec::setGroupChild(const SoBase * const gc)
207 {
208   this->groupChild = gc;
209 }
210 
211 void
setGroupPrevChild(const SoBase * const pc)212 SoNotRec::setGroupPrevChild(const SoBase * const pc)
213 {
214   this->groupPrevChild = pc;
215 }
216