Remove compilation warning
[platform/framework/native/appfw.git] / src / io / FIo_DataSetImpl.cpp
1 //
2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 /**
18 * @file         FIo_DataSetImpl.cpp
19 * @brief                This is the implementation file for the _DataSetImpl class.
20 */
21
22 #include <new>
23 #include <unique_ptr.h>
24
25 #include <FBaseObject.h>
26 #include <FBaseInteger.h>
27 #include <FBaseSysLog.h>
28 #include <FIo_DataSetImpl.h>
29 #include <FIo_DataRowImpl.h>
30 #include <FIo_DataSetEnumeratorImpl.h>
31
32 using namespace std;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35
36 namespace Tizen { namespace Io
37 {
38 _DataSetImpl::_DataSetImpl(void)
39         : __columnCount(0)
40         , __rowCount(0)
41         , __pDataSet(null)
42         , __pColumnList(null)
43         , __pColumnTypeList(null)
44 {
45 }
46
47 _DataSetImpl::~_DataSetImpl(void)
48 {
49         for (int i = 0; i< __enumImplList.GetCount() ; i++)
50                 (static_cast<_DataSetEnumeratorImpl*>(__enumImplList.GetAt(i)))->__dataSetDeleted = true;
51         for (int i = 0; i< __rowImplList.GetCount() ; i++)
52                 (static_cast<_DataRowImpl*>(__rowImplList.GetAt(i)))->__dataSetDeleted = true;
53
54         delete __pDataSet;
55         delete __pColumnList;
56         delete __pColumnTypeList;
57 }
58
59 result
60 _DataSetImpl::Construct(const IList& columnNames)
61 {
62         result r = E_SUCCESS;
63
64         __pDataSet = new (std::nothrow) LinkedList(SingleObjectDeleter);
65         SysTryReturnResult(NID_IO, __pDataSet != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
66         __pColumnList = new (std::nothrow) ArrayList(SingleObjectDeleter);
67         SysTryReturnResult(NID_IO, __pColumnList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
68         __pColumnTypeList = new (std::nothrow) ArrayList(SingleObjectDeleter);
69         SysTryReturnResult(NID_IO, __pColumnTypeList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
70
71         __columnCount = columnNames.GetCount();
72         SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_ARG, "column count is 0.");
73
74         r = __pColumnList->Construct(__columnCount);
75         SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column list construct failed");
76         r = __pColumnTypeList->Construct(__columnCount);
77         SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column type list construct failed");
78
79         for (int i = 0 ; i < __columnCount ; i++)
80         {
81                 r = __pColumnList->Add(new (std::nothrow) String(*(String*)(columnNames.GetAt(i))));
82                 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
83
84                 r = __pColumnTypeList->Add(new (std::nothrow) Integer(DB_COLUMNTYPE_NULL));
85                 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
86         }
87         //SysLog(NID_IO, "column count is %d", __columnCount);
88
89         return r;
90 }
91
92 DataRow*
93 _DataSetImpl::CreateDataRowN(void)
94 {
95         result r;
96         unique_ptr<ArrayList> pNewRowArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
97         SysTryReturn(NID_IO, pNewRowArrayList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
98
99         unique_ptr<DataRow> pDataRow(_DataRowImpl::CreateDataRowInstanceN(__columnCount, pNewRowArrayList.get()));
100         SysTryReturn(NID_IO, pDataRow != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
101
102         r = __pDataSet->Add(pNewRowArrayList.release());
103         SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add Row to DataSet is failed");
104
105         _DataRowImpl::GetInstance(*pDataRow)->__pColumnTypeList = __pColumnTypeList;
106
107         r = __rowImplList.Add(_DataRowImpl::GetInstance(*pDataRow));
108         SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add to LinkedList Falied");
109
110         _DataRowImpl::GetInstance(*pDataRow)->__pRowImplList = &__rowImplList;
111
112         __rowCount = __pDataSet->GetCount();
113         //SysLog(NID_IO, "row count is %d", __rowCount);
114
115         return pDataRow.release();
116
117 }
118
119 DataSetEnumerator*
120 _DataSetImpl::GetDataSetEnumeratorN(void)
121 {
122         result r;
123
124         unique_ptr<DataSetEnumerator> pDataSetEnum(_DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN());
125
126         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pDataSet = __pDataSet;
127         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pColumnList = __pColumnList;
128         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__columnCount = __columnCount;
129         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__rowCount = __rowCount;
130
131         //SysLog(NID_IO, "row count is %d, column count is %d", __rowCount, __columnCount);
132
133         r = __enumImplList.Add(_DataSetEnumeratorImpl::GetInstance(*pDataSetEnum));
134         SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add to LinkedList Falied");
135
136         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pEnumImplList = &__enumImplList;
137
138         return pDataSetEnum.release();
139 }
140
141 DataSet*
142 _DataSetImpl::CloneN(void) const
143 {
144         result r;
145
146         unique_ptr< DataSet > pDataSet(new (std::nothrow) DataSet());
147         SysTryReturn(NID_IO, pDataSet != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
148
149         pDataSet->Construct(*__pColumnList);
150
151         for (int i = 0; i < __columnCount; i++)
152         {
153                 r = _DataSetImpl::GetInstance(*pDataSet)->__pColumnTypeList->SetAt(new Integer(*(Integer*)__pColumnTypeList->GetAt(i)), i);
154                 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] ColumnTypeList Copy Falied");
155         }
156
157         for (int i = 0; i < __rowCount; i++)
158         {
159                 DataRow* pNewRow = pDataSet->CreateDataRowN();
160                 r = _DataRowImpl::GetInstance(*pNewRow)->Clone((const ArrayList*)(__pDataSet->GetAt(i)));
161                 delete pNewRow;
162
163                 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] DataRow Clone Falied");
164         }
165
166         return pDataSet.release();
167 }
168
169 bool
170 _DataSetImpl::Equals(const Tizen::Base::Object& obj) const
171 {
172         int thisHash = this->GetHashCode();
173         int othersHash = obj.GetHashCode();
174
175         if (thisHash == othersHash )
176                 return true;
177         else
178                 return false;
179 }
180
181 int
182 _DataSetImpl::GetHashCode(void) const
183 {
184         int hash = 0;
185
186         for (int i = 0; i < __rowCount; i++)
187         {
188                 const ArrayList* pDataRowArrayList = static_cast<const ArrayList*>(__pDataSet->GetAt(i));
189                 hash += _DataRowImpl::GetHashCode(pDataRowArrayList);
190         }
191
192         return hash;
193 }
194
195 _DataSetImpl*
196 _DataSetImpl::GetInstance(DataSet& dataSet)
197 {
198         return dataSet.__pDataSetImpl;
199 }
200
201 const _DataSetImpl*
202 _DataSetImpl::GetInstance(const DataSet& dataSet)
203 {
204         return dataSet.__pDataSetImpl;
205 }
206
207 }} // Tizen::Io
208
209