IceContainer.h
Go to the documentation of this file.
00001 
00002 
00008 
00009 
00011 // Include Guard
00012 #ifndef __ICECONTAINER_H__
00013 #define __ICECONTAINER_H__
00014 
00015         #define CONTAINER_STATS
00016 
00017         enum FindMode
00018         {
00019                 FIND_CLAMP,
00020                 FIND_WRAP,
00021 
00022                 FIND_FORCE_DWORD = 0x7fffffff
00023         };
00024 
00025         class ICECORE_API Container
00026         {
00027                 public:
00028                 // Constructor / Destructor
00029                                                                 Container();
00030                                                                 Container(const Container& object);
00031                                                                 Container(udword size, float growth_factor);
00032                                                                 ~Container();
00033                 // Management
00035 
00046 
00047                 inline_ Container&              Add(udword entry)
00048                                                                 {
00049                                                                         // Resize if needed
00050                                                                         if(mCurNbEntries==mMaxNbEntries)        Resize();
00051 
00052                                                                         // Add new entry
00053                                                                         mEntries[mCurNbEntries++]       = entry;
00054                                                                         return *this;
00055                                                                 }
00056 
00057                 inline_ Container&              Add(const udword* entries, udword nb)
00058                                                                 {
00059                                                                         // Resize if needed
00060                                                                         if(mCurNbEntries+nb>mMaxNbEntries)      Resize(nb);
00061 
00062                                                                         // Add new entry
00063                                                                         CopyMemory(&mEntries[mCurNbEntries], entries, nb*sizeof(udword));
00064                                                                         mCurNbEntries+=nb;
00065                                                                         return *this;
00066                                                                 }
00067 
00069 
00080 
00081                 inline_ Container&              Add(float entry)
00082                                                                 {
00083                                                                         // Resize if needed
00084                                                                         if(mCurNbEntries==mMaxNbEntries)        Resize();
00085 
00086                                                                         // Add new entry
00087                                                                         mEntries[mCurNbEntries++]       = IR(entry);
00088                                                                         return *this;
00089                                                                 }
00090 
00091                 inline_ Container&              Add(const float* entries, udword nb)
00092                                                                 {
00093                                                                         // Resize if needed
00094                                                                         if(mCurNbEntries+nb>mMaxNbEntries)      Resize(nb);
00095 
00096                                                                         // Add new entry
00097                                                                         CopyMemory(&mEntries[mCurNbEntries], entries, nb*sizeof(float));
00098                                                                         mCurNbEntries+=nb;
00099                                                                         return *this;
00100                                                                 }
00101 
00103                 inline_ Container&              AddUnique(udword entry)
00104                                                                 {
00105                                                                         if(!Contains(entry))    Add(entry);
00106                                                                         return *this;
00107                                                                 }
00108 
00110 
00115 
00116                                 Container&              Empty();
00117 
00119 
00124 
00125                 inline_ void                    Reset()
00126                                                                 {
00127                                                                         // Avoid the write if possible
00128                                                                         // ### CMOV
00129                                                                         if(mCurNbEntries)       mCurNbEntries = 0;
00130                                                                 }
00131 
00132                 // HANDLE WITH CARE
00133                 inline_ void                    ForceSize(udword size)
00134                                                                 {
00135                                                                         mCurNbEntries = size;
00136                                                                 }
00137 
00139 
00144 
00145                                 bool                    SetSize(udword nb);
00146 
00148 
00152 
00153                                 bool                    Refit();
00154 
00155                 // Checks whether the container already contains a given value.
00156                                 bool                    Contains(udword entry, udword* location=null) const;
00157                 // Deletes an entry - doesn't preserve insertion order.
00158                                 bool                    Delete(udword entry);
00159                 // Deletes an entry - does preserve insertion order.
00160                                 bool                    DeleteKeepingOrder(udword entry);
00162                 inline_ void                    DeleteLastEntry()                                               { if(mCurNbEntries)     mCurNbEntries--;                        }
00164                 inline_ void                    DeleteIndex(udword index)                               { mEntries[index] = mEntries[--mCurNbEntries];  }
00165 
00166                 // Helpers
00167                                 Container&              FindNext(udword& entry, FindMode find_mode=FIND_CLAMP);
00168                                 Container&              FindPrev(udword& entry, FindMode find_mode=FIND_CLAMP);
00169                 // Data access.
00170                 inline_ udword                  GetNbEntries()                                  const   { return mCurNbEntries;                                 }       
00171                 inline_ udword                  GetEntry(udword i)                              const   { return mEntries[i];                                   }       
00172                 inline_ udword*                 GetEntries()                                    const   { return mEntries;                                              }       
00173 
00174                 inline_ udword                  GetFirst()                                              const   { return mEntries[0];                                   }
00175                 inline_ udword                  GetLast()                                               const   { return mEntries[mCurNbEntries-1];             }
00176 
00177                 // Growth control
00178                 inline_ float                   GetGrowthFactor()                               const   { return mGrowthFactor;                                 }       
00179                 inline_ void                    SetGrowthFactor(float growth)                   { mGrowthFactor = growth;                               }       
00180                 inline_ bool                    IsFull()                                                const   { return mCurNbEntries==mMaxNbEntries;  }       
00181                 inline_ BOOL                    IsNotEmpty()                                    const   { return mCurNbEntries;                                 }       
00182 
00184                 inline_ udword                  operator[](udword i)                    const   { ASSERT(i>=0 && i<mCurNbEntries); return mEntries[i];  }
00186                 inline_ udword&                 operator[](udword i)                                    { ASSERT(i>=0 && i<mCurNbEntries); return mEntries[i];  }
00187 
00188                 // Stats
00189                                 udword                  GetUsedRam()                                    const;
00190 
00192                                 //void                  operator = (const Container& object);
00193 
00194 #ifdef CONTAINER_STATS
00195                 inline_ udword                  GetNbContainers()                               const   { return mNbContainers;         }
00196                 inline_ udword                  GetTotalBytes()                                 const   { return mUsedRam;                      }
00197                 private:
00198 
00199                 static  udword                  mNbContainers;          
00200                 static  udword                  mUsedRam;                       
00201 #endif
00202                 private:
00203                 // Resizing
00204                                 bool                    Resize(udword needed=1);
00205                 // Data
00206                                 udword                  mMaxNbEntries;          
00207                                 udword                  mCurNbEntries;          
00208                                 udword*                 mEntries;                       
00209                                 float                   mGrowthFactor;          
00210         };
00211 
00212 #endif // __ICECONTAINER_H__


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16