Fix coding style according to tizen rule
[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                 delete[] m_ppData;
37 }
38
39 int CPointerArray::Add(LPVOID pData)
40 {
41         int nResult;
42         int nNewSize;
43         LPVOID *ppTemp;
44
45         if (m_ppData == NULL) {
46                 m_nMaxSize = BUFFER_INC_SIZE;
47                 m_ppData = new LPVOID[BUFFER_INC_SIZE];
48
49                 if (m_ppData == NULL) {
50                         nResult = -1;
51                         goto finish;
52                 }
53         }
54
55         if (m_nNumOfData >= m_nMaxSize) {
56                 nNewSize = m_nMaxSize += BUFFER_INC_SIZE;
57                 ppTemp = new LPVOID[nNewSize];
58                 IF_TRUE_GOTO(ppTemp == NULL, -1);
59
60                 memcpy(ppTemp, m_ppData, BUFFER_INC_SIZE * sizeof(LPVOID));
61
62                 delete[] m_ppData;
63
64                 m_nMaxSize += BUFFER_INC_SIZE;
65                 m_ppData = ppTemp;
66         }
67
68         m_ppData[m_nNumOfData] = pData;
69         m_nNumOfData++;
70
71         nResult = 0;
72
73 finish:
74
75         if (nResult != 0)
76                 DRM_TAPPS_EXCEPTION("CPointerArray::Add() Error! \n");
77
78         return nResult;
79 }
80
81 int CPointerArray::Remove(int nIndex)
82 {
83         int nResult;
84
85         if ((nIndex < 0) || (nIndex >= m_nNumOfData)) {
86                 nResult = -1; //ERRORMSG( ERROR_INVALID_PARAMETER, NULL );
87                 goto finish;
88         }
89
90         for (int i = nIndex; i < m_nNumOfData - 1; i++)
91                 m_ppData[i] = m_ppData[i + 1];
92
93         m_nNumOfData--;
94
95         nResult = 0;
96
97 finish:
98
99         if (nResult != 0)
100                 DRM_TAPPS_EXCEPTION("CPointerArray::Remove() Error! \n");
101
102         return nResult;
103 }
104
105 LPVOID CPointerArray::Get(int nIndex)
106 {
107         if ((nIndex < 0) || (nIndex >= m_nNumOfData))
108                 return NULL;
109
110         return m_ppData[nIndex];
111 }