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;
385 pSimpleList->nodeCount--;
391 TextSimpleList::DeleteAllObject(SimpleList* pSimpleList)
395 , false, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
397 SimpleNode* pNode = null;
398 SimpleNode* pNextNode = null;
399 void* pObject = null;
401 if (pSimpleList->nodeCount <= 0)
406 pNode = pSimpleList->pHeaderNode;
408 while (pNode != null)
410 pNextNode = pNode->pNext;
411 pObject = pNode->pObject;
419 pSimpleList->nodeCount = 0;
420 pSimpleList->pHeaderNode = null;
421 pSimpleList->pTailNode = null;
427 TextSimpleList::GetFirstObject(SimpleList* pSimpleList)
431 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
433 SimpleNode* pNode = null;
435 pNode = GetFirstNode(pSimpleList);
439 , false, E_SYSTEM, "[E_SYSTEM] Fail to get first node.");
441 return pNode->pObject;
445 TextSimpleList::GetNthObject(SimpleList* pSimpleList, int index)
447 if (pSimpleList->nodeCount == 0)
453 , pSimpleList && index >= 0 && index < pSimpleList->nodeCount
454 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
456 SimpleNode* pNode = null;
458 pNode = GetNthNode(pSimpleList, index);
462 , false, E_SYSTEM, "[E_SYSTEM] Fail to get Nth Node.");
464 return pNode->pObject;
468 TextSimpleList::GetObjectIndex(SimpleList* pSimpleList, void* pObject)
472 , -1, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
474 SimpleNode* pNode = null;
477 pNode = pSimpleList->pHeaderNode;
480 if (pNode->pObject == pObject)
486 pNode = pNode->pNext;
493 TextSimpleList::InsertObjectAfterNode(SimpleList* pSimpleList, SimpleNode* pSimpleNode, void* pObject)
497 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
499 SimpleNode* pNode = null;
500 pNode = new (std::nothrow) SimpleNode;
506 pNode->pObject = pObject;
508 pNode->pNext = pSimpleNode->pNext;
509 if (pSimpleNode->pNext != null)
511 pSimpleNode->pNext->pPrev = pNode;
514 pSimpleNode->pNext = pNode;
515 pNode->pPrev = pSimpleNode;
517 if (pSimpleList->pTailNode == pSimpleNode)
519 pSimpleList->pTailNode = pNode;
522 pSimpleList->nodeCount++;
528 TextSimpleList::InsertObjectBeforeNode(SimpleList* pSimpleList, SimpleNode* pSimpleNode, void* pObject)
532 , null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
534 SimpleNode* pNode = null;
535 pNode = new (std::nothrow) SimpleNode;
541 pNode->pObject = pObject;
543 if (pSimpleNode->pPrev == null)
546 pNode->pNext = pSimpleNode;
547 pSimpleNode->pPrev = pNode;
548 pSimpleList->pHeaderNode = pNode;
552 pNode->pNext = pSimpleNode;
553 pSimpleNode->pPrev->pNext = pNode;
554 pNode->pPrev = pSimpleNode->pPrev;
555 pSimpleNode->pPrev = pNode;
558 pSimpleList->nodeCount++;
562 }}} // Tizen::Graphics::_Text