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

phObject.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 <phObject.h>
00033 
00034 #include <phError.h>
00035 #include <phMemory.h>
00036 #include <phPrint.h>
00037 
00038 /* ------------------------------------------------------------------------ */
00039 phObject::phObject()
00040 {
00041     this->m_phObject_name       = NULL;
00042     this->m_phObject_name_array = NULL;
00043     this->m_phObject_name_count = 0;
00044 }
00045 
00046 /* ------------------------------------------------------------------------ */
00047 phObject::phObject(const char *name)
00048 {
00049     this->m_phObject_name       = NULL;
00050     this->m_phObject_name_array = NULL;
00051     this->m_phObject_name_count = 0;
00052 
00053     this->setName(name);
00054 }
00055 
00056 /* ------------------------------------------------------------------------ */
00057 phObject::~phObject()
00058 {
00059     unsigned long i = 0;
00060 
00061     this->m_phObject_name       = NULL;
00062     
00063     for (i = 0; i < this->m_phObject_name_count; i++ )
00064     {
00065         phFree(this->m_phObject_name_array[i]);
00066     }
00067     
00068     phFree(this->m_phObject_name_array);
00069     this->m_phObject_name_count = 0;
00070 }
00071 
00072 /* ------------------------------------------------------------------------ */
00073 void phObject::setName( const char *n)
00074 {
00075     phFUNCTION("phObject::setName")
00076     char        *name = NULL;
00077     uint32_t    length = 0;
00078     
00079     phStringCopy(n,1024,
00080                 &(name),
00081                 &(length),"phObject");
00082 
00083     /* Push */
00084     if (name != NULL) 
00085     {
00086         this->m_phObject_name_count++;
00087     }
00088     /* pop : free string pointer now */
00089     else if (this->m_phObject_name_count > 0)
00090     {
00091         this->m_phObject_name_count--;
00092         phFree(this->m_phObject_name_array[this->m_phObject_name_count]);
00093     }    
00094     
00095     /* no names? No need for the array */
00096     if ((this->m_phObject_name_array != NULL) && 
00097         (this->m_phObject_name_count == 0))
00098     {
00099         phFree(this->m_phObject_name_array);
00100     }
00101     
00102     if ((this->m_phObject_name_array == NULL) && 
00103         (this->m_phObject_name_count > 0))
00104     {
00105         this->m_phObject_name_array = 
00106                         (char **)phCalloc(this->m_phObject_name_count,
00107                                           sizeof(char*));
00108         phCHECK_NULLPTR(this->m_phObject_name_array,"phCalloc",
00109                       "(this:%p)phCalloc failed",this);
00110     }
00111     /* if m_count is adjusted less, then it pops; Otherwise more space
00112      * is allocated for a push */
00113     else if (this->m_phObject_name_count > 0)
00114     {
00115         this->m_phObject_name_array = 
00116                     (char **)phRealloc(this->m_phObject_name_array,
00117                         this->m_phObject_name_count * sizeof(char*));
00118         phCHECK_NULLPTR(this->m_phObject_name_array,"phRealloc",
00119                       "(this: %p) phRealloc failed",this);
00120     }
00121 
00122     /* Push */
00123     if (name != NULL)
00124     {
00125         this->m_phObject_name = 
00126            this->m_phObject_name_array[this->m_phObject_name_count - 1] = name;
00127     }
00128 
00129     /* no name */
00130     if (this->m_phObject_name_count == 0)
00131     {
00132         this->m_phObject_name = NULL;
00133     }
00134 error:
00135     return;
00136 }
00137 
00138 /* ------------------------------------------------------------------------ */
00139 const char *phObject::getName()
00140 {
00141     return this->m_phObject_name;
00142 }
00143 
00144 /* ------------------------------------------------------------------------ */
00145 const char **phObject::getNameArray()
00146 {
00147     return (const char **)this->m_phObject_name_array;
00148 }
00149 
00150 /* ------------------------------------------------------------------------ */
00151 unsigned long phObject::getNameCount()
00152 {
00153     return this->m_phObject_name_count;
00154 }
00155 
00156 /* ------------------------------------------------------------------------ */
00157 int phObject::isNamed( const char *n)
00158 {
00159     phFUNCTION("phObject::isNamed")
00160     int retrc = 0;
00161     
00162     uint32_t length = (uint32_t)((n != NULL) ? strlen(n) : 0);
00163     uint32_t this_length = (uint32_t)((this->m_phObject_name != NULL) ? 
00164                                         strlen(this->m_phObject_name) : 0);
00165 
00166     if ((this_length == 0) || 
00167         (length == 0) || 
00168         (this_length != length))
00169     {
00170         retrc = phFAIL;
00171     }
00172     else
00173     {
00174         rc = strncmp(this->m_phObject_name, n, length);
00175         if (rc == 0) retrc = 1;
00176         if (rc != 0) retrc = 0;
00177     }
00178 
00179     return retrc;
00180 }
00181 
00182 /* ------------------------------------------------------------------------ */
00183 int phObject::hasParent( const char *n )
00184 {
00185     phFUNCTION("phObject::hasParent")
00186     int retrc = 0;
00187     
00188     long long i = 0;
00189     unsigned long length = ((n != NULL) ? strlen(n) : 0);
00190     unsigned long this_length = 0;
00191 
00192     if ((this->m_phObject_name_array == NULL)||(n==NULL)) return phFAIL;
00193     
00194     for ((i = this->m_phObject_name_count - 1); 
00195          (i >= 0) && (retrc == 0); i-- )
00196     {
00197         this_length = ((this->m_phObject_name_array[i] != NULL) ? 
00198                        strlen(this->m_phObject_name_array[i]) : 0);
00199 
00200         this_length = (this_length > length) ? length : this_length;
00201 
00202         rc = strncmp(this->m_phObject_name_array[i], n, this_length);
00203         if (rc == 0) retrc = 1;
00204         if (rc != 0) retrc = 0;
00205     }
00206 
00207     return retrc;
00208 }
00209 
00210 /* ---------------------------------------------------------------------- */
00211 int phObject::copy( phObject *copyto_obj )
00212 {
00213     phFUNCTION("phObject::copy")
00214     
00215     /* This should be overloaded by an inheriting object
00216      * to actually copy data; */
00217     
00218     return phSUCCESS;
00219 }
00220 /* ---------------------------------------------------------------------- */
00221 int phObject::swap( phObject *obj )
00222 {
00223     phFUNCTION("phObject::swap")
00224     
00225     /* This should be overloaded by an inheriting object
00226      * to actually copy data; */
00227     
00228     return phSUCCESS;
00229 }




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