Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r28 - trunk

genelib
Discussion topic

Back to topic list

svn commit: r28 - trunk

Author lotec
Full name Jan Bogaerts
Date 2006-03-21 10:22:16 PST
Message Author: lotec
Date: Tue Mar 21 10:22:15 2006
New Revision: 28

Added:
   trunk/Future.txt
   trunk/Search.gen
Modified:
   trunk/WUser32.gen
Log:


Added: trunk/Future.txt
Url: http://genelib.tigri​s.org/source/browse/​genelib/trunk/Future​.txt?view=auto&r​ev=28
====================​====================​====================​==================
--- (empty file)
+++ trunk/Future.txt Tue Mar 21 10:22:15 2006
@@ -0,0 +1,15 @@
+Ver 0.6
+-------
+-Prelude to integration with GCC
+-remove Store keyword and replace store type with spaces.
+-prev, next, first, last,.... -> will become properties
+-Implement namespaces + a more unit oriented style of compiling (important for RTL?)
+-Single compile -> no longer allowed to have multiple processes or libs in the project unit.
+-OS will be interpreted global var set up by the units that generate the main function
+-Platform will be interpreted global const (set up by the compiler) the compiler receives gcc type param to indicate this info)
+-Update the RTTI engine for libs (meta objects register themselves with the RTL at startup and get a reference to their type structure)
+-Update the RTTI engine so that it can dynamically create objects based on the type name (initial values rendering must change)
+-More code rendering needs to be moved from the C renderer to the parser (constructor default values,...)
+-all structs and spaces inherit from a base type struct and space -> all receive a constructor create, createByType and destructor destroy
+-Include system -> at the very least allow public includes -> if unit a include d and c, than if unit d includes a, it will also include b and c
+ this is done by adding an extra list in sUnit-> public includes, the dictionary will also search in these dicts.
\ No newline at end of file

