src/Sim/Op/OpArray/OpArray.h

説明を見る。
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_ARRAY_OP_ARRAY_H
00033 #define SIM_OP_OP_ARRAY_OP_ARRAY_H
00034 
00035 #include "Utility/RuntimeError.h"
00036 
00037 namespace Onikiri
00038 {
00039 
00040     // forward declaration
00041     class OpIterator;
00042     class Op;
00043 
00044     class OpArray 
00045     {
00046     public:
00047         typedef int ID;
00048 
00049         class ArrayID
00050         {
00051         public:
00052             ArrayID() : 
00053                 m_op(0),
00054                 m_opArray(0),
00055                 m_id(0)
00056             {}
00057             
00058             ArrayID(
00059                 Op* op, 
00060                 OpArray* opArray,
00061                 ID id
00062             ) :
00063                 m_op(op), 
00064                 m_opArray(opArray), 
00065                 m_id(id)
00066             {}
00067             
00068             ArrayID(const ArrayID& arrayID) : 
00069                 m_op(arrayID.m_op), 
00070                 m_opArray(arrayID.m_opArray), 
00071                 m_id(arrayID.m_id)
00072             {}
00073 
00074             virtual ~ArrayID();
00075 
00076             // accessors
00077             Op* GetOp() const  { return m_op; }
00078             void SetOp(Op* op)
00079             {
00080                 ASSERT(m_op == 0, "SetOp called twice.");           
00081                 m_op = op;
00082             }
00083 
00084             const OpArray* GetOpArray() const { return m_opArray; }
00085             const ID       GetID()      const { return m_id;     }
00086         
00087         private:
00088             Op*         m_op;
00089             OpArray*    m_opArray;
00090             ID          m_id;
00091 
00092         };  // class ArrayID
00093 
00094     public:
00095         // constructor & destructor
00096         OpArray( int capacity );
00097         virtual ~OpArray();
00098         
00099         // copy ~
00100         OpArray( const OpArray& opArray )
00101         {
00102             THROW_RUNTIME_ERROR("cannot create OpArray copy");
00103         };
00104         
00105         // VOpAOpIterator
00106         OpIterator CreateOp();
00107 
00108         // OpIteratorwOp
00109         void ReleaseOp(const OpIterator& opIterator);
00110         // OpIteratorwOpCopyS
00111         void ReleaseAll(const OpIterator& opIterator);
00112 
00113         // OpIteratorwOp
00114         bool IsAlive(const OpIterator& opIterator) const;
00115         bool IsAlive( ID id ) const
00116         {
00117             ASSERT(
00118                 id >= 0 && id < m_capacity,
00119                 "id range error(id = %d, capacity = %d)",
00120                 id,
00121                 m_capacity
00122             );
00123 
00124             return m_alive[id];
00125         }
00126 
00127         bool IsFull() const
00128         {
00129             return m_freeList.size() == 0;
00130         }
00131 
00132         bool IsEmpty() const
00133         {
00134             return GetSize() == 0;
00135         }
00136 
00137         int GetSize() const 
00138         {
00139             return GetCapacity() - static_cast<int>(m_freeList.size());
00140         }
00141 
00142         int GetCapacity() const
00143         {
00144             return m_capacity;
00145         }
00146 
00147     protected:
00148         // Op  pool 
00149         // IDz
00150         std::vector<OpArray::ArrayID*> m_body;
00151 
00152         // gptO
00153         // Copyz
00154         boost::dynamic_bitset<> m_alive;
00155 
00156         // \Xg
00157         pool_vector<ID> m_freeList;
00158 
00159         // mTCY
00160         int m_capacity;
00161     };
00162 
00163 
00164     class OpIterator 
00165     {
00166     public:
00167         INLINE OpIterator()
00168             : m_arrayID(0)
00169         {
00170         }
00171 
00172         INLINE OpIterator( OpArray::ArrayID* arrayID )
00173             : m_arrayID(arrayID)
00174         {
00175         }
00176 
00177         INLINE OpIterator( const OpIterator& iterator )
00178             : m_arrayID( iterator.m_arrayID )
00179         {
00180         }
00181 
00182         const OpArray::ArrayID* GetArrayID() const
00183         {
00184             return m_arrayID;
00185         }
00186 
00187         Op* GetOp() const
00188         {
00189             return m_arrayID->GetOp();
00190         }
00191 
00192         const OpArray::ID GetID() const
00193         {
00194             return m_arrayID->GetID();
00195         }
00196 
00197         bool IsAlive() const
00198         {
00199             return m_arrayID->GetOpArray()->IsAlive(*this);
00200         }
00201 
00202         bool IsNull() const
00203         {
00204             return m_arrayID == 0 || GetOp() == 0;
00205         }
00206         
00207         // pointer  operator
00208         Op& operator*() const
00209         {
00210             return *m_arrayID->GetOp();
00211         }
00212 
00213         Op* operator->() const
00214         {
00215             return m_arrayID->GetOp();
00216         }
00217 
00218         bool operator==(const OpIterator& rhv) const
00219         {
00220             return m_arrayID == rhv.GetArrayID();
00221         }
00222 
00223         bool operator!=(const OpIterator& rhv) const
00224         {
00225             return !(*this == rhv);
00226         }
00227 
00228     protected:
00229         OpArray::ArrayID* m_arrayID;
00230     };
00231 
00232 
00233     
00234 }; // namespace Onikiri
00235 
00236 #endif // SIM_OP_OP_ARRAY_OP_ARRAY_H
00237 

Onikiri2に対してTue Jun 18 14:34:24 2013に生成されました。  doxygen 1.4.7