2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 FGrp_TextTextSimpleList.cpp
20 * @brief This is the implementation file for TextSimpleList class.
24 #include <FBaseSysLog.h>
25 #include "FGrp_TextTextSimpleList.h"
26 #include "FGrp_TextCommon.h"
28 namespace Tizen { namespace Graphics
34 TextSimpleList::Create(void)
36 SimpleList* pSimpleList = null;
38 pSimpleList = new (std::nothrow) SimpleList;
44 TextSimpleList::Destory(SimpleList* pSimpleList)
46 DeleteAllObject(pSimpleList);
55 TextSimpleList::Init(SimpleList* pSimpleList)
59 , false, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
61 pSimpleList->pHeaderNode = null;
62 pSimpleList->pTailNode = null;
63 pSimpleList->nodeCount = 0;
69 TextSimpleList::InsertObject(SimpleList* pSimpleList, void* pObject, int index)
73 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
75 SimpleNode* pNode = null;
76 SimpleNode* pNextNode = null;
80 return AddObject(pSimpleList, pObject);
83 if (index >= pSimpleList->nodeCount)
85 return AppendObject(pSimpleList, pObject);
88 pNode = new (std::nothrow) SimpleNode;
94 pNode->pObject = pObject;
96 SimpleNode* pPrevNode = GetNthNode(pSimpleList, index - 1);
99 , , E_SYSTEM, "[E_SYSTEM] Fail to get node.");
101 pNextNode = pPrevNode->pNext;
104 , , E_SYSTEM, "[E_SYSTEM] Fail to get node.");
106 pNode->pNext = pNextNode;
107 pPrevNode->pNext = pNode;
109 pNode->pPrev = pPrevNode;
110 pNextNode->pPrev = pNode;
112 pSimpleList->nodeCount++;
124 TextSimpleList::IsEmpty(SimpleList* pSimpleList)
128 , false, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
132 if (pSimpleList->nodeCount == 0)
141 TextSimpleList::GetCount(SimpleList* pSimpleList)
145 , false, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
147 return pSimpleList->nodeCount;
151 TextSimpleList::AddObject(SimpleList* pSimpleList, void* pObject)
155 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
157 SimpleNode* pNode = null;
158 pNode = new (std::nothrow) SimpleNode;
164 pNode->pObject = pObject;
166 if (pSimpleList->pHeaderNode != null)
168 pNode->pNext = pSimpleList->pHeaderNode;
170 pSimpleList->pHeaderNode->pPrev = pNode;
171 pSimpleList->pHeaderNode = pNode;
175 pSimpleList->pHeaderNode = pNode;
176 pSimpleList->pTailNode = pNode;
181 pSimpleList->nodeCount++;
187 TextSimpleList::AppendObject(SimpleList* pSimpleList, void* pObject)
191 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
193 SimpleNode* pNode = null;
194 pNode = new (std::nothrow) SimpleNode;
200 pNode->pObject = pObject;
202 if (pSimpleList->pHeaderNode != null)
204 SimpleNode* pPrevNode = pSimpleList->pTailNode;
206 pPrevNode->pNext = pNode;
208 pNode->pPrev = pPrevNode;
209 pSimpleList->pTailNode = pNode;
213 pSimpleList->pHeaderNode = pNode;
214 pSimpleList->pTailNode = pNode;
219 pSimpleList->nodeCount++;
225 TextSimpleList::GetFirstNode(SimpleList* pSimpleList)
229 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
231 return pSimpleList->pHeaderNode;
235 TextSimpleList::GetLastNode(SimpleList* pSimpleList)
239 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
241 return pSimpleList->pTailNode;
245 TextSimpleList::DeleteNode(SimpleList* pSimpleList, SimpleNode* pNode)
249 , false, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
251 SimpleNode* pPrevNode = null;
253 if (pSimpleList->pHeaderNode == pNode)
255 if (pSimpleList->pTailNode == pNode)
257 pSimpleList->pHeaderNode = null;
258 pSimpleList->pTailNode = null;
262 pSimpleList->pHeaderNode = pSimpleList->pHeaderNode->pNext;
263 if (pSimpleList->pHeaderNode != null)
265 pSimpleList->pHeaderNode->pPrev = null;
269 else if (pSimpleList->pTailNode == pNode)
271 pSimpleList->pTailNode = pSimpleList->pTailNode->pPrev;
272 pSimpleList->pTailNode->pNext = null;
276 pPrevNode = pSimpleList->pHeaderNode;
277 while (pPrevNode && pPrevNode->pNext != pNode)
279 pPrevNode = pPrevNode->pNext;
287 pPrevNode->pNext = pNode->pNext;
289 if (pPrevNode->pNext != null)
291 pPrevNode->pNext->pPrev = pPrevNode;
297 pSimpleList->nodeCount--;
303 TextSimpleList::GetNthNode(SimpleList* pSimpleList, int index)
307 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
309 SimpleNode* pNode = null;
317 pNode = pSimpleList->pHeaderNode;
318 while (pNode && n < index)
320 pNode = pNode->pNext;
328 TextSimpleList::DeleteNthObject(SimpleList* pSimpleList, int index)
332 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
334 SimpleNode* pNode = null;
335 void* pObject = null;
337 if (pSimpleList->nodeCount == 0)
342 pNode = GetNthNode(pSimpleList, index);
348 pObject = pNode->pObject;
350 if (pSimpleList->pHeaderNode == pNode)
352 if (pSimpleList->pTailNode == pNode)
354 pSimpleList->pHeaderNode = null;
355 pSimpleList->pTailNode = null;
359 pSimpleList->pHeaderNode = pSimpleList->pHeaderNode->pNext;
360 if (pSimpleList->pHeaderNode != null)
362 pSimpleList->pHeaderNode->pPrev = null;
366 else if (pSimpleList->pTailNode == pNode)
368 pSimpleList->pTailNode = pSimpleList->pTailNode->pPrev;
369 pSimpleList->pTailNode->pNext = null;
373 SimpleNode* pPrevNode = null;
375 pPrevNode = pNode->pPrev;
376 pPrevNode->pNext = pNode->pNext;
377 if (pPrevNode->pNext != null)
379 pPrevNode->pNext->pPrev = pPrevNode;
386 pSimpleList->nodeCount--;
392 TextSimpleList::DeleteAllObject(SimpleList* pSimpleList)
396 , false, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
398 SimpleNode* pNode = null;
399 SimpleNode* pNextNode = null;
400 void* pObject = null;
402 if (pSimpleList->nodeCount <= 0)
407 pNode = pSimpleList->pHeaderNode;
409 while (pNode != null)
411 pNextNode = pNode->pNext;
412 pObject = pNode->pObject;
420 pSimpleList->nodeCount = 0;
421 pSimpleList->pHeaderNode = null;
422 pSimpleList->pTailNode = null;
428 TextSimpleList::GetFirstObject(SimpleList* pSimpleList)
432 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
434 SimpleNode* pNode = null;
436 pNode = GetFirstNode(pSimpleList);
440 , false, E_SYSTEM, "[E_SYSTEM] Fail to get first node.");
442 return pNode->pObject;
446 TextSimpleList::GetNthObject(SimpleList* pSimpleList, int index)
448 if (pSimpleList->nodeCount == 0)
454 , pSimpleList && index >= 0 && index < pSimpleList->nodeCount
455 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
457 SimpleNode* pNode = null;
459 pNode = GetNthNode(pSimpleList, index);
463 , false, E_SYSTEM, "[E_SYSTEM] Fail to get Nth Node.");
465 return pNode->pObject;
469 TextSimpleList::GetObjectIndex(SimpleList* pSimpleList, void* pObject)
473 , -1, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
475 SimpleNode* pNode = null;
478 pNode = pSimpleList->pHeaderNode;
481 if (pNode->pObject == pObject)
487 pNode = pNode->pNext;
494 TextSimpleList::InsertObjectAfterNode(SimpleList* pSimpleList, SimpleNode* pSimpleNode, void* pObject)
498 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
500 SimpleNode* pNode = null;
501 pNode = new (std::nothrow) SimpleNode;
507 pNode->pObject = pObject;
509 pNode->pNext = pSimpleNode->pNext;
510 if (pSimpleNode->pNext != null)
512 pSimpleNode->pNext->pPrev = pNode;
515 pSimpleNode->pNext = pNode;
516 pNode->pPrev = pSimpleNode;
518 if (pSimpleList->pTailNode == pSimpleNode)
520 pSimpleList->pTailNode = pNode;
523 pSimpleList->nodeCount++;
529 TextSimpleList::InsertObjectBeforeNode(SimpleList* pSimpleList, SimpleNode* pSimpleNode, void* pObject)
533 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
535 SimpleNode* pNode = null;
536 pNode = new (std::nothrow) SimpleNode;
542 pNode->pObject = pObject;
544 if (pSimpleNode->pPrev == null)
547 pNode->pNext = pSimpleNode;
548 pSimpleNode->pPrev = pNode;
549 pSimpleList->pHeaderNode = pNode;
553 pNode->pNext = pSimpleNode;
554 pSimpleNode->pPrev->pNext = pNode;
555 pNode->pPrev = pSimpleNode->pPrev;
556 pSimpleNode->pPrev = pNode;
559 pSimpleList->nodeCount++;
563 }}} // Tizen::Graphics::_Text