Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoAuditorList.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Paul S. Strauss (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2018 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifndef _SO_AUDITOR_LIST_
51#define _SO_AUDITOR_LIST_
52
53#include <Inventor/misc/SoNotification.h>
54#include <Inventor/STL/vector>
55
56#ifdef _WIN32
57#pragma warning(push)
58#pragma warning(disable:4251)
59#endif
60
62//
63// Class: SoAuditorList
64//
65// SoAuditorList class. This class maintains a list of instances that
66// audit (receive notification from) an SoBase or SoField. Each entry
67// in the list consists of a pointer to the auditor (base or field)
68// instance and a type code of type SoNotRec::Type.
69//
70// The type of the auditor object pointer depends on the type code,
71// as follows:
72//
73// Type code: Auditor object pointer:
74//
75// CONTAINER The SoFieldContainer containing the field
76// PARENT The parent node
77// SENSOR The SoDataSensor instance
78// FIELD The destination field instance
79// ENGINE The destination field instance
80// UNDEFINED null
81//
83{
84 private:
85 struct AuditorListValue {
86 void* auditor;
87 SoNotRec::Type type;
88
89 AuditorListValue(void* auditor_, SoNotRec::Type type_)
90 : auditor(auditor_), type(type_)
91 {
92 }
93
94 AuditorListValue()
95 : auditor(0), type(SoNotRec::UNDEFINED)
96 {
97 }
98 };
99 typedef std::vector<AuditorListValue> ListContainer;
100
101 public:
102 typedef AuditorListValue value_type;
103 // Constructor and destructor.
104 SoAuditorList();
105 virtual ~SoAuditorList();
106
107 typedef ListContainer::iterator iterator;
108 typedef ListContainer::const_iterator const_iterator;
109
110 // Adds an auditor of the given type to the list
111 void append(void *auditor, SoNotRec::Type type);
112
113 // Finds an auditor in the list, returning the index or -1 if not found
114 iterator find(void *auditor, SoNotRec::Type type);
115 const_iterator find(void *auditor, SoNotRec::Type type) const;
116
117 // Removes an auditor from the list
118 size_t remove(void *auditor, SoNotRec::Type type);
119 // Returns number of auditors in list
120 virtual int getLength() const;
121 size_t size() const;
122 bool empty() const;
123 // Call a functor object on all auditor/type pairs in the list. This
124 // is safe even if auditors are being added or removed.
125 template<typename Func>
126 void traverse(const Func& func)
127 {
128 if (m_list.empty())
129 return;
130 m_isTraversing++;
131 ListContainer::size_type i = m_list.size();
132 do
133 {
134 --i;
135 const value_type& v = m_list[i];
136 void* auditor = v.auditor;
137 if (auditor)
138 {
139 SoNotRec::Type type = v.type;
140 func(auditor, type);
141 }
142 } while (i != 0);
143 m_isTraversing--;
144 }
145 // Traverse in forward direction i.e., the order that auditors were
146 // added. For compatibility.
147 template<typename Func>
148 void traverse_forward(const Func& func)
149 {
150 if (m_list.empty())
151 return;
152 m_isTraversing++;
153 for (ListContainer::size_type i = 0, e = m_list.size();
154 i != e;
155 ++i)
156 {
157 const value_type& v = m_list[i];
158 void* auditor = v.auditor;
159 if (auditor)
160 {
161 SoNotRec::Type type = v.type;
162 func(auditor, type);
163 }
164 }
165 m_isTraversing--;
166 }
167 // Propagates notification to all auditors in list
168 void notify(SoNotList *list);
169
170 iterator begin();
171 const_iterator begin() const;
172 const_iterator cbegin() const;
173 iterator end();
174 const_iterator end() const;
175 const_iterator cend() const;
176 private:
177
178 ListContainer m_list;
179
180 size_t numAuds;
181 struct AuditorMap;
182 AuditorMap* m_fastFindDict;
183 int m_isTraversing;
184
185 void compact();
186};
187
188#ifdef _WIN32
189#pragma warning(pop)
190#endif
191
192#endif /* _SO_AUDITOR_LIST_ */
193
194