00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : Paul S. Strauss (MMM yyyy) 00025 **=======================================================================*/ 00026 /*======================================================================= 00027 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00028 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00029 *** *** 00030 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00031 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00032 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00033 *** *** 00034 *** RESTRICTED RIGHTS LEGEND *** 00035 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00036 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00037 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00038 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00039 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00040 *** *** 00041 *** COPYRIGHT (C) 1996-2018 BY FEI S.A.S, *** 00042 *** BORDEAUX, FRANCE *** 00043 *** ALL RIGHTS RESERVED *** 00044 **=======================================================================*/ 00045 /*======================================================================= 00046 ** Modified by : VSG (MMM YYYY) 00047 **=======================================================================*/ 00048 00049 00050 #ifndef _SO_AUDITOR_LIST_ 00051 #define _SO_AUDITOR_LIST_ 00052 00053 #include <Inventor/misc/SoNotification.h> 00054 #include <Inventor/STL/vector> 00055 00056 #ifdef _WIN32 00057 #pragma warning(push) 00058 #pragma warning(disable:4251) 00059 #endif 00060 00062 // 00063 // Class: SoAuditorList 00064 // 00065 // SoAuditorList class. This class maintains a list of instances that 00066 // audit (receive notification from) an SoBase or SoField. Each entry 00067 // in the list consists of a pointer to the auditor (base or field) 00068 // instance and a type code of type SoNotRec::Type. 00069 // 00070 // The type of the auditor object pointer depends on the type code, 00071 // as follows: 00072 // 00073 // Type code: Auditor object pointer: 00074 // 00075 // CONTAINER The SoFieldContainer containing the field 00076 // PARENT The parent node 00077 // SENSOR The SoDataSensor instance 00078 // FIELD The destination field instance 00079 // ENGINE The destination field instance 00080 // UNDEFINED null 00081 // 00083 { 00084 private: 00085 struct AuditorListValue { 00086 void* auditor; 00087 SoNotRec::Type type; 00088 00089 AuditorListValue(void* auditor_, SoNotRec::Type type_) 00090 : auditor(auditor_), type(type_) 00091 { 00092 } 00093 00094 AuditorListValue() 00095 : auditor(0), type(SoNotRec::UNDEFINED) 00096 { 00097 } 00098 }; 00099 typedef std::vector<AuditorListValue> ListContainer; 00100 00101 public: 00102 typedef AuditorListValue value_type; 00103 // Constructor and destructor. 00104 SoAuditorList(); 00105 virtual ~SoAuditorList(); 00106 00107 typedef ListContainer::iterator iterator; 00108 typedef ListContainer::const_iterator const_iterator; 00109 00110 // Adds an auditor of the given type to the list 00111 void append(void *auditor, SoNotRec::Type type); 00112 00113 // Finds an auditor in the list, returning the index or -1 if not found 00114 iterator find(void *auditor, SoNotRec::Type type); 00115 const_iterator find(void *auditor, SoNotRec::Type type) const; 00116 00117 // Removes an auditor from the list 00118 size_t remove(void *auditor, SoNotRec::Type type); 00119 // Returns number of auditors in list 00120 virtual int getLength() const; 00121 size_t size() const; 00122 bool empty() const; 00123 // Call a functor object on all auditor/type pairs in the list. This 00124 // is safe even if auditors are being added or removed. 00125 template<typename Func> 00126 void traverse(const Func& func) 00127 { 00128 if (m_list.empty()) 00129 return; 00130 m_isTraversing++; 00131 ListContainer::size_type i = m_list.size(); 00132 do 00133 { 00134 --i; 00135 const value_type& v = m_list[i]; 00136 void* auditor = v.auditor; 00137 if (auditor) 00138 { 00139 SoNotRec::Type type = v.type; 00140 func(auditor, type); 00141 } 00142 } while (i != 0); 00143 m_isTraversing--; 00144 } 00145 // Traverse in forward direction i.e., the order that auditors were 00146 // added. For compatibility. 00147 template<typename Func> 00148 void traverse_forward(const Func& func) 00149 { 00150 if (m_list.empty()) 00151 return; 00152 m_isTraversing++; 00153 for (ListContainer::size_type i = 0, e = m_list.size(); 00154 i != e; 00155 ++i) 00156 { 00157 const value_type& v = m_list[i]; 00158 void* auditor = v.auditor; 00159 if (auditor) 00160 { 00161 SoNotRec::Type type = v.type; 00162 func(auditor, type); 00163 } 00164 } 00165 m_isTraversing--; 00166 } 00167 // Propagates notification to all auditors in list 00168 void notify(SoNotList *list); 00169 00170 iterator begin(); 00171 const_iterator begin() const; 00172 const_iterator cbegin() const; 00173 iterator end(); 00174 const_iterator end() const; 00175 const_iterator cend() const; 00176 private: 00177 00178 ListContainer m_list; 00179 00180 size_t numAuds; 00181 struct AuditorMap; 00182 AuditorMap* m_fastFindDict; 00183 int m_isTraversing; 00184 00185 void compact(); 00186 }; 00187 00188 #ifdef _WIN32 00189 #pragma warning(pop) 00190 #endif 00191 00192 #endif /* _SO_AUDITOR_LIST_ */ 00193 00194 00195