Home | History | Annotate | Download | only in source
      1 /*****************************************************************************/
      2 // Copyright 2006-2007 Adobe Systems Incorporated
      3 // All Rights Reserved.
      4 //
      5 // NOTICE:  Adobe permits you to use, modify, and distribute this file in
      6 // accordance with the terms of the Adobe license agreement accompanying it.
      7 /*****************************************************************************/
      8 
      9 /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_string_list.cpp#1 $ */
     10 /* $DateTime: 2012/05/30 13:28:51 $ */
     11 /* $Change: 832332 $ */
     12 /* $Author: tknoll $ */
     13 
     14 /*****************************************************************************/
     15 
     16 #include "dng_string_list.h"
     17 
     18 #include "dng_bottlenecks.h"
     19 #include "dng_exceptions.h"
     20 #include "dng_string.h"
     21 #include "dng_utils.h"
     22 
     23 /*****************************************************************************/
     24 
     25 dng_string_list::dng_string_list ()
     26 
     27 	:	fCount     (0)
     28 	,	fAllocated (0)
     29 	,	fList      (NULL)
     30 
     31 	{
     32 
     33 	}
     34 
     35 /*****************************************************************************/
     36 
     37 dng_string_list::~dng_string_list ()
     38 	{
     39 
     40 	Clear ();
     41 
     42 	}
     43 
     44 /*****************************************************************************/
     45 
     46 void dng_string_list::Allocate (uint32 minSize)
     47 	{
     48 
     49 	if (fAllocated < minSize)
     50 		{
     51 
     52 		uint32 newSize = Max_uint32 (minSize, fAllocated * 2);
     53 
     54 		dng_string **list = (dng_string **)
     55 							malloc (newSize * sizeof (dng_string *));
     56 
     57 		if (!list)
     58 			{
     59 
     60 			ThrowMemoryFull ();
     61 
     62 			}
     63 
     64 		if (fCount)
     65 			{
     66 
     67 			DoCopyBytes (fList, list, fCount * (uint32) sizeof (dng_string *));
     68 
     69 			}
     70 
     71 		if (fList)
     72 			{
     73 
     74 			free (fList);
     75 
     76 			}
     77 
     78 		fList = list;
     79 
     80 		fAllocated = newSize;
     81 
     82 		}
     83 
     84 	}
     85 
     86 /*****************************************************************************/
     87 
     88 void dng_string_list::Insert (uint32 index,
     89 							  const dng_string &s)
     90 	{
     91 
     92 	Allocate (fCount + 1);
     93 
     94 	dng_string *ss = new dng_string (s);
     95 
     96 	if (!ss)
     97 		{
     98 
     99 		ThrowMemoryFull ();
    100 
    101 		}
    102 
    103 	fCount++;
    104 
    105 	for (uint32 j = fCount - 1; j > index; j--)
    106 		{
    107 
    108 		fList [j] = fList [j - 1];
    109 
    110 		}
    111 
    112 	fList [index] = ss;
    113 
    114 	}
    115 
    116 /*****************************************************************************/
    117 
    118 bool dng_string_list::Contains (const dng_string &s) const
    119 	{
    120 
    121 	for (uint32 j = 0; j < fCount; j++)
    122 		{
    123 
    124 		if ((*this) [j] == s)
    125 			{
    126 
    127 			return true;
    128 
    129 			}
    130 
    131 		}
    132 
    133 	return false;
    134 
    135 	}
    136 
    137 /*****************************************************************************/
    138 
    139 void dng_string_list::Clear ()
    140 	{
    141 
    142 	if (fList)
    143 		{
    144 
    145 		for (uint32 index = 0; index < fCount; index++)
    146 			{
    147 
    148 			delete fList [index];
    149 
    150 			}
    151 
    152 		free (fList);
    153 
    154 		fList = NULL;
    155 
    156 		}
    157 
    158 	fCount     = 0;
    159 	fAllocated = 0;
    160 
    161 	}
    162 
    163 /*****************************************************************************/
    164