Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r33 - trunk

genelib
Discussion topic

Back to topic list

svn commit: r33 - trunk

Author lotec
Full name Jan Bogaerts
Date 2006-03-24 03:14:32 PST
Message Author: lotec
Date: Fri Mar 24 03:14:32 2006
New Revision: 33

Modified:
   trunk/BaseStore.gen
   trunk/Controls.gen
   trunk/string.gen
Log:
-string.gen: fixed release so that there is no more memleak
-BaseStore.gen: added duplicate to zeroEndArray

Modified: trunk/BaseStore.gen
Url: http://genelib.tigri​s.org/source/browse/​genelib/trunk/BaseSt​ore.gen?view=diff​&rev=33&p1=trun​k/BaseStore.gen&​r1=32&p2=trunk/B​aseStore.gen&r2=​33
====================​====================​====================​==================
--- trunk/BaseStore.gen (original)
+++ trunk/BaseStore.gen Fri Mar 24 03:14:32 2006
@@ -29,18 +29,16 @@
 //stLinkedList
 //this store is a basic linked list
 
-//the item that creates the linked list within the data
-struct sLinkedListItem =
+struct sLinkedListItem = //the item that creates the linked list within the data
  var PrevItem: sLinkedListItem^
      NextItem: sLinkedListItem^
 ;
 
-//the store itself
-store stLinkedList =
+store stLinkedList = //the store itself
  var FirstItem: sLinkedListItem^ = nil
            LastItem: sLinkedListItem^ = nil
            RecCount: int = 0
- exp SwitchWithNext(aItem: sLinkedListItem^) //used by SetNext, SetPrev to move the same item to
+ exp SwitchWithNext(aItem: sLinkedListItem^) //used by SetNext, SetPrev to move the same item to
  entity LinkItem: sLinkedListItem
  first read GetFirst: pointer inline = return(pointer(FirstItem));
            write SetFirst(aValue: pointer)
@@ -59,7 +57,6 @@
  operator '<<' CopyLData(aSize: dword): pointer inline
            '<<' CopyLDataInsert(aSize: dword, aBefore: pointer): pointer inline
            '>>' RemoveDataByRef(aVal: pointer) inline
- //'>>' RemoveLooped inline
  destructor Destroy default
 ;
 
@@ -91,8 +88,7 @@
 
 exp stLinkedlist.SetPos(aNew: int, aVal: pointer)
 =
- //currently not yet supported in LinkedList
- raise('SetPos not yet suppported in LinkedList')
+ raise('SetPos not yet suppported in LinkedList') //currently not yet supported in LinkedList
 ;
 
 exp stLinkedList.DoLoop
@@ -130,9 +126,7 @@
 
 exp stLinkedList.CopyLData(aSize: dword): pointer
 =
