[x265] [PATCH] List: std::list Implementation

Gopu Govindaswamy gopu at multicorewareinc.com
Mon Sep 16 12:31:26 CEST 2013


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1379327475 -19800
# Node ID e499466c7c6591345af2a625da12185c7735347b
# Parent  6bab41a554b36133865fe3378964cb9e76c24ebd
List: std::list Implementation

To remove the std::list dependency from X265,  and this class can be enhanced based on the types of std::list API's used in current x265

diff -r 6bab41a554b3 -r e499466c7c65 source/common/CMakeLists.txt
--- a/source/common/CMakeLists.txt	Fri Sep 13 17:24:05 2013 +0530
+++ b/source/common/CMakeLists.txt	Mon Sep 16 16:01:15 2013 +0530
@@ -16,8 +16,10 @@
 
 file(GLOB LIBCOMMON_HDR ../Lib/TLibCommon/*.h)
 file(GLOB LIBCOMMON_SRC ../Lib/TLibCommon/*.cpp)
+file(GLOB LIBUTIL ../util/*.cpp ../util/*.h)
 source_group(TLibCommon FILES ${LIBCOMMON_SRC})
 source_group(TLibCommonH FILES ${LIBCOMMON_HDR})
+source_group(Util FILES ${LIBUTIL})
 if(GCC)
     set_source_files_properties(${LIBCOMMON_SRC} PROPERTIES COMPILE_FLAGS 
         "-Wno-sign-compare")
@@ -38,7 +40,7 @@
 endif(MSVC)
 
 add_library(common STATIC ../../COPYING
-    ${LIBCOMMON_SRC} ${LIBCOMMON_HDR}
+    ${LIBCOMMON_SRC} ${LIBCOMMON_HDR} ${LIBUTIL}
     primitives.cpp primitives.h
     pixel.cpp dct.cpp ipfilter.cpp intrapred.cpp
     ../VectorClass/instrset_detect.cpp
diff -r 6bab41a554b3 -r e499466c7c65 source/util/list.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/util/list.h	Mon Sep 16 16:01:15 2013 +0530
@@ -0,0 +1,158 @@
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Authors: Gopu Govindaswamy <gopu at multicorewareinc.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing at multicorewareinc.com.
+ *****************************************************************************/
+
+#ifndef X265_LIST_H
+#define X265_LIST_H
+
+#include "common.h"
+
+// Short Notes: 
+// Under development
+// this class is used to remove the std::list dependency from x265, 
+// Providing Minimum std::list API implementation
+// this class can be enhanced based on types of std::list API's used in current x265
+
+template<class T>
+struct List
+{
+private:
+
+    struct Node
+    {
+        T object;
+        Node* next;
+    };
+
+public:
+
+    Node* head;
+    Node* tail;
+    int size;
+
+    List() { head = 0; size = 0; }
+
+    inline T* begin() { return head; }
+
+    inline T* end() { return tail; }
+
+    inline bool isEmpty()
+    {
+        if (head == NULL)
+            return true;
+        else
+            return false;
+    }
+
+    inline void push_back(T value)
+    {
+        if (head == NULL)
+        {
+            head = (Node*)X265_MALLOC(Node, sizeof(Node));
+            head->object = value;
+            head->next = NULL;
+            tail = head;
+        }
+        else
+        {
+            Node *nodePtr = tail;
+            nodePtr->next = (Node*)X265_MALLOC(Node, sizeof(Node));
+            nodePtr->next->object = value;
+            nodePtr->next->next = NULL;
+            tail = nodePtr->next;
+        }
+        size += 1;
+    }
+
+    inline void push_front(T value)
+    {
+        if (head == NULL)
+        {
+            head = (Node*)X265_MALLOC(Node, sizeof(Node));
+            head->object = value;
+            head->next = NULL;
+            tail = head;
+        }
+        else
+        {
+            Node *front;
+            front = (Node*)X265_MALLOC(Node, sizeof(Node));
+            front->object = value;
+            front->next = head;
+            head = front;
+        }
+        size += 1;
+    }
+
+    inline void pop_front()
+    {
+        if (head != NULL)
+        {
+            if (head->next == NULL)
+                X265_FREE(head);
+            else
+            {
+                Node *temp = head->next;
+                X265_FREE(head);
+                head = temp;
+            }
+            size -= 1;
+        }
+    }
+
+    inline void pop_back()
+    {
+        if (head != NULL)
+        {
+            if (head->next == NULL)
+                X265_FREE(head);
+            else
+            {
+                Node *ptr = head, *ptr1 = NULL;
+                while (ptr->next != NULL)
+                {
+                    ptr1 = ptr;
+                    ptr = ptr->next;
+                }
+
+                X265_FREE(ptr1->next);
+                ptr1->next = NULL;
+            }
+            size -= 1;
+        }
+    }
+
+    inline void remove_all()
+    {
+        Node *temp = head;
+        Node *remove;
+
+        while (temp->next != NULL)
+        {
+            remove = temp->next;
+            X265_FREE(temp);
+            temp = remove;
+        }
+    }
+};
+
+#endif // ifndef X265_LIST_H


More information about the x265-devel mailing list