hostsupport/hostopengles20/src/GLES2/object.c
branchbug235_bringup_0
changeset 53 c2ef9095503a
parent 24 a3f46bb01be2
equal deleted inserted replaced
52:39e5f73667ba 53:c2ef9095503a
       
     1 /* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2  *
       
     3  * Permission is hereby granted, free of charge, to any person obtaining a
       
     4  * copy of this software and associated documentation files (the "Software"),
       
     5  * to deal in the Software without restriction, including without limitation
       
     6  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
       
     7  * and/or sell copies of the Software, and to permit persons to whom the
       
     8  * Software is furnished to do so, subject to the following conditions:
       
     9  *
       
    10  * The above copyright notice and this permission notice shall be included
       
    11  * in all copies or substantial portions of the Software.
       
    12  *
       
    13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
       
    14  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
       
    15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
       
    16  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
       
    17  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
       
    18  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
       
    19  *
       
    20  * Initial Contributors:
       
    21  * Nokia Corporation - initial contribution.
       
    22  *
       
    23  * Contributors:
       
    24  *
       
    25  * Description:
       
    26  *
       
    27  */
       
    28 
       
    29 #include "object.h"
       
    30 
       
    31 void DGLObject_insert(DGLObject** root, DGLObject* object)
       
    32 {
       
    33 	// Insert the object into the linked list while maintaining the ordering by name.
       
    34 
       
    35 	DGLES2_ASSERT(root != NULL);
       
    36 	DGLES2_ASSERT(object != NULL);
       
    37 
       
    38 	if(*root == NULL)
       
    39 	{
       
    40 		// This is the first object.
       
    41 		*root = object;
       
    42 	}
       
    43 	else if((*root)->name > object->name)
       
    44 	{
       
    45 		// Insert in the front.
       
    46 		object->next = *root;
       
    47 		*root = object;
       
    48 	}
       
    49 	else
       
    50 	{
       
    51 		DGLObject* prev = *root;
       
    52 		while(prev->next != NULL && prev->next->name < object->name)
       
    53 		{
       
    54 			prev = prev->next;
       
    55 		}
       
    56 		
       
    57 		object->next = prev->next;
       
    58 		prev->next = object;
       
    59 	}
       
    60 }
       
    61 
       
    62 DGLObject* DGLObject_remove(DGLObject** root, GLuint name)
       
    63 {
       
    64 	DGLES2_ASSERT(root != NULL);
       
    65 	{
       
    66 		DGLObject* object = *root;
       
    67 
       
    68 		if(object == NULL)
       
    69 		{
       
    70 			// There are no buffers.
       
    71 			return NULL;
       
    72 		}
       
    73 
       
    74 		if(object->name == name)
       
    75 		{
       
    76 			// The first buffer is to be destroyed.
       
    77 			*root = object->next;
       
    78 			return object;
       
    79 		}
       
    80 		else
       
    81 		{
       
    82 			DGLObject* removed = NULL;
       
    83 
       
    84 			while(object->next != NULL && object->next->name != name)
       
    85 			{
       
    86 				object = object->next;
       
    87 			}
       
    88 
       
    89 			if(object->next != NULL)
       
    90 			{
       
    91 				// The buffer to be destroyed was found.
       
    92 				DGLObject* newNext = object->next->next;
       
    93 				removed = object->next;
       
    94 				object->next = newNext;
       
    95 			}
       
    96 
       
    97 			return removed;
       
    98 		}
       
    99 	}
       
   100 }
       
   101 
       
   102 DGLObject* DGLObject_find(DGLObject* root, GLuint name)
       
   103 {
       
   104 	DGLObject* object = root;
       
   105 	while(object != NULL && object->name != name)
       
   106 	{
       
   107 		object = object->next;
       
   108 	}
       
   109 	return object;
       
   110 }