- //check if there is already a first, if not, set up the first,
- //otherwise, add to back
- [<-FirstItem == nil->
+ [<-FirstItem == nil-> //check if there is already a first, if not, set up the first, otherwise, add to back
       FirstItem = Memory.Malloc(aSize)
       FirstItem.NextItem = nil
       FirstItem.PrevItem = nil
@@ -153,25 +147,22 @@
 
 exp stLinkedList.RemoveD​ataByRef(aVal: pointer)
 =
- //check if there is anything to destroy
- [<-aVal <> nil->
- //check if it is the first item or the last (or both)
- [<-aVal == FirstItem-> FirstItem = FirstItem.NextItem ]
+ [<-aVal <> nil-> //check if there is anything to destroy
+ [<-aVal == FirstItem-> FirstItem = FirstItem.NextItem ] //check if it is the first item or the last (or both)
       [<-aVal == LastItem-> LastItem = LastItem.PrevItem ]
       //if there is a PrevItem and/or NextItem in aVal, link them together so the item is
       //completly isolated
       [<-sLinkedListIte​m^(aVal).NextItem <> nil-> sLinkedListItem^(aVa​l).NextItem.PrevItem​ = sLinkedListItem^(aVa​l).PrevItem]
       [<-sLinkedListIte​m^(aVal).PrevItem <> nil-> sLinkedListItem^(aVa​l).PrevItem.NextItem​ = sLinkedListItem^(aVa​l).NextItem]
- //and delete the item
- Memory.Free(aVal)
+ Memory.Free(aVal) //and delete the item
       RecCount -= 1
    ]
 ;
 
-exp stLinkedList.Destroy =
- //delete all the items
+exp stLinkedList.Destroy
+=
    iItem: sLinkedListItem^
- {<-FirstItem <> nil->
+ {<-FirstItem <> nil-> //delete all the items
       iItem = FirstItem.NextItem
       Memory.Free(FirstItem)
       FirstItem = iItem
@@ -181,15 +172,13 @@
 exp stLinkedList.SetFirst(aValue: pointer)
 =
    [<-aValue <> nil && aValue <> FirstItem->
- //first close the gap that avalue creates
- [<-sLinkedListIte​m^(aValue).NextITem <> nil->
+ [<-sLinkedListIte​m^(aValue).NextITem <> nil-> //first close the gap that avalue creates
           sLinkedListItem^(aVa​lue).NextItem.PrevIt​em = sLinkedListItem^(aVa​lue).PrevItem
        ]
        [<-sLinkedListIte​m^(aValue).PrevItem <> nil->
           sLinkedListItem^(aVa​lue).PrevItem.NextIt​em = sLinkedListItem^(aVa​lue).NextItem
        ]
- //check if there is a first, if so, set prev of first to new + new.next to first
- sLinkedListItem^(aVa​lue).NextItem = FirstItem
+ sLinkedListItem^(aVa​lue).NextItem = FirstItem //check if there is a first, if so, set prev of first to new + new.next to first
       sLinkedListItem^(aVa​lue).PrevItem = nil
       [<-FirstItem <> nil->
          FirstItem.PrevItem = sLinkedListItem^(aValue)
@@ -201,15 +190,13 @@
 exp stLinkedList.SetLast(avalue: pointer)
 =
    [<-aValue <> nil && aValue <> LastItem->
- //first close the gap that avalue creates
- [<-sLinkedListIte​m^(aValue).NextITem <> nil->
+ [<-sLinkedListIte​m^(aValue).NextITem <> nil-> //first close the gap that avalue creates
           sLinkedListItem^(aVa​lue).NextItem.PrevIt​em = sLinkedListItem^(aVa​lue).PrevItem
        ]
        [<-sLinkedListIte​m^(aValue).PrevItem <> nil->
           sLinkedListItem^(aVa​lue).PrevItem.NextIt​em = sLinkedListItem^(aVa​lue).NextItem
        ]
- //check if there is a first, if so, set prev of first to new + new.next to first
- sLinkedListItem^(aVa​lue).NextItem = nil
+ sLinkedListItem^(aVa​lue).NextItem = nil //check if there is a first, if so, set prev of first to new + new.next to first
       sLinkedListItem^(aVa​lue).PrevItem = LastItem
       [<-LastItem <> nil->
          LastItem.PrevItem = sLinkedListItem^(aValue)
@@ -226,31 +213,23 @@
 
 exp stLinkedList.SetNext(aItem: pointer, aNew: pointer)
 =
- //first check if there is a new, otherwise, skip
- [<-aNew <> nil->
- //if aNew == aItem, handle simpler: move the item to the next one
- //otherwise, first remove aNew, then insert into the next pos of aItem
- [<-aItem <> aNew->
+ [<-aNew <> nil-> //first check if there is a new, otherwise, skip
+ [<-aItem <> aNew-> //if aNew == aItem, handle simpler: move the item to the next one otherwise, first remove aNew, then insert into the next pos of aItem
          sLinkedListItem^(aNe​w).PrevItem.NextItem​ = sLinkedListItem^(aNew).NextItem
          sLinkedListItem^(aNe​w).NextItem.PrevItem​ = sLinkedListItem^(aNew).PrevItem
          sLinkedListItem^(aNew).NextItem = sLinkedListItem^(aIt​em).NextItem
          sLinkedListItem^(aNew).PrevItem = sLinkedListItem^(aItem)
          sLinkedListItem^(aIt​em).NextItem.PrevIte​m = sLinkedListItem^(aNew)
          sLinkedListItem^(aIt​em).NextItem = sLinkedListItem^(aNew)
- <-->
- //can only do this if this is not the last item
- [<-aItem <> LastItem-> SwitchWithNext(sLink​edListItem^(aItem))
- ]
+ <-aItem <> LastItem-> //can only do this if this is not the last item
+ SwitchWithNext(sLink​edListItem^(aItem))
       ]
    ]
 ;
 
 exp stLinkedList.SetPrev(aItem: pointer, aNew: pointer)
 =
- //first check if there is a new, otherwise, skip
- [<-aNew <> nil->
- //if aNew == aItem, handle simpler: move the item to the next one
- //otherwise, first remove aNew, then insert into the next pos of aItem
+ [<-aNew <> nil-> //first check if there is a new, otherwise, skip
       [<-aItem <> aNew->
          sLinkedListItem^(aNe​w).PrevItem.NextItem​ = sLinkedListItem^(aNew).NextItem
          sLinkedListItem^(aNe​w).NextItem.PrevItem​ = sLinkedListItem^(aNew).PrevItem
@@ -258,9 +237,8 @@
          sLinkedListItem^(aNew).PrevItem = sLinkedListItem^(aItem)
          sLinkedListItem^(aIt​em).PrevItem.NextIte​m = sLinkedListItem^(aNew)
          sLinkedListItem^(aIt​em).PrevItem = sLinkedListItem^(aNew)
- <-->
- //can only do this if this is not the first item
- [<-aItem <> FirstItem-> SwitchWithNext(sLink​edListItem^(aItem).P​revItem)]
+ <-aItem <> FirstItem->
+ SwitchWithNext(sLink​edListItem^(aItem).P​revItem)
       ]
    ]
 ;
@@ -312,10 +290,9 @@
    }
 ;
 
-exp stStack.CopyLData(aSize: dword): pointer =
- //check if there is already a first, if not, set up the first,
- //otherwise, add to back
- [<-LastItem == nil->
+exp stStack.CopyLData(aSize: dword): pointer
+=
+ [<-LastItem == nil-> //check if there is already a first, if not, set up the first, otherwise, add to back
       LastItem = sStackItem^(Memory.M​alloc(aSize))
       LastItem.PrevItem = nil
       RecCount += 1
@@ -330,40 +307,38 @@
    ]
 ;
 
-exp stStack.RemoveDataByRef(aVal: pointer, aSize: int) =
- //check if there is anything to destroy
- [<-aVal <> nil->
- //check if it is the first item or the last (or both)
- [<-aVal == LastItem-> LastItem = LastItem.PrevItem
+exp stStack.RemoveDataByRef(aVal: pointer, aSize: int)
+=
+ [<-aVal <> nil-> //check if there is anything to destroy
+ [<-aVal == LastItem-> LastItem = LastItem.PrevItem //check if it is the first item or the last (or both)
        <-->
- //find the item just before the aVal, set its PrevItem to that of the item being destroyed
          iTemp: sStackItem^
          iPrev: sStackItem^
          iPrev = nil
          iTemp = LastItem
- {<-iTemp <> aVal->
+ {<-iTemp <> aVal-> //find the item just before the aVal, set its PrevItem to that of the item being destroyed
             iPrev = iTemp
             iTemp = iTemp.PrevItem
          }
          iPrev.PrevItem = iTemp.PrevItem
       ]
- //and delete the item
- Memory.Free(aVal)
+ Memory.Free(aVal) //and delete the item
       RecCount -= 1
    ]
 ;
 
-exp stStack.Destroy =
- //delete all the items
+exp stStack.Destroy
+=
    iTemp: sStackItem^
- {<-LastItem <> nil->
+ {<-LastItem <> nil-> //delete all the items
       iTemp = LastItem.PrevItem
       Memory.Free(LastItem)
       LastItem = iTemp
    }
 ;
 
-exp stStack.GetFirst: pointer =
+exp stStack.GetFirst: pointer
+=
    [<-lastItem <> nil->
       iTemp: sStackItem^
       iTemp = LastItem
@@ -426,7 +401,8 @@
    ]
 ;
 
-exp stStack.GetNext(aItem: pointer): pointer =
+exp stStack.GetNext(aItem: pointer): pointer
+=
    [<-aItem <> nil->
       iTemp: sStackItem^
       iPrev: sStackItem^
@@ -582,6 +558,7 @@
    pos @ GetAtPos(aIndex: int, aSize: int): pointer inline
        read GetPos(aVal: pointer, aSize: int): int inline
    exp AddBlock(aData: pointer, aSize: dword, aElSize: dword) //this will add a data block to ours, it knows how much because of the /0 at the end which is for what it checks
+ Duplicate(aSize: dword): pointer
        MakeUnique(aSize: dword) inline
    operator
       '=' AssignSelf(aVal: stZeroEndArray&): stZeroEndArray&
@@ -627,6 +604,19 @@
    ]
 ;
 
+exp stZeroEndArray.Duplicate(aSize: dword): pointer
+=
+ iRes: pointer
+ [<-SpaceData <> nil->
+ [<-SpaceData.Data <> nil->
+ iRes = Memory.Malloc((space​Data.RecCount + 1) * aSize)
+ memory.memcpy(iRes, SpaceData.Data, (spaceData.RecCount + 1) * aSize)
+ ]
+ <-->
+ iRes = nil
+ ]
+;
+
 exp stZeroEndArray.SetNr​Records(aValue: int, aSize: int)
 =
    //make certain that we are unique (which also makes the SpaceData object)

Modified: trunk/Controls.gen
Url: http://genelib.tigri​s.org/source/browse/​genelib/trunk/Contro​ls.gen?view=diff​&rev=33&p1=trunk​/Controls.gen&r1​=32&p2=trunk/Con​trols.gen&r2=33
====================​====================​====================​==================
--- trunk/Controls.gen (original)
+++ trunk/Controls.gen Fri Mar 24 03:14:32 2006
@@ -1315,7 +1315,9 @@
 space sListBox;
 
 space sListBoxItem =
- var Text: string
+ var fText: string //this will store the text if there is no Listbox
+ Position: int = -1 //the index of the listbox Item as returned when it was created, don't change
+ prop Text: string read exp GetString: string write exp SetString(aValue: string&) //access the content of the listbox item
  constructor Create virtual = ;
  destructor Destroy virtual = ;
 ;
@@ -1336,12 +1338,14 @@
  BorderStyle 7
  AdditionalStyles LBS_Notify
  exp Sort
- prop ItemIndex: int read exp GetItemIndex: int write exp SetItemIndex(aValue: int) //which item is selected
- Items: sListBoxItems read var fItems: sListBoxItems.Create(self) //the list of items
- TopIndex: int read exp GetTopIndex: int write exp SetTopIndex(aValue: int) //Specifies the index number of the item that appears at the top of the list box.
- AutoRedraw: bool read exp GetAutoRedraw: bool write exp SetAutoRedraw(aValue: bool) //specifies if listbox is automatically redrawn when item is added or not
- Sorted: bool read var fSorted: bool write exp SetSorted(aValue: bool)
- exp select(aStart: string) //selects the first item that begins with the given string
+ prop ItemIndex: int read exp GetItemIndex: int write exp SetItemIndex(aValue: int) //which item is selected
+ Items: sListBoxItems read var fItems: sListBoxItems.Create(self) //the list of items
+ TopIndex: int read exp GetTopIndex: int write exp SetTopIndex(aValue: int) //Specifies the index number of the item that appears at the top of the list box.
+ AutoRedraw: bool read exp GetAutoRedraw: bool write exp SetAutoRedraw(aValue: bool) //specifies if listbox is automatically redrawn when item is added or not
+ Sorted: bool read var fSorted: bool = false write exp SetSorted(aValue: bool) //sorted or not, recreates the listbox
+ MultiSelect: bool read var fMultiSelect: bool = false write exp SetMultiSelect(aVal: bool)//determins if multiselect or not, when changed, the object gets recreated, best set in construction list
+ MultiColumn: bool read var fMultiColumn: bool = false write exp SetmultiColumn(aVal: bool)//does it have multiple columns or not, when changed, the object gets recreated, best set in construction list
+ exp select(aStart: string) //selects the first item that begins with the given string
 ;
 
 
@@ -1352,7 +1356,10 @@
       [<-Owner.Sorted == true->
          raise(Exception.Crea​te('ListBox: sorted add not yet implemented'))
        <-->
- //send a message to the parent window
+ aItem.Position = User32.SendMessage(T​oolBar.Handle, dword(LB_ADDSTRING), 0, int(aItem.fText.c_str))
+ [<-aItem.Position == LB_ERR->
+ raise(Exception.Create('Unable to add to the list'))
+ ]
       ]
    ]
 ;

Modified: trunk/string.gen
Url: http://genelib.tigri​s.org/source/browse/​genelib/trunk/string​.gen?view=diff&r​ev=33&p1=trunk/s​tring.gen&r1=32​&p2=trunk/string.​gen&r2=33
====================​====================​====================​==================
--- trunk/string.gen (original)
+++ trunk/string.gen Fri Mar 24 03:14:32 2006
@@ -158,12 +158,22 @@
 
 exp sAnsiString.ReleaseString: char^
 =
+ iRes: char^
+
    [<-store.SpaceData <> nil->
- store.SpaceData.RefCount += 1
- return(store.SpaceData.Data)
+ iRes = C_str
+ [<-store.SpaceData.RefCount == 1->
+ store.SpaceData.Data = nil //this will detach it, but still allows the SpaceData object to be deleted
+ store.SpaceData.Destroy //the data is released, so don't store it anymore
+ <-->
+ store.SpaceData.Data = store.duplicate(sizeof(char)) //we give the string new data so we can release the previous one
+ store.SpaceData.RefCount -= 1 //we detach ourselves
+ store.spacedata = nil
+ ]
     <-->
- return(nil)
+ iRes = nil
    ]
+ return(iRes)
 ;
 
 exp sAnsiString.StrLen(aStr: char^): dword

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r33 - trunk lotec Jan Bogaerts 2006-03-24 03:14:32 PST
Messages per page: