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 #ifndef SIM_OP_OP_CONTAINER_OP_LIST_H 00033 #define SIM_OP_OP_CONTAINER_OP_LIST_H 00034 00035 #include "Utility/RuntimeError.h" 00036 #include "Sim/Op/OpArray/OpArray.h" 00037 00038 namespace Onikiri 00039 { 00040 class OpList 00041 : private pool_list<OpIterator> 00042 { 00043 public: 00044 typedef pool_list<OpIterator> list_type; 00045 typedef pool_list<OpIterator>::iterator iterator; 00046 typedef pool_list<OpIterator>::const_iterator const_iterator; 00047 00048 OpList(); 00049 OpList( const OpArray& opArray ); 00050 virtual ~OpList(); 00051 00052 void resize( const OpArray& opArray ); 00053 void resize( int capacity ); 00054 00055 iterator get_iterator( const OpIterator& opIterator ) const; 00056 iterator get_original_iterator( const OpIterator& opIterator ) const; 00057 iterator operator[]( const OpIterator& opIterator ) const; 00058 iterator insert( iterator pos, const OpIterator& opIterator ); 00059 iterator erase( const OpIterator& opIterator ); 00060 iterator erase( iterator pos ); 00061 void clear(); 00062 iterator find( const OpIterator& opIterator ); 00063 size_t count( const OpIterator& op ) const; 00064 void push_inorder( OpIterator op ); 00065 bool find_and_erase( OpIterator op ); 00066 00067 size_t size() const 00068 { 00069 return list_type::size(); 00070 } 00071 00072 bool empty() const 00073 { 00074 return list_type::empty(); 00075 } 00076 00077 iterator begin() 00078 { 00079 return list_type::begin(); 00080 } 00081 00082 const_iterator begin() const 00083 { 00084 return list_type::begin(); 00085 } 00086 00087 iterator end() 00088 { 00089 return list_type::end(); 00090 } 00091 00092 const_iterator end() const 00093 { 00094 return list_type::end(); 00095 } 00096 00097 OpIterator& front() 00098 { 00099 return list_type::front(); 00100 } 00101 00102 OpIterator& back() 00103 { 00104 return list_type::back(); 00105 } 00106 00107 const OpIterator& front() const 00108 { 00109 return list_type::front(); 00110 } 00111 00112 const OpIterator& back() const 00113 { 00114 return list_type::back(); 00115 } 00116 00117 void push_front( const OpIterator& opIterator ) 00118 { 00119 insert( begin(), opIterator ); 00120 } 00121 00122 void push_back( const OpIterator& opIterator ) 00123 { 00124 insert( end(), opIterator ); 00125 } 00126 00127 void pop_front() 00128 { 00129 erase( begin() ); 00130 } 00131 00132 void pop_back() 00133 { 00134 erase( --end() ); 00135 } 00136 00137 template <class SortCmpT> 00138 void sort(SortCmpT cmp) 00139 { 00140 list_type::sort(cmp); 00141 } 00142 00143 // Move ops from other list to this list. 00144 void move( OpList* from ) 00145 { 00146 for( iterator i = from->begin(); i != from->end(); ){ 00147 push_inorder( *i ); 00148 i = from->erase(i); 00149 } 00150 } 00151 00152 protected: 00153 boost::dynamic_bitset<> alive_table; 00154 std::vector< iterator > iterator_table; 00155 00156 }; 00157 }; // namespace Onikiri 00158 00159 #endif // SIM_OP_OP_CONTAINER_OP_LIST_H 00160