OSDN Git Service

#xxxxx DTXViewerのプロジェクトを追加。
[dtxmania/dtxmania.git] / DTXViewerプロジェクト / @FDK10プロジェクト / CArrayList.cpp
1 #include "stdafx.h"
2 #include "CArrayList.h"
3
4 namespace FDK {
5         namespace General {
6
7 CArrayList::CArrayList( CArrayList::ARRAYLISTTYPE Type, UINT n\97v\91f\83T\83C\83Y )
8 {
9     this->arrayListType                         = Type;
10     this->p\93®\93I\94z\97ñ                                     = NULL;
11         this->n\97v\91f\83T\83C\83Y                               = (Type == ALT_REFERENCE) ? sizeof(LPVOID) : n\97v\91f\83T\83C\83Y;
12     this->n\8c»\8dÝ\82Ì\97v\91f\90\94                         = 0;
13         this->n\8c»\8dÝ\82Ì\93®\93I\94z\97ñ\82Ì\83T\83C\83Y   = 0;
14 }
15
16 CArrayList::~CArrayList()
17 {
18     if( ! this->p\93®\93I\94z\97ñ )
19         delete[] this->p\93®\93I\94z\97ñ;
20 }
21
22 HRESULT CArrayList::t\97v\91f\82ð\92Ç\89Á\82·\82é( void* pEntry )
23 {
24     if( this->n\97v\91f\83T\83C\83Y == 0 )
25         return E_FAIL;  // \8f\89\8aú\89»\82³\82ê\82Ä\82È\82¢
26
27         // \94z\97ñ\82ð\83I\81[\83o\81[\83t\83\8d\81[\82·\82é\82È\82ç\90V\82µ\82­\97Ì\88æ\82ð\8am\95Û\82·\82é\81B
28         if( ! this->p\93®\93I\94z\97ñ || this->n\8c»\8dÝ\82Ì\97v\91f\90\94 + 1 > this->n\8c»\8dÝ\82Ì\93®\93I\94z\97ñ\82Ì\83T\83C\83Y )
29         {
30                 HRESULT hr = this->t\90V\82µ\82¢\93®\93I\94z\97ñ\82ð\8am\95Û\82·\82é();
31                 if( FAILED(hr) )
32                         return hr;
33         }
34
35         // \93®\93I\94z\97ñ\82É\90V\97v\91f\82ð\92Ç\89Á\82·\82é\81B
36         switch( this->arrayListType )
37         {
38         case ALT_REFERENCE:
39         *(((void**)this->p\93®\93I\94z\97ñ) + this->n\8c»\8dÝ\82Ì\97v\91f\90\94) = pEntry;
40                 break;
41
42         case ALT_VALUE:
43         CopyMemory( (BYTE*)this->p\93®\93I\94z\97ñ + (this->n\8c»\8dÝ\82Ì\97v\91f\90\94 * this->n\97v\91f\83T\83C\83Y), pEntry, this->n\97v\91f\83T\83C\83Y );
44                 break;
45         }
46     this->n\8c»\8dÝ\82Ì\97v\91f\90\94++;
47
48     return S_OK;
49 }
50
51 void CArrayList::t\97v\91f\82ð\8dí\8f\9c\82·\82é( UINT nIndex )
52 {
53         if( this->n\8c»\8dÝ\82Ì\97v\91f\90\94 <= 0 )
54                 return;
55
56     this->n\8c»\8dÝ\82Ì\97v\91f\90\94 --;
57
58         BYTE* pData = (BYTE*)this->p\93®\93I\94z\97ñ + (nIndex * this->n\97v\91f\83T\83C\83Y);
59     MoveMemory( pData, pData + this->n\97v\91f\83T\83C\83Y, ( this->n\8c»\8dÝ\82Ì\97v\91f\90\94 - nIndex) * this->n\97v\91f\83T\83C\83Y );
60 }
61
62 void* CArrayList::p\97v\91f\82ð\8eæ\93¾\82·\82é( UINT nIndex )
63 {
64         switch( this->arrayListType )
65         {
66                 case ALT_REFERENCE:
67                 return *(((void**)this->p\93®\93I\94z\97ñ) + nIndex);
68
69                 case ALT_VALUE:
70                 return (BYTE*)this->p\93®\93I\94z\97ñ + (nIndex * this->n\97v\91f\83T\83C\83Y);
71         }
72
73         return NULL;
74 }
75
76 bool CArrayList::b\97v\91f\82ª\94z\97ñ\93à\82É\91\8dÝ\82·\82é( void* pEntryData )
77 {
78     for( UINT i = 0; i < this->n\8c»\8dÝ\82Ì\97v\91f\90\94; i++ )
79     {
80                 switch( this->arrayListType )
81                 {
82                 case ALT_REFERENCE:
83                         if( this->p\97v\91f\82ð\8eæ\93¾\82·\82é(i) == pEntryData )
84                 return true;
85                         break;
86
87                 case ALT_VALUE:
88                         if( memcmp( this->p\97v\91f\82ð\8eæ\93¾\82·\82é(i), pEntryData, this->n\97v\91f\83T\83C\83Y ) == 0 )
89                 return true;
90                         break;
91                 }
92     }
93     return false;
94 }
95
96 HRESULT CArrayList::t\90V\82µ\82¢\93®\93I\94z\97ñ\82ð\8am\95Û\82·\82é()
97 {
98         // \90V\82µ\82¢\94z\97ñ\82Ì\83T\83C\83Y\82Í\82±\82ê\82Ü\82Å\82Ì\82Q\94{
99         UINT \90V\82µ\82¢\93®\93I\94z\97ñ\82Ì\83T\83C\83Y = ( this->n\8c»\8dÝ\82Ì\93®\93I\94z\97ñ\82Ì\83T\83C\83Y == 0 ) ? 16 : this->n\8c»\8dÝ\82Ì\93®\93I\94z\97ñ\82Ì\83T\83C\83Y * 2;
100
101         // \90V\94z\97ñ\82Ì\83\81\83\82\83\8a\82ð\8am\95Û
102         void* \90V\82µ\82¢\93®\93I\94z\97ñ = new BYTE[ \90V\82µ\82¢\93®\93I\94z\97ñ\82Ì\83T\83C\83Y * this->n\97v\91f\83T\83C\83Y ];
103         if( ! \90V\82µ\82¢\93®\93I\94z\97ñ )
104                 return E_OUTOFMEMORY;   // \8e¸\94s
105
106         // \8b\8c\94z\97ñ\82ª\82 \82é\82È\82ç\92\86\90g\82ð\83R\83s\81[\82·\82é
107         if( this->p\93®\93I\94z\97ñ  )
108         {
109                 CopyMemory( \90V\82µ\82¢\93®\93I\94z\97ñ, this->p\93®\93I\94z\97ñ, this->n\8c»\8dÝ\82Ì\97v\91f\90\94 * this->n\97v\91f\83T\83C\83Y );
110                 delete[] this->p\93®\93I\94z\97ñ;
111         }
112
113         // \88Ú\8ds\8a®\97¹
114         this->p\93®\93I\94z\97ñ               = \90V\82µ\82¢\93®\93I\94z\97ñ;
115         this->n\8c»\8dÝ\82Ì\93®\93I\94z\97ñ\82Ì\83T\83C\83Y = \90V\82µ\82¢\93®\93I\94z\97ñ\82Ì\83T\83C\83Y;
116
117         return S_OK;
118 }
119
120         }//General
121 }//FDK