EDA/idList: Fixed remaining issues with 64 bit Id
[sdk] / eda / libeda / src / idList.ec
index f6be74c..50425a0 100644 (file)
@@ -30,7 +30,7 @@ __attribute__((unused)) static void UnusedFunction()
 }
 private:
 
-public class Id : uint
+public class Id : uint64
 {
    class_data Table * table;     class_property Table * table     { set { class_data(table) = value; } get { return class_data(table); } };
    //class_data Field * idField; class_property Field * idField { set { class_data(nameField) = value; } get { return class_data(idField); } };
@@ -67,8 +67,7 @@ public class Id : uint
 
             bool DataBox::NotifySelect(DropBox control, DataRow row, Modifiers mods)
             {
-               // TOFIX: Id is still 32 bit
-               uint id = (uint)(row ? row.tag : 0);
+               Id id = (Id)(row ? row.tag : 0);
                SetData(&id, mods.closingDropDown);
                return true;
             }
@@ -155,7 +154,7 @@ public class Id : uint
       dropBox.Create();
       dropBox.currentRow = dropBox.FindSubRow(this);
       if(!dropBox.currentRow && this)
-         dataBox.SetData((uint *)&this, false);
+         dataBox.SetData((Id *)&this, false);
       {
          DataRow r = dropBox.currentRow;
          if(r)
@@ -169,6 +168,7 @@ public class Id : uint
    {
       if(&this)
       {
+         Id thisID = this;
          // FIXME
          Table tbl = class_data(table) ? *class_data(table) : null;
          if(tbl)
@@ -183,9 +183,9 @@ public class Id : uint
             }
             r = tbl.cachedIdRow;
 
-            if(this)
+            if(thisID)
             {
-               if(r.Find(idField, middle, nil, this))
+               if(r.Find(idField, middle, nil, thisID))
                {
                   String name = null;
                   Field * nameField = class_data(nameField);
@@ -204,18 +204,18 @@ public class Id : uint
                            type = dataType;
                      }
                      if(type.type == structClass)
-                        data = (int64)new0 byte[type.structSize];
-                     ((bool (*)())(void *)r.GetData)(r, *nameField, type, (type.type == structClass) ? (void *)data : &data);
+                        data = (int64)(intptr)new0 byte[type.structSize];
+                     ((bool (*)())(void *)r.GetData)(r, *nameField, type, (type.type == structClass) ? (void *)(intptr)data : &data);
 
                      if(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass)
                         name = ((char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, (void *)&data, tempString, null, null);
                      else
-                        name = ((char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, (void *)data, tempString, null, null);
+                        name = ((char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, (void *)(intptr)data, tempString, null, null);
 
                      if(name && name != tempString)
                         strcpy(tempString, name ? name : "");
                      if(!(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass))
-                        ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)data);
+                        ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)(intptr)data);
                   }
                   else
                   {
@@ -223,7 +223,15 @@ public class Id : uint
                   }
                }
                else
-                  sprintf(tempString, "(Invalid %s entry: %d)", tbl.name, this);
+               {
+                 sprintf(tempString, "(Invalid %s entry: "
+                    #if defined(__WIN32__)
+                     "%I64d"
+                    #else
+                     "%lld"
+                    #endif
+                     ")", tbl.name, thisID);
+               }
             }
             else
             {
@@ -234,7 +242,7 @@ public class Id : uint
          }
          else
          {
-            uint id = this;
+            Id id = thisID;
             id.OnGetString(tempString, null, null);
          }
       }
