Merge "Update doxygen" into tizen_2.1
[platform/framework/native/appfw.git] / src / io / FIo_DataSetImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19 * @file         FIo_DataSetImpl.cpp
20 * @brief                This is the implementation file for the _DataSetImpl class.
21 */
22
23 #include <new>
24 #include <unique_ptr.h>
25
26 #include <FBaseObject.h>
27 #include <FBaseInteger.h>
28 #include <FBaseSysLog.h>
29 #include <FIo_DataSetImpl.h>
30 #include <FIo_DataRowImpl.h>
31 #include <FIo_DataSetEnumeratorImpl.h>
32
33 using namespace std;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36
37 namespace Tizen { namespace Io
38 {
39 _DataSetImpl::_DataSetImpl(void)
40         :__rowCount(0)
41 {
42
43 }
44
45 _DataSetImpl::~_DataSetImpl(void)
46 {
47
48 }
49
50 result
51 _DataSetImpl::Construct(const IList& columnNames)
52 {
53         result r = E_SUCCESS;
54
55         __columnCount = columnNames.GetCount();
56         SysTryReturn(NID_IO, __columnCount > 0, E_INVALID_ARG, r, "[E_INVALID_ARG] column count is 0.");
57
58         r = __columnList.Construct(__columnCount);
59         SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column list construct failed");
60         r = __columnTypeList.Construct(__columnCount);
61         SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column type list construct failed");
62
63         for (int i = 0 ; i < __columnCount ; i++)
64         {
65                 r = __columnList.Add(new (std::nothrow) String(*(String*)(columnNames.GetAt(i))));
66                 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
67
68                 r = __columnTypeList.Add(new (std::nothrow) Integer(DB_COLUMNTYPE_NULL));
69                 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
70         }
71         //SysLog(NID_IO, "column count is %d", __columnCount);
72
73         return r;
74 }
75
76 DataRow*
77 _DataSetImpl::CreateDataRowN(void)
78 {
79         result r;
80         unique_ptr<ArrayList> pNewRowArrayList(new (std::nothrow) ArrayList);
81         SysTryReturn(NID_IO, pNewRowArrayList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
82
83         unique_ptr<DataRow> pDataRow(_DataRowImpl::CreateDataRowInstanceN(__columnCount, pNewRowArrayList.get()));
84         SysTryReturn(NID_IO, pDataRow != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
85
86         r = __dataSet.Add(pNewRowArrayList.release());
87         SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add Row to DataSet is failed");
88
89         _DataRowImpl::GetInstance(*pDataRow)->__pColumnTypeList = &__columnTypeList;
90
91         __rowCount = __dataSet.GetCount();
92         //SysLog(NID_IO, "row count is %d", __rowCount);
93
94         return pDataRow.release();
95
96 }
97
98 DataSetEnumerator*
99 _DataSetImpl::GetDataSetEnumeratorN(void)
100 {
101         unique_ptr<DataSetEnumerator> pDataSetEnum(_DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN());
102
103         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pDataSet = &__dataSet;
104         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pColumnList = &__columnList;
105         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__columnCount = __columnCount;
106         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__rowCount = __rowCount;
107
108         //SysLog(NID_IO, "row count is %d, column count is %d", __rowCount, __columnCount);
109
110         return pDataSetEnum.release();
111 }
112
113 DataSet*
114 _DataSetImpl::CloneN(void) const
115 {
116         result r;
117         Integer* pColumnType = null;
118
119         unique_ptr< DataSet > pDataSet(new (std::nothrow) DataSet());
120         SysTryReturn(NID_IO, pDataSet != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
121
122         pDataSet->Construct(__columnList);
123
124         for (int i = 0; i < __columnCount; i++)
125         {
126                 pColumnType = static_cast<Integer*>(_DataSetImpl::GetInstance(*pDataSet)->__columnTypeList.GetAt(i));
127                 r = _DataSetImpl::GetInstance(*pDataSet)->__columnTypeList.SetAt(new Integer(*(Integer*)__columnTypeList.GetAt(i)), i);
128                 delete pColumnType;
129
130                 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] ColumnTypeList Copy Falied");
131         }
132
133         for (int i = 0; i < __rowCount; i++)
134         {
135                 DataRow* pNewRow = pDataSet->CreateDataRowN();
136                 r = _DataRowImpl::GetInstance(*pNewRow)->Clone((const ArrayList*)(__dataSet.GetAt(i)));
137                 delete pNewRow;
138
139                 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] DataRow Clone Falied");
140         }
141
142         return pDataSet.release();
143 }
144
145 bool
146 _DataSetImpl::Equals(const Tizen::Base::Object& obj) const
147 {
148         int thisHash = this->GetHashCode();
149         int othersHash = obj.GetHashCode();
150
151         if (thisHash == othersHash )
152                 return true;
153         else
154                 return false;
155 }
156
157 int
158 _DataSetImpl::GetHashCode(void) const
159 {
160         int hash = 0;
161
162         for (int i = 0; i < __rowCount; i++)
163         {
164                 const ArrayList* pDataRowArrayList = static_cast<const ArrayList*>(__dataSet.GetAt(i));
165                 hash += _DataRowImpl::GetHashCode(pDataRowArrayList);
166         }
167
168         return hash;
169 }
170
171 _DataSetImpl*
172 _DataSetImpl::GetInstance(DataSet& dataSet)
173 {
174         return dataSet.__pDataSetImpl;
175 }
176
177 const _DataSetImpl*
178 _DataSetImpl::GetInstance(const DataSet& dataSet)
179 {
180         return dataSet.__pDataSetImpl;
181 }
182
183 }} // Tizen::Io
184
185