Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

idbase.cc

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------
00002  *
00003  * (C) Copyright Koninklijke Philips Electronics NV 2006. 
00004  * All rights reserved. This software is licensed under the terms of
00005  * version 2.1 of the GNU Lesser General Public License as published 
00006  * by the Free Software Foundation. For licensing and warranty
00007  * information, see the file COPYING in the main directory.
00008  *
00009  *------------------------------------------------------------------*/
00010 
00011 #include "idbase.h"
00012 
00013 #include <stdlib.h>
00014 #include <string.h>
00015 #include "strdup.h"
00016 
00017 #include <iostream>
00018 
00019 IdBase::IdBase(const char* n, IdBase* p)
00020 {
00021   nm = strDup(n);
00022   pa = p;
00023 }
00024 
00025 IdBase::IdBase(const IdBase& i)
00026 {
00027   nm = strDup(i.nm);
00028   pa = i.pa;
00029 }
00030 
00031 IdBase::~IdBase()
00032 {
00033   free(nm);
00034 }
00035 
00036 IdBase& IdBase::operator=(const IdBase& i)
00037 {
00038   if (this != &i)
00039   {
00040     free(nm);
00041     nm = strDup(i.nm);
00042     pa = i.pa;
00043   }
00044   return *this;
00045 }
00046 
00047 IdBase& IdBase::operator+(char c)
00048 {
00049   char* n = (char*)malloc(strlen(this->nm) + 2);
00050   strcpy(n, this->nm);
00051   strncat(n, &c,1);
00052   free(this->nm);
00053   this->nm = n;
00054 
00055   return *this;
00056 }
00057 
00058 IdBase& IdBase::operator+(const char* str)
00059 {
00060   char* n = (char*)malloc(strlen(this->nm) + strlen(str) + 1);
00061   strcpy(n, this->nm);
00062   strcat(n, str);
00063   free(this->nm);
00064   this->nm = n;
00065 
00066   return *this;
00067 }
00068 
00069 IdBase* IdBase::parent() const
00070 {
00071   return pa;
00072 }
00073 
00074 const char* IdBase::name() const
00075 {
00076   return nm;
00077 }
00078 
00079 const char* IdBase::fullName(char* buf) const
00080 { 
00081   static char static_buf[1024];
00082   if (!buf)
00083     buf = static_buf;
00084   IdBase* p = parent();
00085   if (p) 
00086   {
00087     p->fullName(buf);
00088     strcat(buf, ".");
00089   } 
00090   else
00091     buf[0] = '\0';
00092   strcat(buf, name());
00093   return buf;
00094 }
00095 
00096 IdBase::operator const char*() const
00097 {
00098   return fullName();
00099 }
00100 
00101 IdBase IdBase::id(const char* n) 
00102 {
00103   return IdBase(n, this);
00104 }
00105 
00106 

Generated on Wed Feb 15 14:52:39 2006 for yapi by doxygen 1.3.2