681f2250feb2753f895f666c54d8c00b52d6c021
[platform/core/security/drm-service-core-tizen.git] / tadcore / XMLParser / CPointerArray.cpp
1 /*
2  * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "CPointerArray.h"
18 #include "TADC_IF.h"
19 #include "TADC_ErrorCode.h"
20
21 //////////////////////////////////////////////////////////////////////
22 // Construction/Destruction
23 //////////////////////////////////////////////////////////////////////
24 #define                 BUFFER_INC_SIZE                         128
25
26 CPointerArray::CPointerArray()
27 {
28         m_ppData = NULL;
29         m_nMaxSize = 0;
30         m_nNumOfData = 0;
31 }
32
33 CPointerArray::~CPointerArray()
34 {
35         if( m_ppData != NULL )
36         {
37                 delete[] m_ppData;
38         }
39 }
40
41 int CPointerArray::Add( LPVOID pData )
42 {
43         int                                     nResult;
44         int                                     nNewSize;
45         LPVOID*                         ppTemp;
46
47         if( m_ppData == NULL )
48         {
49                 m_nMaxSize = BUFFER_INC_SIZE;
50                 m_ppData = new LPVOID[ BUFFER_INC_SIZE ];
51
52                 if(m_ppData == NULL)
53                 {
54                         nResult = -1;
55
56                         goto finish;
57                 }
58         }
59
60         if( m_nNumOfData >= m_nMaxSize )
61         {
62                 nNewSize = m_nMaxSize += BUFFER_INC_SIZE;
63                 ppTemp = new LPVOID[ nNewSize ];
64                 IF_TRUE_GOTO( ppTemp == NULL, -1 );
65                 
66                 memcpy( ppTemp, m_ppData, BUFFER_INC_SIZE * sizeof( LPVOID ) );
67
68                 delete[] m_ppData;
69
70                 m_nMaxSize += BUFFER_INC_SIZE;
71                 m_ppData = ppTemp;
72         }
73
74         m_ppData[ m_nNumOfData ] = pData;
75         m_nNumOfData++;
76
77         nResult = 0;
78
79 finish:
80
81         if( nResult != 0 )
82         {
83                 DRM_TAPPS_EXCEPTION("CPointerArray::Add() Error! \n");
84         }
85
86         return nResult;
87 }
88
89 int CPointerArray::Remove( int nIndex )
90 {
91         int             nResult;
92         int             i;
93
94         if( ( nIndex < 0 ) || ( nIndex >= m_nNumOfData ) )
95         {
96                 nResult = -1;//ERRORMSG( ERROR_INVALID_PARAMETER, NULL );
97
98                 goto finish;
99         }
100
101         for( i = nIndex ; i < m_nNumOfData - 1 ; i++ )
102         {
103                 m_ppData[ i ] = m_ppData[ i + 1 ];
104         }
105         
106         m_nNumOfData--;
107
108         nResult = 0;
109
110 finish:
111
112         if( nResult != 0 )
113         {
114                 DRM_TAPPS_EXCEPTION("CPointerArray::Remove() Error! \n");
115         }
116
117         return nResult;
118 }
119
120 LPVOID CPointerArray::Get( int nIndex )
121 {
122         if( ( nIndex < 0 ) || ( nIndex >= m_nNumOfData ) )
123         {
124                 return NULL;
125         }
126
127         return m_ppData[ nIndex ];
128 }