00001 // 00002 // Copyright (c) 2005-2008 Kenichi Watanabe. 00003 // Copyright (c) 2005-2008 Yasuhiro Watari. 00004 // Copyright (c) 2005-2008 Hironori Ichibayashi. 00005 // Copyright (c) 2008-2009 Kazuo Horio. 00006 // Copyright (c) 2009-2013 Naruki Kurata. 00007 // Copyright (c) 2005-2013 Ryota Shioya. 00008 // Copyright (c) 2005-2013 Masahiro Goshima. 00009 // 00010 // This software is provided 'as-is', without any express or implied 00011 // warranty. In no event will the authors be held liable for any damages 00012 // arising from the use of this software. 00013 // 00014 // Permission is granted to anyone to use this software for any purpose, 00015 // including commercial applications, and to alter it and redistribute it 00016 // freely, subject to the following restrictions: 00017 // 00018 // 1. The origin of this software must not be misrepresented; you must not 00019 // claim that you wrote the original software. If you use this software 00020 // in a product, an acknowledgment in the product documentation would be 00021 // appreciated but is not required. 00022 // 00023 // 2. Altered source versions must be plainly marked as such, and must not be 00024 // misrepresented as being the original software. 00025 // 00026 // 3. This notice may not be removed or altered from any source 00027 // distribution. 00028 // 00029 // 00030 00031 00032 // 00033 // Event list 00034 // 00035 00036 #ifndef SIM_FOUNDATION_EVENT_EVENT_LIST_H 00037 #define SIM_FOUNDATION_EVENT_EVENT_LIST_H 00038 00039 #include "Sim/Foundation/Event/EventBase.h" 00040 00041 namespace Onikiri 00042 { 00043 #if 1 00044 // vector giC[uタ 00045 class EventList 00046 { 00047 public: 00048 // A bit mask for selective event cancel. 00049 typedef u32 MaskType; 00050 static const int EVENT_MASK_POS_DEFAULT = 0; 00051 static const int EVENT_MASK_POS_USER = 1; 00052 00053 static const MaskType EVENT_MASK_DEFAULT = 1 << EVENT_MASK_POS_DEFAULT; 00054 static const MaskType EVENT_MASK_ALL = ~((MaskType)0); 00055 00056 struct Entry 00057 { 00058 EventPtr event; 00059 MaskType mask; 00060 00061 INLINE Entry( const EventPtr& e = EventPtr(), MaskType m = EVENT_MASK_DEFAULT ) : 00062 event( e ), 00063 mask ( m ) 00064 { 00065 } 00066 }; 00067 00068 typedef pool_vector< Entry > ListType; 00069 typedef ListType::iterator IteratorType; 00070 typedef ListType::const_iterator ConstIteratorType; 00071 00072 EventList() 00073 { 00074 m_inProcess = false; 00075 } 00076 00077 INLINE void AddEvent( const EventPtr& eventPtr, MaskType mask = EVENT_MASK_DEFAULT ) 00078 { 00079 ASSERT( !m_inProcess ); 00080 m_list.push_back( Entry( eventPtr, mask ) ); 00081 } 00082 00083 // Cancel events specified by the 'mask'. 00084 INLINE void Cancel( MaskType mask = EVENT_MASK_ALL ) 00085 { 00086 ASSERT( !m_inProcess ); 00087 m_inProcess = true; 00088 00089 if( mask == EVENT_MASK_ALL ){ 00090 for( ListType::iterator i = m_list.begin(); i != m_list.end(); ++i ){ 00091 i->event->Cancel(); 00092 } 00093 m_list.clear(); 00094 } 00095 else{ 00096 for( ListType::iterator i = m_list.begin(); i != m_list.end(); ++i ){ 00097 if( mask & i->mask ){ 00098 i->event->Cancel(); 00099 } 00100 } 00101 } 00102 m_inProcess = false; 00103 } 00104 00105 int Size() const 00106 { 00107 return (int)m_list.size(); 00108 } 00109 00110 INLINE void Clear() 00111 { 00112 m_list.clear(); 00113 } 00114 00115 ConstIteratorType begin() const 00116 { 00117 return m_list.begin(); 00118 } 00119 00120 ConstIteratorType end() const 00121 { 00122 return m_list.end(); 00123 } 00124 00125 private: 00126 ListType m_list; 00127 bool m_inProcess; 00128 00129 }; 00130 #else 00131 // TCYuゥO 00132 class EventList 00133 { 00134 private: 00135 typedef pool_vector< EventPtr > ListType; 00136 ListType m_list; 00137 int m_size; 00138 00139 public: 00140 typedef pool_vector< EventPtr >::iterator IteratorType; 00141 typedef pool_vector< EventPtr >::const_iterator ConstIteratorType; 00142 00143 EventList() 00144 { 00145 m_size = 0; 00146 } 00147 00148 void AddEvent(const EventPtr& eventPtr) 00149 { 00150 int size = m_size; 00151 if( (int)m_list.size() <= size ){ 00152 m_list.resize( size + 1 ); 00153 } 00154 m_list[size] = eventPtr; 00155 m_size = size + 1; 00156 } 00157 00158 void Cancel() 00159 { 00160 IteratorType begin = m_list.begin(); 00161 IteratorType end = begin + m_size; 00162 for( IteratorType i = begin; i != end; ++i ){ 00163 (*i)->Cancel(); 00164 *i = NULL; // |C^NA 00165 } 00166 m_size = 0; 00167 } 00168 00169 int Size() 00170 { 00171 return (int)m_size; 00172 } 00173 00174 void Clear() 00175 { 00176 IteratorType begin = m_list.begin(); 00177 IteratorType end = begin + m_size; 00178 for( IteratorType i = begin; i != end; ++i ){ 00179 *i = NULL; // |C^NA 00180 } 00181 m_size = 0; 00182 } 00183 00184 void Trigger() 00185 { 00186 IteratorType begin = m_list.begin(); 00187 IteratorType end = begin + m_size; 00188 for( IteratorType i = begin; i != end; ++i ){ 00189 (*i)->Trigger(); 00190 } 00191 } 00192 00193 ConstIteratorType begin() const 00194 { 00195 return m_list.begin(); 00196 } 00197 00198 ConstIteratorType end() const 00199 { 00200 return begin() + m_size; 00201 } 00202 }; 00203 #endif 00204 } 00205 00206 00207 #endif // SIM_FOUNDATION_EVENT_E_EVENT_LIST_H 00208