Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phInt32Array.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission :
00003         Realtime Vision Processing System
00004 
00005     Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008 
00009     This file is part of Phission.
00010 
00011     Phission is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU Lesser General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     Phission is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU Lesser General Public License for more details.
00020 
00021     You should have received a copy of the GNU Lesser General Public License
00022     along with Phission; if not, write to the Free Software
00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 
00025  ---------------------------------------------------------------------------*/
00026 #ifdef HAVE_CONFIG_H
00027     #include <phissionconfig.h>
00028 #endif
00029 
00030 #include <phStandard.h>
00031 
00032 #include <phError.h>
00033 #include <phMemory.h>
00034 #include <phPrint.h>
00035 
00036 #include <phInt32Array.h>
00037 
00038 #ifdef __cplusplus
00039 extern "C" 
00040 {
00041 #endif
00042 
00043 /* ------------------------------------------------------------------------ */
00044 struct ph_int32_array_t
00045 {
00046     uint32_t    m_length;
00047     int32_t     *m_array;
00048 };
00049 
00050 /* ------------------------------------------------------------------------ */
00051 int ph_int32_array_new( struct ph_int32_array_t **arr )
00052 {
00053     phFUNCTION("ph_int32_array_new")
00054 
00055     if ((arr == NULL) || (*arr != NULL)) return phFAIL;
00056     
00057     (*arr) = (struct ph_int32_array_t *)phCalloc(1,
00058                                       sizeof(struct ph_int32_array_t));
00059     phCHECK_PTR((*arr),"phCalloc","phCalloc failed to allocate ph_int32_array");
00060 
00061     (*arr)->m_length = 0;
00062     (*arr)->m_array  = NULL;
00063     
00064     return phSUCCESS;
00065 error:
00066     return phFAIL;
00067 }
00068 
00069 /* ------------------------------------------------------------------------ */
00070 int ph_int32_array_append( struct ph_int32_array_t *arr, int32_t value )
00071 {
00072     phFUNCTION("ph_int32_array_append")
00073     
00074     if (arr == NULL) return phFAIL;
00075 
00076     arr->m_length++;
00077     
00078     if (arr->m_array == NULL)
00079     {
00080         arr->m_array = (int32_t *)phCalloc(arr->m_length,sizeof(int32_t));
00081         phCHECK_PTR(arr->m_array,"phCalloc","phCalloc failed to alloc array");
00082     }
00083     else
00084     {
00085         arr->m_array = (int32_t *)phRealloc(arr->m_array,
00086                                         arr->m_length * sizeof(int32_t));
00087         phCHECK_PTR(arr->m_array,"phRealloc","phRealloc failed to grow array");
00088     }
00089 
00090     arr->m_array[arr->m_length - 1] = value;
00091     
00092     return phSUCCESS;
00093     
00094 error:
00095     return phFAIL;
00096 }
00097 
00098 /* ------------------------------------------------------------------------ */
00099 uint32_t ph_int32_array_get_length( struct ph_int32_array_t *arr )
00100 {
00101     uint32_t retrc = 0;
00102     
00103     if (arr != NULL)
00104         retrc = arr->m_length;
00105 
00106     return retrc;
00107 }
00108 
00109 /* ------------------------------------------------------------------------ */
00110 int ph_int32_array_get( struct ph_int32_array_t *arr, uint32_t index,
00111                       int32_t *retval )
00112 {
00113     if ((arr == NULL) || (retval == NULL)) return phFAIL;
00114     if (arr->m_length <= index) return phFAIL;
00115 
00116     (*retval) = arr->m_array[index];
00117     
00118     return phFAIL;
00119 }
00120 
00121 /* ------------------------------------------------------------------------ */
00122 /* returns: phSUCCESS, phFAIL, 1 */
00123 int ph_int32_array_find( struct ph_int32_array_t *arr, int32_t value,
00124                        uint32_t *retindex )
00125 {
00126     uint32_t i = 0;
00127     int found = phSUCCESS;
00128     
00129     if (arr == NULL) return phFAIL;
00130    
00131     for (i = 0; i < arr->m_length; i++ )
00132         if (arr->m_array[i] == value)
00133         {
00134             if (retindex != NULL) *retindex = i;
00135             i = arr->m_length;
00136             found = 1;
00137         }
00138     
00139     return found;
00140 }
00141 
00142 /* ------------------------------------------------------------------------ */
00143 int ph_int32_array_empty( struct ph_int32_array_t *arr )
00144 {
00145     if (arr == NULL) return phFAIL;
00146 
00147     phFree(arr->m_array);
00148     arr->m_length = 0;
00149     
00150     return phSUCCESS;
00151 }
00152 
00153 /* ------------------------------------------------------------------------ */
00154 int ph_int32_array_free( struct ph_int32_array_t **arr )
00155 {
00156     if (arr == NULL) return phFAIL;
00157     if (*arr == NULL) return phSUCCESS;
00158 
00159     phFree((*arr)->m_array);
00160     phFree(*arr);
00161     
00162     return phSUCCESS;
00163 }
00164 
00165 /* ------------------------------------------------------------------------ */
00166 #ifdef __cplusplus
00167 } /* extern "C" { */
00168 #endif
00169 




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:02 2007 for phission by  doxygen 1.4.4