Added: trunk/Search.gen
Url: http://genelib.tigri​s.org/source/browse/​genelib/trunk/Search​.gen?view=auto&r​ev=28
====================​====================​====================​==================
--- (empty file)
+++ trunk/Search.gen Tue Mar 21 10:22:15 2006
@@ -0,0 +1,163 @@
+//copyright LoTeC (Jan Bogaerts) 2006
+
+//This unit is part of the Gene standarad library
+
+//This program is free software; you can redistribute it and/or modify
+//it under the terms of the Lesser GNU General Public License as published by
+//the Free Software Foundation; either version 2.1 of the License, or
+//(at your option) any later version.
+
+//This program is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//Lesser GNU General Public License for more details.
+
+//You should have received a copy of the Lesser GNU General Public License
+//along with this program; if not, write to the Free Software
+//Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+/*
+string Search algorithm
+-----------------------
+-should work on chars and words (so use TCHAR)
+-should work with a stream object (so read an element from the stream and reposition it using stream pos) -> this way we can have memory stream, string stream, streams on complex objects,...
+-uses the Boyer-Moore algorithm
+-should be able to go left or right
+-should be able to continue after it has done 1 complete circel or indicate that the end of the search is reached
+
+*/
+
+
+include wUser32, stdio, string, memory;
+
+space sSearchData = //implement this space if you want to create a custom data source for the search algorithm
+ prop Position: int read exp GetPosition: int abstract write exp SetPosition(aValue: int) abstract //to retrieve or set the current position in the data
+ exp Value: TCHAR abstract //return the current value
+ IsEOF: bool abstract //return true if no more data
+ SetStart abstract //lets the data know we are beginning to compare a new part, this allows the data implementor to set a start point
+ GetSelection: pointer abstract //returns information needed by the data source to identify the section of text between the last call to setStart and the current position
+;
+
+space sStringSearchData(sSearchData) = //implementation of sSearchData for data comming from a string
+ var Data: string
+ CurPos: int = 0
+ StartPos: int = 0
+ exp GetPosition: int override = return(CurPos);
+ SetPosition(aValue: int) override = CurPos = aValue;
+ Value: TCHAR override = return(Data@(CurPos).entity);
+ IsEOF: bool override = return(CurPos < 0 || CurPos >= Data.NrRecords);
+ SetStart override = StartPos = CurPos;
+ GetSelection: pointer override = return(Point.Create(\x = CurPos, y = StartPos)); //we need to inverse, cause the start was actually set at the end of the selection
+ constructor create = ;
+ destructor Destroy = ;
+;
+
+
+space sStringSearch =
+ var JumpPoints: int$
+ CaseSensitive: bool = false //do we want a case sensitive search or not
+ prop Pattern: string read var fPattern: string write exp SetPattern(aValue: string&) //the pattern to search for
+ Input: sSearchData^ read var fInput: sSearchData^ = nil write exp SetInput(aValue: sSearchData^) //the input stream to search in
+ FromLeftToRight: bool read var fFromLeftToRight: bool = true write exp SetFromLeftTorRight(aValue: bool) //the direction we need to search in
+ exp Find: pointer
+;
+
+//-----------------​--------------------​--------------------​--------------------​--------------------​-
+
+exp sStringSearch.SetPat​tern(aValue: string&)
+=
+ fPattern = aValue
+
+ //also build the JumpPoints array
+ [<-JumpPoints == nil->
+ JumpPoints = memory.malloc(sizeof(TCHAR))
+ ]
+
+ iChar: fPattern.entity
+ iChar = fPattern.last
+ [<-FromLeftToRight == true-> //according to the direction, we need to calculate the jump point differently
+ memory.MemSet(JumpPoints, sizeof(TCHAR), fPattern.NrRecords - 1)
+ {<-ichar.cursor <> nil->
+ [<-JumpPoints@(ichar.entity) == fPattern.NrRecords - 1->
+ JumpPoints@(ichar.entity) = fPattern.NrRecords - (1 + iChar.pos) //there was no previous char in the pattern that was the same as this, so store the jumppoint
+ ]
+ iChar = iChar.prev
+ }
+ <-->
+ memory.MemSet(JumpPoints, sizeof(TCHAR), -fPattern.NrRecords)
+ {<-ichar.cursor <> nil->
+ [<-JumpPoints@(ichar.entity) == -fPattern.NrRecords->
+ JumpPoints@(ichar.entity) = -1 //calculation is based on the fact that we need to have the character before the one we just read
+ ]
+ iChar = iChar.prev
+ }
+ ]
+;
+
+exp sStringSearch.SetInput(aValue: sSearchData^)
+=
+ fInput = aValue
+ //when we are searching from left to right, we need to advance the current search pos in the input with the size of the pattern (-1) so we
+ //check the last char first (see the Boyer-Moore algorithm). Offcourse, when we are checking from right to left, we are already at the correct
+ //position
+ [<-FromLeftToRight == true->
+ fInput.Position += (fPattern.nrrecords - 1)
+ ]
+;
+
+exp sStringSearch.SetFro​mLeftTorRight(aValue​: bool)
+=
+ [<-aValue <> fFromLeftToRight-> //se if we are changing the value, if so, we need to reposition the current pos in the input (see SetInput)
+ [<-fInput <> nil->
+ [<-fFromLeftToRight == true->
+ fInput.Position -= (fPattern.nrrecords - 1)
+ <-->
+ fInput.Position += (fPattern.nrrecords - 1)
+ ]
+ ]
+ SetPattern(fPattern) //we call the setPattern again so that the JumpPoints are recalculated correctly taking the direction into account
+ ]
+ fFromLeftToRight = aValue
+;
+
+
+//the actual search algorithm is an implementation of the Boyer-Moore search algorithm. This is not the fastest implementation but it does the job.
+exp sStringSearch.Find: pointer
+=
+ iChar: TChar
+ iCurPos: int //this is a temp store for the current 'start' of the pattern in the input, is used for the possible return value
+ iPatternPos: int //the position of the char in the pattern we are currently checking
+
+ iPatternPos = fPattern.nrrecords - 1
+ Input.SetStart
+ [<-CaseSensitive == true-> //check outside the loop to speed it up a bit
+ {<-fInput.IsEOF == false-> //we try for as long as we are not at the end of the data to check
+ iChar = fInput.Value //store the value in a temp for faster and cleaner code (this isn't really necessary)
+ {<-(iChar | 32) == (fPattern@(iPatternPos).entity | 32)->
+ [<-iPatternPos == 0-> return(Input.GetSelection)] //check if we are at the end of the search, if so return the value, othewise continue
+ fInput.Position -= 1 //it is a match, so continue to go back in the pattern and input
+ [<-fInput.IsEOF == true->
+ return(nil) //we have reached the end/beginning of the file but not the end of the pattern so return -1 indicating a not found
+ ]
+ iPatternPos -= 1
+ }
+ fInput.position += JumpPoints@iChar //haven't found it, so see if this character is found somewhere else in the pattern and if so, advance with that amount or advance the amount of the intire pattern (see Boyer-Moore algorithm)
+ Input.SetStart //we start comparing from a new start position, let the input source know
+ }
+ <-->
+ {<-fInput.IsEOF == false-> //we try for as long as we are not at the end of the data to check
+ iChar = fInput.Value //store the value in a temp for faster and cleaner code (this isn't really necessary)
+ {<-iChar == fPattern@(iPatternPo​s).entity->
+ [<-iPatternPos == 0-> return(Input.GetSelection)] //check if we are at the end of the search, if so return the value, othewise continue
+ fInput.Position -= 1 //it is a match, so continue to go back in the pattern and input
+ [<-fInput.IsEOF == true->
+ return(nil) //we have reached the end/beginning of the file but not the end of the pattern so return -1 indicating a not found
+ ]
+ iPatternPos -= 1
+ }
+ fInput.position += JumpPoints@iChar //haven't found it, so see if this character is found somewhere else in the pattern and if so, advance with that amount or advance the amount of the intire pattern (see Boyer-Moore algorithm)
+ Input.SetStart //we start comparing from a new start position, let the input source know
+ }
+ ]
+ return(nil) //return nil indicating a not found
+;
\ No newline at end of file

Modified: trunk/WUser32.gen
Url: http://genelib.tigri​s.org/source/browse/​genelib/trunk/WUser3​2.gen?view=diff&​rev=28&p1=trunk/​WUser32.gen&r1=2​7&p2=trunk/WUser​32.gen&r2=28
====================​====================​====================​==================
--- trunk/WUser32.gen (original)
+++ trunk/WUser32.gen Tue Mar 21 10:22:15 2006
@@ -121,6 +121,8 @@
       x = int(short(aValue & 0xffff))
       y = int(short(aValue shr 16))
      ;
+ constructor Create =;
+ destructor Destroy =;
 ;
 
 struct MSG =

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

Messages

Show all messages in topic

svn commit: r28 - trunk lotec Jan Bogaerts 2006-03-21 10:22:16 PST
Messages per page: