IceContainer.h
Go to the documentation of this file.
1 
8 
11 // Include Guard
12 #ifndef __ICECONTAINER_H__
13 #define __ICECONTAINER_H__
14 
15  #define CONTAINER_STATS
16 
17  enum FindMode
18  {
21 
22  FIND_FORCE_DWORD = 0x7fffffff
23  };
24 
26  {
27  public:
28  // Constructor / Destructor
29  Container();
30  Container(const Container& object);
31  Container(udword size, float growth_factor);
32  ~Container();
33  // Management
35 
46  inline_ Container& Add(udword entry)
48  {
49  // Resize if needed
50  if(mCurNbEntries==mMaxNbEntries) Resize();
51 
52  // Add new entry
53  mEntries[mCurNbEntries++] = entry;
54  return *this;
55  }
56 
58  {
59  // Resize if needed
60  if(mCurNbEntries+nb>mMaxNbEntries) Resize(nb);
61 
62  // Add new entry
63  CopyMemory(&mEntries[mCurNbEntries], entries, nb*sizeof(udword));
64  mCurNbEntries+=nb;
65  return *this;
66  }
67 
69 
80  inline_ Container& Add(float entry)
82  {
83  // Resize if needed
84  if(mCurNbEntries==mMaxNbEntries) Resize();
85 
86  // Add new entry
87  mEntries[mCurNbEntries++] = IR(entry);
88  return *this;
89  }
90 
91  inline_ Container& Add(const float* entries, udword nb)
92  {
93  // Resize if needed
94  if(mCurNbEntries+nb>mMaxNbEntries) Resize(nb);
95 
96  // Add new entry
97  CopyMemory(&mEntries[mCurNbEntries], entries, nb*sizeof(float));
98  mCurNbEntries+=nb;
99  return *this;
100  }
101 
104  {
105  if(!Contains(entry)) Add(entry);
106  return *this;
107  }
108 
110 
115  Container& Empty();
117 
119 
124  inline_ void Reset()
126  {
127  // Avoid the write if possible
128  // ### CMOV
129  if(mCurNbEntries) mCurNbEntries = 0;
130  }
131 
132  // HANDLE WITH CARE
134  {
135  mCurNbEntries = size;
136  }
137 
139 
144  bool SetSize(udword nb);
146 
148 
152  bool Refit();
154 
155  // Checks whether the container already contains a given value.
156  bool Contains(udword entry, udword* location=null) const;
157  // Deletes an entry - doesn't preserve insertion order.
158  bool Delete(udword entry);
159  // Deletes an entry - does preserve insertion order.
160  bool DeleteKeepingOrder(udword entry);
162  inline_ void DeleteLastEntry() { if(mCurNbEntries) mCurNbEntries--; }
164  inline_ void DeleteIndex(udword index) { mEntries[index] = mEntries[--mCurNbEntries]; }
165 
166  // Helpers
167  Container& FindNext(udword& entry, FindMode find_mode=FIND_CLAMP);
168  Container& FindPrev(udword& entry, FindMode find_mode=FIND_CLAMP);
169  // Data access.
170  inline_ udword GetNbEntries() const { return mCurNbEntries; }
171  inline_ udword GetEntry(udword i) const { return mEntries[i]; }
172  inline_ udword* GetEntries() const { return mEntries; }
173 
174  inline_ udword GetFirst() const { return mEntries[0]; }
175  inline_ udword GetLast() const { return mEntries[mCurNbEntries-1]; }
176 
177  // Growth control
178  inline_ float GetGrowthFactor() const { return mGrowthFactor; }
179  inline_ void SetGrowthFactor(float growth) { mGrowthFactor = growth; }
180  inline_ bool IsFull() const { return mCurNbEntries==mMaxNbEntries; }
181  inline_ BOOL IsNotEmpty() const { return mCurNbEntries; }
182 
184  inline_ udword operator[](udword i) const { ASSERT(i>=0 && i<mCurNbEntries); return mEntries[i]; }
186  inline_ udword& operator[](udword i) { ASSERT(i>=0 && i<mCurNbEntries); return mEntries[i]; }
187 
188  // Stats
189  udword GetUsedRam() const;
190 
192  //void operator = (const Container& object);
193 
194 #ifdef CONTAINER_STATS
195  inline_ udword GetNbContainers() const { return mNbContainers; }
196  inline_ udword GetTotalBytes() const { return mUsedRam; }
197  private:
198 
200  static udword mUsedRam;
201 #endif
202  private:
203  // Resizing
204  bool Resize(udword needed=1);
205  // Data
210  };
211 
212 #endif // __ICECONTAINER_H__
#define IR(x)
Integer representation of a floating-point value.
Definition: IceFPU.h:18
static udword mNbContainers
Number of containers around.
Definition: IceContainer.h:199
inline_ Container & AddUnique(udword entry)
Add unique [slow].
Definition: IceContainer.h:103
inline_ void SetGrowthFactor(float growth)
Sets the growth factor.
Definition: IceContainer.h:179
#define null
our own NULL pointer
Definition: IceTypes.h:57
static udword mUsedRam
Amount of bytes used by containers in the system.
Definition: IceContainer.h:200
png_uint_32 size
Definition: png.h:1521
inline_ void ForceSize(udword size)
Definition: IceContainer.h:133
#define inline_
inline_ bool IsFull() const
Checks the container is full.
Definition: IceContainer.h:180
inline_ BOOL IsNotEmpty() const
Checks the container is empty.
Definition: IceContainer.h:181
png_uint_32 i
Definition: png.h:2735
inline_ udword GetLast() const
Definition: IceContainer.h:175
inline_ void DeleteLastEntry()
Deletes the very last entry.
Definition: IceContainer.h:162
inline_ udword GetTotalBytes() const
Definition: IceContainer.h:196
#define ICECORE_API
udword * mEntries
List of entries.
Definition: IceContainer.h:208
int BOOL
Another boolean type.
Definition: IceTypes.h:102
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
inline_ udword operator[](udword i) const
Read-access as an array.
Definition: IceContainer.h:184
void Delete(RTObject_impl *rtc)
inline_ void DeleteIndex(udword index)
Deletes the entry whose index is given.
Definition: IceContainer.h:164
udword mCurNbEntries
Current number of entries.
Definition: IceContainer.h:207
png_infop int int location
Definition: png.h:2487
inline_ udword GetNbContainers() const
Operator for "Container A = Container B".
Definition: IceContainer.h:195
#define ASSERT(exp)
Definition: OPC_IceHook.h:24
FindMode
Definition: IceContainer.h:17
png_infop png_sPLT_tpp entries
Definition: png.h:2396
inline_ Container & Add(const udword *entries, udword nb)
Definition: IceContainer.h:57
float mGrowthFactor
Resize: new number of entries = old number * mGrowthFactor.
Definition: IceContainer.h:209
inline_ void CopyMemory(void *dest, const void *src, udword size)
inline_ Container & Add(const float *entries, udword nb)
Definition: IceContainer.h:91
inline_ udword GetNbEntries() const
Returns the current number of entries.
Definition: IceContainer.h:170
inline_ udword GetEntry(udword i) const
Returns ith entry.
Definition: IceContainer.h:171
inline_ udword * GetEntries() const
Returns the list of entries.
Definition: IceContainer.h:172
inline_ float GetGrowthFactor() const
Returns the growth factor.
Definition: IceContainer.h:178
udword mMaxNbEntries
Maximum possible number of entries.
Definition: IceContainer.h:206
inline_ udword GetFirst() const
Definition: IceContainer.h:174
inline_ udword & operator[](udword i)
Write-access as an array.
Definition: IceContainer.h:186


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:22