@@ -355,18 +363,19 @@ public:
       stringOutput[0] = 0;
       if(this)
       {
-         int c;
-         for(c = 0; c<count; c++)
+         Class type = class_data(type);
+         if(type)
          {
             char tempString[256];
-            Class type = class_data(type);
-            String s;
-            if(c) strcat(stringOutput, ", ");
+            int c;
+            for(c = 0; c<count; c++)
+            {
+               String s = ((char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &ids[c], tempString, null, null);
+               if(c) strcat(stringOutput, ", ");
 
-            if(type)
-               s = ((char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &ids[c], tempString, null, null);
-            // strcatf(stringOutput, "%d", ids[c]);
-            strcat(stringOutput, s);
+               // strcatf(stringOutput, "%d", ids[c]);
+               strcat(stringOutput, s);
+            }
          }
       }
       return stringOutput;
@@ -394,7 +403,7 @@ public:
          int c;
          for(c = 0; c<count; c++)
          {
-            int idA = ids[c], idB = b.ids[c];
+            Id idA = ids[c], idB = b.ids[c];
             if(idA > idB) return 1;
             else if(idA < idB) return -1;
          }
@@ -424,7 +433,7 @@ public:
                if(row == listBox.lastRow)
                {
                   row = listBox.AddRow();
-                  row.SetData(null, 0);
+                  row.SetData(null, (Id)0);
                   listBox.scroll.y = listBox.scrollArea.h;
                }
                else if(row.next == listBox.lastRow)
@@ -450,7 +459,7 @@ public:
          r.SetData(null, ids[c]);
       }
       r = list.AddRow();
-      r.SetData(null, 0);
+      r.SetData(null, (Id)0);
       list.Create();
       list.modifiedDocument = false;
       return list;
@@ -482,6 +491,67 @@ public:
    }
 }
 
+public class IdList32 : IdList
+{
+   void OnUnserialize(IOChannel channel)
+   {
+      int c, count;
+
+      this = null;
+
+      channel.Unserialize(count);
+      if(count != MAXDWORD)
+      {
+         IdList idList = eInstance_New(_class);
+         idList.count = count;
+         idList.ids = new Id[count];
+         for(c = 0; c < count; c++)
+         {
+            uint32 id;
+            channel.Unserialize(id);
+            idList.ids[c] = id;
+         }
+         this = idList;
+      }
+   }
+
+   void OnSerialize(IOChannel channel)
+   {
+      if(this)
+      {
+         int c;
+         channel.Serialize(count);
+         for(c = 0; c < count; c++)
+            channel.Serialize((uint32)ids[c]);
+      }
+      else
+      {
+         Id none = MAXDWORD;
+         channel.Serialize((uint32)none);
+      }
+   }
+}
+
+public class IdListIncludes : SQLCustomFunction
+{
+   // Should private methods be added to the component system?
+public:
+   bool function(IdList list, Id id)
+   {
+      return list.Includes(id);
+   }
+}
+
+public class IdList32Includes : SQLCustomFunction
+{
+   // Should private methods be added to the component system?
+public:
+   bool function(IdList32 list, Id id)
+   {
+      return list.Includes(id);
+   }
+}
+
 static void FreeString(String string)
 {
    delete string;
@@ -950,7 +1020,7 @@ public struct DataList : OldList
                   if(type.type == normalClass || type.type == structClass || type.type == noHeadClass)
                      listBox.AddRow().SetData(null, null);
                   else
-                     listBox.AddRow().SetData(null, 0);
+                     listBox.AddRow().SetData(null, (Id)0);
                   listBox.scroll.y = listBox.scrollArea.h;
                   listBox.alwaysEdit = true;
                }
@@ -970,7 +1040,7 @@ public struct DataList : OldList
             // if(type.type != normalClass || strcmp(type.dataTypeString, "char *"))
             if(type)
             {
-               void * data = ((type.type == normalClass || type.type == noHeadClass || type.type == structClass) ? row.GetData(null) : (void *)(uintptr)*(uint *)row.GetData(null));
+               void * data = ((type.type == normalClass || type.type == noHeadClass || type.type == structClass) ? row.GetData(null) : (void *)(uintptr)*(Id *)row.GetData(null));
                if(!data)
                {
                   //if(strcmp(type.dataTypeString, char *"))
@@ -998,7 +1068,7 @@ public struct DataList : OldList
                if(type.type == normalClass || type.type == structClass || type.type == noHeadClass)
                   lastRow.SetData(null, null);
                else
-                  lastRow.SetData(null, 0);
+                  lastRow.SetData(null, (Id)0);
             }
          }
       };
@@ -1026,7 +1096,7 @@ public struct DataList : OldList
       if(type.type == normalClass || type.type == structClass || type.type == noHeadClass)
          r.SetData(null, null);
       else
-         r.SetData(null, 0);
+         r.SetData(null, (Id)0);
       list.Create();
       list.modifiedDocument = false;
       return list;