New target "hc08" for the Motorola 68hc08 family of micros
[fw/sdcc] / sim / ucsim / pobj.cc
index 2149ecd715294e0b974fd79b8f6823ad63e22ac2..f747e96bbd9473988f2970dbc821bc21afc1eced 100644 (file)
@@ -46,18 +46,46 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  * Initializing the object
  */
 
-cl_base::cl_base(void) {}
+cl_base::cl_base(void)
+{
+  name= 0;
+}
 
 
 /* 
  * Destructing the object: calling hte virtual Done method
  */
 
-cl_base::~cl_base(void) {}
-
+cl_base::~cl_base(void)
+{
+  if (name)
+    free(name);
+}
 
 int cl_base::init(void) {return(0);}
 
+char *
+cl_base::get_name(char *def)
+{
+  if (!name)
+    return(def);
+  return(name);
+}
+
+char *
+cl_base::set_name(char *new_name)
+{
+  if (name)
+    free(name);
+  if (!new_name)
+    name= 0;
+  else if (*new_name)
+    name= strdup(new_name);
+  else
+    name= strdup("");
+  return(name);
+}
+
 
 /*                                                                         *
   ==========================================================================*
@@ -87,7 +115,8 @@ cl_list::cl_list(t_index alimit, t_index adelta):
 
 cl_list::~cl_list(void)
 {
-  delete Items;
+  //delete Items;
+  free(Items);
 }
 
 
@@ -136,7 +165,10 @@ cl_list::disconn_at(t_index index)
 void
 cl_list::disconn(void *item)
 {
-  disconn_at(index_of(item));
+  t_index i;
+
+  if (index_of(item, &i))
+    disconn_at(i);
 }
 
 
@@ -164,6 +196,19 @@ cl_list::free_at(t_index index)
   free_item(Item);
 }
 
+void
+cl_list::free_all(void)
+{
+  t_index i;
+
+  if (count)
+    {
+      for (i= count-1; i; i--)
+       free_at(i);
+      free_at(0);
+    }
+}
+
 
 /*
  * Inserting a new item to the exact position
@@ -297,6 +342,19 @@ cl_list::index_of(void *item)
   return(0);    /* Needed by Sun! */
 }
 
+bool
+cl_list::index_of(void *item, t_index *idx)
+{
+  for (t_index i= 0; i < count; i++)
+    if (item == Items[i])
+      {
+       if (idx)
+         *idx= i;
+       return(DD_TRUE);
+      }
+  return(DD_FALSE);
+}
+
 
 /* 
  * Inserting a new item to the collection.
@@ -377,13 +435,14 @@ cl_list::set_limit(t_index alimit)
        AItems= 0;
       else
        {
-         AItems = new void *[alimit];
-         //i= ALimit*(sizeof(void *));
-         //AItems= (void **)malloc(i);
+         //AItems = new void *[alimit];
+         int i= alimit*(sizeof(void *));
+         AItems= (void **)malloc(i);
          if (count)
            memcpy(AItems, Items, count*sizeof(void *));
        }
-      delete Items;
+      //delete Items;
+      free(Items);
       Items= AItems;
       Limit= alimit;
     }