Merge "Modify the max count of player" 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         __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 = 1;
51
52         delete __pDataSet;
53         delete __pColumnList;
54         delete __pColumnTypeList;
55 }
56
57 result
58 _DataSetImpl::Construct(const IList& columnNames)
59 {
60         result r = E_SUCCESS;
61
62         __pDataSet = new (std::nothrow) LinkedList(SingleObjectDeleter);
63         SysTryReturnResult(NID_IO, __pDataSet != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
64         __pColumnList = new (std::nothrow) ArrayList(SingleObjectDeleter);
65         SysTryReturnResult(NID_IO, __pColumnList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
66         __pColumnTypeList = new (std::nothrow) ArrayList(SingleObjectDeleter);
67         SysTryReturnResult(NID_IO, __pColumnTypeList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
68
69         __columnCount = columnNames.GetCount();
70         SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_ARG, "column count is 0.");
71
72         r = __pColumnList->Construct(__columnCount);
73         SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column list construct failed");
74         r = __pColumnTypeList->Construct(__columnCount);
75         SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column type list construct failed");
76
77         for (int i = 0 ; i < __columnCount ; i++)
78         {
79                 r = __pColumnList->Add(new (std::nothrow) String(*(String*)(columnNames.GetAt(i))));
80                 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
81
82                 r = __pColumnTypeList->Add(new (std::nothrow) Integer(DB_COLUMNTYPE_NULL));
83                 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
84         }
85         //SysLog(NID_IO, "column count is %d", __columnCount);
86
87         return r;
88 }
89
90 DataRow*
91 _DataSetImpl::CreateDataRowN(void)
92 {
93         result r;
94         unique_ptr<ArrayList> pNewRowArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
95         SysTryReturn(NID_IO, pNewRowArrayList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
96
97         unique_ptr<DataRow> pDataRow(_DataRowImpl::CreateDataRowInstanceN(__columnCount, pNewRowArrayList.get()));
98         SysTryReturn(NID_IO, pDataRow != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
99
100         r = __pDataSet->Add(pNewRowArrayList.release());
101         SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add Row to DataSet is failed");
102
103         _DataRowImpl::GetInstance(*pDataRow)->__pColumnTypeList = __pColumnTypeList;
104
105         __rowCount = __pDataSet->GetCount();
106         //SysLog(NID_IO, "row count is %d", __rowCount);
107
108         return pDataRow.release();
109
110 }
111
112 DataSetEnumerator*
113 _DataSetImpl::GetDataSetEnumeratorN(void)
114 {
115         result r;
116
117         unique_ptr<DataSetEnumerator> pDataSetEnum(_DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN());
118
119         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pDataSet = __pDataSet;
120         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pColumnList = __pColumnList;
121         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__columnCount = __columnCount;
122         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__rowCount = __rowCount;
123
124         //SysLog(NID_IO, "row count is %d, column count is %d", __rowCount, __columnCount);
125
126         r = __enumImplList.Add(_DataSetEnumeratorImpl::GetInstance(*pDataSetEnum));
127         SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add to LinkedList Falied");
128
129         _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pEnumImplList = &__enumImplList;
130
131         return pDataSetEnum.release();
132 }
133
134 DataSet*
135 _DataSetImpl::CloneN(void) const
136 {
137         result r;
138
139         unique_ptr< DataSet > pDataSet(new (std::nothrow) DataSet());
140         SysTryReturn(NID_IO, pDataSet != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
141
142         pDataSet->Construct(*__pColumnList);
143
144         for (int i = 0; i < __columnCount; i++)
145         {
146                 r = _DataSetImpl::GetInstance(*pDataSet)->__pColumnTypeList->SetAt(new Integer(*(Integer*)__pColumnTypeList->GetAt(i)), i);
147                 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] ColumnTypeList Copy Falied");
148         }
149
150         for (int i = 0; i < __rowCount; i++)
151         {
152                 DataRow* pNewRow = pDataSet->CreateDataRowN();
153                 r = _DataRowImpl::GetInstance(*pNewRow)->Clone((const ArrayList*)(__pDataSet->GetAt(i)));
154                 delete pNewRow;
155
156                 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] DataRow Clone Falied");
157         }
158
159         return pDataSet.release();
160 }
161
162 bool
163 _DataSetImpl::Equals(const Tizen::Base::Object& obj) const
164 {
165         int thisHash = this->GetHashCode();
166         int othersHash = obj.GetHashCode();
167
168         if (thisHash == othersHash )
169                 return true;
170         else
171                 return false;
172 }
173
174 int
175 _DataSetImpl::GetHashCode(void) const
176 {
177         int hash = 0;
178
179         for (int i = 0; i < __rowCount; i++)
180         {
181                 const ArrayList* pDataRowArrayList = static_cast<const ArrayList*>(__pDataSet->GetAt(i));
182                 hash += _DataRowImpl::GetHashCode(pDataRowArrayList);
183         }
184
185         return hash;
186 }
187
188 _DataSetImpl*
189 _DataSetImpl::GetInstance(DataSet& dataSet)
190 {
191         return dataSet.__pDataSetImpl;
192 }
193
194 const _DataSetImpl*
195 _DataSetImpl::GetInstance(const DataSet& dataSet)
196 {
197         return dataSet.__pDataSetImpl;
198 }
199
200 }} // Tizen::Io
201
202