2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FIo_DataSetImpl.cpp
20 * @brief This is the implementation file for the _DataSetImpl class.
24 #include <unique_ptr.h>
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>
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
37 namespace Tizen { namespace Io
39 _DataSetImpl::_DataSetImpl(void)
43 __pColumnTypeList(null)
47 _DataSetImpl::~_DataSetImpl(void)
51 delete __pColumnTypeList;
55 _DataSetImpl::Construct(const IList& columnNames)
59 __pDataSet = new (std::nothrow) LinkedList(SingleObjectDeleter);
60 SysTryReturnResult(NID_IO, __pDataSet != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
61 __pColumnList = new (std::nothrow) ArrayList(SingleObjectDeleter);
62 SysTryReturnResult(NID_IO, __pColumnList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
63 __pColumnTypeList = new (std::nothrow) ArrayList(SingleObjectDeleter);
64 SysTryReturnResult(NID_IO, __pColumnTypeList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
66 __columnCount = columnNames.GetCount();
67 SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_ARG, "column count is 0.");
69 r = __pColumnList->Construct(__columnCount);
70 SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column list construct failed");
71 r = __pColumnTypeList->Construct(__columnCount);
72 SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column type list construct failed");
74 for (int i = 0 ; i < __columnCount ; i++)
76 r = __pColumnList->Add(new (std::nothrow) String(*(String*)(columnNames.GetAt(i))));
77 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
79 r = __pColumnTypeList->Add(new (std::nothrow) Integer(DB_COLUMNTYPE_NULL));
80 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
82 //SysLog(NID_IO, "column count is %d", __columnCount);
88 _DataSetImpl::CreateDataRowN(void)
91 unique_ptr<ArrayList> pNewRowArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
92 SysTryReturn(NID_IO, pNewRowArrayList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
94 unique_ptr<DataRow> pDataRow(_DataRowImpl::CreateDataRowInstanceN(__columnCount, pNewRowArrayList.get()));
95 SysTryReturn(NID_IO, pDataRow != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
97 r = __pDataSet->Add(pNewRowArrayList.release());
98 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add Row to DataSet is failed");
100 _DataRowImpl::GetInstance(*pDataRow)->__pColumnTypeList = __pColumnTypeList;
102 __rowCount = __pDataSet->GetCount();
103 //SysLog(NID_IO, "row count is %d", __rowCount);
105 return pDataRow.release();
110 _DataSetImpl::GetDataSetEnumeratorN(void)
112 unique_ptr<DataSetEnumerator> pDataSetEnum(_DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN());
114 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pDataSet = __pDataSet;
115 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pColumnList = __pColumnList;
116 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__columnCount = __columnCount;
117 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__rowCount = __rowCount;
119 //SysLog(NID_IO, "row count is %d, column count is %d", __rowCount, __columnCount);
121 return pDataSetEnum.release();
125 _DataSetImpl::CloneN(void) const
129 unique_ptr< DataSet > pDataSet(new (std::nothrow) DataSet());
130 SysTryReturn(NID_IO, pDataSet != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
132 pDataSet->Construct(*__pColumnList);
134 for (int i = 0; i < __columnCount; i++)
136 r = _DataSetImpl::GetInstance(*pDataSet)->__pColumnTypeList->SetAt(new Integer(*(Integer*)__pColumnTypeList->GetAt(i)), i);
137 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] ColumnTypeList Copy Falied");
140 for (int i = 0; i < __rowCount; i++)
142 DataRow* pNewRow = pDataSet->CreateDataRowN();
143 r = _DataRowImpl::GetInstance(*pNewRow)->Clone((const ArrayList*)(__pDataSet->GetAt(i)));
146 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] DataRow Clone Falied");
149 return pDataSet.release();
153 _DataSetImpl::Equals(const Tizen::Base::Object& obj) const
155 int thisHash = this->GetHashCode();
156 int othersHash = obj.GetHashCode();
158 if (thisHash == othersHash )
165 _DataSetImpl::GetHashCode(void) const
169 for (int i = 0; i < __rowCount; i++)
171 const ArrayList* pDataRowArrayList = static_cast<const ArrayList*>(__pDataSet->GetAt(i));
172 hash += _DataRowImpl::GetHashCode(pDataRowArrayList);
179 _DataSetImpl::GetInstance(DataSet& dataSet)
181 return dataSet.__pDataSetImpl;
185 _DataSetImpl::GetInstance(const DataSet& dataSet)
187 return dataSet.__pDataSetImpl;