WIL説明書(C++)  3.0.0
FvBufferAllocator.h
[詳解]
1 // $Revision: 1.2 $
2 /*
3  @file FvBufferAllocator.h
4  @brief CFvBufferAllocator template class
5  @author FAST Corporation
6 */
7 
8 #ifndef _FVBUFFERALLOCATOR_H_INCLUDED_
9 #define _FVBUFFERALLOCATOR_H_INCLUDED_
10 
11 #include "fie.h"
12 #include "oal_aloc.h"
13 #include "FvMacros.h"
14 #include "FvDefs.h"
15 #include "FvDebug.h"
16 #include "FvErrors.h"
17 #include "FvObject.h"
18 #include "fvalg.api.h"
19 #include "MultiData/FvAllocator.h"
20 
21 #pragma pack(push,_FVCL_PACKING)
22 
23 namespace FVCL
24 {
25 
26 // /////////////////////////////////////////////////////////////////
27 // DEFINE
28 
29 // /////////////////////////////////////////////////////////////////
30 // TYPEDEF
31 
32 // /////////////////////////////////////////////////////////////////
33 // CLASS
34 template<class TYPE> class CFvBufferAllocator : public CFvAllocator<TYPE>
35 {
36 public:
37  // DEFINE/TYPEDEF
38  typedef TYPE* pointer;
39  typedef const TYPE* const_pointer;
40  typedef TYPE& reference;
41  typedef const TYPE& const_reference;
42  typedef UINT size_type;
43 
44 public:
45  // ===================================================================
46  CFvBufferAllocator( size_type uiInitial, size_type uiIncrease ) : CFvAllocator<TYPE>( uiInitial, uiIncrease )
47  {
48  this->m_pTable = NULL;
49  this->m_uiCount = 0;
50  this->m_IsAttach = false;
53  }
54 
55  // ===================================================================
56  CFvBufferAllocator( size_type uiInitial, size_type uiIncrease, TYPE* adrs, size_type count ) : CFvAllocator<TYPE>( uiInitial, uiIncrease )
57  {
58  if( adrs == NULL && count != 0 )
60  this->m_pTable = adrs;
61  this->m_uiCount = count;
62  this->m_IsAttach = false;
63  }
64 
65  // ===================================================================
66  CFvBufferAllocator( size_type uiInitial, size_type uiIncrease, TYPE* adrs, size_type count, bool is_attach ) : CFvAllocator<TYPE>( uiInitial, uiIncrease )
67  {
68  if( adrs == NULL && count != 0 )
70  this->m_pTable = adrs;
71  this->m_uiCount = count;
72  this->m_IsAttach = is_attach;
73  }
74 
75  // ===================================================================
77  {
79  }
80 
81 public:
82  //
83  // METHOD
84  //
85 
86  // ===================================================================
87  virtual reference SetItem( size_type uiIndex, const_reference _Val )
88  {
89  if( this->m_uiCount <= uiIndex )
91  this->m_pTable[uiIndex] = _Val;
92  return this->m_pTable[uiIndex];
93  }
94 
95  // ===================================================================
96  virtual reference GetItem( size_type uiIndex ) const
97  {
98  if( this->m_uiCount <= uiIndex )
100  return this->m_pTable[uiIndex];
101  }
102 
103  // ===================================================================
104  virtual bool SetBuffer( pointer adrs, size_type count )
105  {
106  return SetBuffer(adrs, count, false);
107  }
108 
109  // ===================================================================
110  virtual bool SetBuffer( pointer adrs, size_type count, bool is_attach )
111  {
112  if( adrs == NULL && count != 0 ) return false;
114  this->m_pTable = adrs;
115  this->m_uiCount = count;
116  this->m_IsAttach = is_attach;
117  return true;
118  }
119 
120  // ===================================================================
121  virtual pointer GetBuffer( size_type uiIndex = 0 ) const
122  {
123  if (this->m_pTable == NULL) return NULL;
124  if( this->m_uiCount <= uiIndex )
126  return &this->m_pTable[uiIndex];
127  }
128 
129  // ===================================================================
130  virtual void IsAttach( bool value )
131  {
132  this->m_IsAttach = value;
133  }
134 
135  // ===================================================================
136  virtual bool IsAttach() const
137  {
138  return this->m_IsAttach;
139  }
140 
141  // ===================================================================
142  virtual bool Allocate()
143  {
144  if( this->m_pTable != NULL )
145  {
147  }
148  if( this->m_uiInitial != 0 )
149  {
150  this->m_pTable = (TYPE*)fvalg::api::fnOAL_calloc( this->m_uiInitial, sizeof(TYPE) );
151  if( this->m_pTable == NULL )
152  return false;
153  }
154  this->m_uiCapacity = this->m_uiInitial;
155  return true;
156  }
157 
158  // ===================================================================
159  virtual void Clear()
160  {
161  if( this->m_pTable != NULL && !this->m_IsAttach )
162  {
163  fvalg::api::fnOAL_free( this->m_pTable );
164  }
165  this->m_pTable = NULL;
166  this->m_uiCount = 0;
167  this->m_uiCapacity = 0;
168  this->m_IsAttach = false;
169  }
170 
171  // ===================================================================
172  virtual void Reset()
173  {
174  if (this->m_pTable == NULL) return;
175 
176  for(UINT i=0 ; i<this->m_uiCount ; i++)
177  memset(&this->m_pTable[i], 0, sizeof(TYPE));
178  }
179 
180  // ===================================================================
181  virtual bool Reserve( size_type uiIncrease )
182  {
183  if( this->m_pTable == NULL )
184  {
185  if( !Allocate() ) return false;
186  }
187  TYPE *pNewTable;
188  pNewTable = (TYPE*)fvalg::api::fnOAL_calloc( (this->m_uiCapacity + uiIncrease), sizeof(TYPE) );
189  if( pNewTable == NULL ) return false;
190 
191  size_type iCnt;
192  for( iCnt=0 ; iCnt<this->m_uiCount ; iCnt++ )
193  pNewTable[iCnt] = this->m_pTable[iCnt];
194 
195  this->m_uiCapacity += uiIncrease;
196 
197  if (!this->m_IsAttach)
198  fvalg::api::fnOAL_free( this->m_pTable );
199  this->m_pTable = pNewTable;
200  this->m_IsAttach = false;
201  return true;
202  }
203 
204  // ===================================================================
205  virtual bool Erase( size_type uiS, size_type uiE )
206  {
207  if( this->m_pTable == NULL ) return false;
208  if( this->m_uiCount<=uiS ) return false;
209  if( this->m_uiCount<=uiE ) uiE = this->m_uiCount-1;
210  if( uiE < uiS ) return false;
211 
212  size_type iCnt, jCnt;
213  for( iCnt=uiS, jCnt=1 ; iCnt<this->m_uiCount ; iCnt++, jCnt++ )
214  {
215  size_type uiP = uiE+jCnt;
216  if( uiP < this->m_uiCount )
217  this->m_pTable[iCnt] = this->m_pTable[uiP];
218  }
219  this->m_uiCount -= (uiE-uiS+1);
220  return true;
221  }
222 
223  // ===================================================================
224  virtual bool Insert( size_type uiPos, size_type uiSize, const_reference _Val )
225  {
226  if( this->m_pTable == NULL ) return false;
227  if( this->m_uiCount <= uiPos ) return false;
228  if( uiSize == 0 ) uiSize = 1;
229  if( this->m_uiCapacity < this->m_uiCount+uiSize )
230  CFvBufferAllocator<TYPE>::Reserve( max(this->m_uiCount + uiSize - this->m_uiCapacity,this->m_uiIncrease) );
231 
232  size_type uiLen = this->m_uiCount - uiPos;
233  size_type iCnt;
234  for( iCnt=1 ; iCnt<=uiLen ; iCnt++ )
235  this->m_pTable[this->m_uiCount+uiSize-iCnt] = this->m_pTable[this->m_uiCount-iCnt];
236  for( iCnt=uiPos ; iCnt<uiPos+uiSize ; iCnt++ )
237  this->m_pTable[iCnt] = _Val;
238  this->m_uiCount += uiSize;
239  return true;
240  }
241 
242  // ===================================================================
243  virtual bool PopBack()
244  {
245  if( this->m_pTable == NULL ) return false;
246  if( this->m_uiCount == 0 ) return false;
247  this->m_uiCount--;
248  return true;
249  }
250 
251  // ===================================================================
252  virtual bool PushBack( const_reference _Val )
253  {
254  if( this->m_pTable == NULL )
255  {
256  if( !Allocate() ) return false;
257  }
258  if( this->m_uiCapacity <= this->m_uiCount )
260  return false;
261  this->m_pTable[this->m_uiCount] = _Val;
262  this->m_uiCount++;
263  return true;
264  }
265 
266  // ===================================================================
267  virtual bool Resize( size_type uiSize, const_pointer pVal=NULL )
268  {
269  if( this->m_pTable == NULL )
270  {
271  if( !Allocate() ) return false;
272  }
273  if( uiSize == 0 )
274  {
276  }
277  else if( uiSize < this->m_uiCount )
278  {
279  this->m_uiCount = uiSize;
280  }
281  else if( this->m_uiCount < uiSize )
282  {
283  if( this->m_uiCapacity < uiSize )
284  if( !CFvBufferAllocator<TYPE>::Reserve( max(uiSize - this->m_uiCapacity,this->m_uiIncrease) ) )
285  return false;
286  if( pVal )
287  for( size_type iCnt=this->m_uiCount ; iCnt<uiSize ; iCnt++ )
288  this->m_pTable[iCnt] = static_cast<const_reference>(*pVal);
289  this->m_uiCount = uiSize;
290  }
291  return true;
292  }
293 
294  // ===================================================================
295  virtual bool ChangeOrder( size_type uiPos, INT order )
296  {
297  if( !(0 <= uiPos && uiPos < this->m_uiCount) )
298  return false;
299 
300  INT iPos1 = (INT)uiPos;
301  INT iPos2 = iPos1 + order;
302  if( iPos2 < 0 )
303  iPos2 = 0;
304  if( iPos2 >= (INT)this->m_uiCount )
305  iPos2 = (INT)this->m_uiCount - 1;
306 
307  INT inc = (iPos1<iPos2) ? 1 : -1;
308  TYPE temp = this->m_pTable[iPos1];
309  for( INT i=iPos1 ; i!=iPos2 ; i+=inc )
310  this->m_pTable[i] = this->m_pTable[i+inc];
311  this->m_pTable[iPos2] = temp;
312 
313  return true;
314  }
315 
316  // ===================================================================
317  virtual bool SwapItem( size_type uiPos1, size_type uiPos2 )
318  {
319  if( ! (uiPos1 < this->m_uiCount) ) return false;
320  if( ! (uiPos2 < this->m_uiCount) ) return false;
321 
322  TYPE temp = this->m_pTable[uiPos1];
323  this->m_pTable[uiPos1] = this->m_pTable[uiPos2];
324  this->m_pTable[uiPos2] = temp;
325 
326  return true;
327  }
328 
329 protected:
330  // OBJECT
331  pointer m_pTable;
333 };
334 
335 } // FVCL
336 
337 #pragma pack(pop)
338 
339 #endif // _FVBUFFERALLOCATOR_H_INCLUDED_
virtual bool IsAttach() const
アタッチ属性の取得
Definition: FvBufferAllocator.h:136
virtual bool SetBuffer(pointer adrs, size_type count, bool is_attach)
配列の設定
Definition: FvBufferAllocator.h:110
size_type m_uiInitial
配列の初期容量
Definition: FvAllocator.h:112
TYPE * pointer
ポインタ型
Definition: FvAllocator.h:38
size_type m_uiIncrease
配列の増分
Definition: FvAllocator.h:113
virtual pointer GetBuffer(size_type uiIndex=0) const
配列の要素へのアドレス取得
Definition: FvBufferAllocator.h:121
配列確保テンプレートクラスの基本クラス
Definition: FvAllocator.h:34
virtual reference GetItem(size_type uiIndex) const
配列の要素の取得
Definition: FvBufferAllocator.h:96
FVCLのネームスペース
Definition: EVCbasicDeclare.txt:9
領域確保不可例外クラス
Definition: FveBadAllocException.h:18
virtual bool PopBack()
配列末端からの要素の取り出し
Definition: FvBufferAllocator.h:243
const INT FAILED_TO_ALLOCATE
メモリの確保に失敗しました。
Definition: FvErrors.h:15
const INT INVALID_PARAMETER
パラメータが無効です。
Definition: FvErrors.h:24
int INT
整数型(32ビット)
Definition: FvDefs.h:36
virtual bool PushBack(const_reference _Val)
配列への要素の追加
Definition: FvBufferAllocator.h:252
virtual bool SetBuffer(pointer adrs, size_type count)
配列の設定
Definition: FvBufferAllocator.h:104
virtual bool Erase(size_type uiS, size_type uiE)
配列要素の削除
Definition: FvBufferAllocator.h:205
マクロ定義
FVALG ラッパー
パラメータ不正例外クラス
Definition: FveBadParamException.h:18
virtual bool Reserve(size_type uiIncrease)
配列容量の追加
Definition: FvBufferAllocator.h:181
UINT size_type
サイズ型
Definition: FvAllocator.h:42
size_type m_uiCapacity
配列の許容量
Definition: FvAllocator.h:111
virtual ~CFvBufferAllocator()
デストラクタ
Definition: FvBufferAllocator.h:76
virtual void Clear()
配列の開放
Definition: FvBufferAllocator.h:159
const TYPE * const_pointer
ポインタ型(const付き)
Definition: FvAllocator.h:39
size_type m_uiCount
配列内の要素数
Definition: FvAllocator.h:110
const TYPE & const_reference
参照型(const付き)
Definition: FvAllocator.h:41
CFvBufferAllocator(size_type uiInitial, size_type uiIncrease)
コンストラクタ
Definition: FvBufferAllocator.h:46
アクセス違反例外クラス
Definition: FveBadAccessException.h:18
TYPE & reference
参照型
Definition: FvAllocator.h:40
エラーコード定義
CFvBufferAllocator(size_type uiInitial, size_type uiIncrease, TYPE *adrs, size_type count)
コンストラクタ
Definition: FvBufferAllocator.h:56
virtual void Reset()
配列のリセット
Definition: FvBufferAllocator.h:172
CFvBufferAllocator(size_type uiInitial, size_type uiIncrease, TYPE *adrs, size_type count, bool is_attach)
コンストラクタ
Definition: FvBufferAllocator.h:66
virtual bool SwapItem(size_type uiPos1, size_type uiPos2)
配列要素の位置入れ替え
Definition: FvBufferAllocator.h:317
virtual bool Allocate()
配列の確保
Definition: FvBufferAllocator.h:142
unsigned int UINT
整数型(32ビット)[符号なし]
Definition: FvDefs.h:37
bool m_IsAttach
アタッチ属性
Definition: FvBufferAllocator.h:332
CFvObject クラスのインターフェース
virtual bool Insert(size_type uiPos, size_type uiSize, const_reference _Val)
配列への要素の挿入
Definition: FvBufferAllocator.h:224
virtual void IsAttach(bool value)
アタッチ属性の設定
Definition: FvBufferAllocator.h:130
pointer m_pTable
配列
Definition: FvBufferAllocator.h:331
配列確保テンプレートクラスの基本クラス
変数型と定数の定義
デバッグ用関数のインターフェース
virtual bool Resize(size_type uiSize, const_pointer pVal=NULL)
配列の再確保
Definition: FvBufferAllocator.h:267
virtual bool ChangeOrder(size_type uiPos, INT order)
配列要素の順序入れ替え
Definition: FvBufferAllocator.h:295
virtual reference SetItem(size_type uiIndex, const_reference _Val)
配列への要素の設定
Definition: FvBufferAllocator.h:87
配列確保テンプレートクラス(ポインタ型)
Definition: FvBufferAllocator.h:34

Documentation copyright © 2007 FAST Corporation. [B-001864]
Generated on 2023年11月02日(木) 10時12分53秒 for WIL説明書(C++) by doxygen 1.8.11