Oberon Community Platform Forum
October 14, 2019, 06:22:50 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: PropertyHelper  (Read 5112 times)
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« on: April 22, 2008, 11:05:22 AM »

When porting the source code from Delphi, a lot of time spent on the addition Get() and Set() to property.
This can be done more easily if the overload operators:

Code:
MODULE PropertyHelper;
IMPORT WMProperties,AosOut;
PROCEDURE ":="*( VAR l: WMProperties.Int32Property;r:LONGINT ); 
BEGIN
l.Set(r);
END ":="; 
PROCEDURE ":="*( VAR l:LONGINT; VAR r: WMProperties.Int32Property); 
BEGIN
l:=r.Get();
END ":="; 
PROCEDURE "="*(l:LONGINT; CONST r: WMProperties.Int32Property):BOOLEAN; 
BEGIN
RETURN l=r.Get();
END "="; 
PROCEDURE "="*(CONST l: WMProperties.Int32Property; r:LONGINT; ):BOOLEAN; 
BEGIN
RETURN l.Get()=r;
END "="; 
PROCEDURE ">"*(CONST l: WMProperties.Int32Property; r:LONGINT; ):BOOLEAN; 
BEGIN
RETURN l.Get()>r;
END ">"; 
PROCEDURE "<"*(CONST l: WMProperties.Int32Property; r:LONGINT; ):BOOLEAN; 
BEGIN
RETURN l.Get()<r;
END "<"; 
PROCEDURE "<="*(CONST l: WMProperties.Int32Property;r:LONGINT; ):BOOLEAN; 
BEGIN
RETURN l.Get()<=r;
END "<="; 
PROCEDURE ">="*(CONST l: WMProperties.Int32Property; r:LONGINT; ):BOOLEAN; 
BEGIN
RETURN l.Get()>=r;
END ">="; 

PROCEDURE "#"*(CONST l: WMProperties.Int32Property; r:LONGINT; ):BOOLEAN; 
BEGIN
RETURN l.Get()#r;
END "#"; 

PROCEDURE "+"*(CONST l: WMProperties.Int32Property; r:LONGINT; ):LONGINT; 
BEGIN
RETURN l.Get()+r;
END "+"; 
PROCEDURE "+"*(CONST l: WMProperties.Int32Property; r:REAL; ):REAL; 
BEGIN
RETURN l.Get()+r;
END "+"; 

PROCEDURE "-"*(CONST r: WMProperties.Int32Property; l:LONGINT; ):LONGINT; 
BEGIN
RETURN l-r.Get();
END "-"; 
PROCEDURE "-"*(CONST r: WMProperties.Int32Property; l:REAL; ):REAL; 
BEGIN
RETURN l-r.Get();
END "-"; 

PROCEDURE "*"*(CONST r: WMProperties.Int32Property; l:LONGINT; ):LONGINT; 
BEGIN
RETURN l*r.Get();
END "*"; 

PROCEDURE "*"*(CONST r: WMProperties.Int32Property; l:REAL; ):REAL; 
BEGIN
RETURN l*r.Get();
END "*"; 

PROCEDURE "DIV"*(CONST l: WMProperties.Int32Property; r:LONGINT; ):LONGINT; 
BEGIN
RETURN  l.Get() DIV r;
END "DIV"; 
PROCEDURE "DIV"*( l:LONGINT;CONST r: WMProperties.Int32Property; ):LONGINT; 
BEGIN
RETURN l DIV r.Get();
END "DIV"; 
PROCEDURE "/"*(CONST l: WMProperties.Int32Property; r:REAL; ):REAL; 
BEGIN
RETURN l.Get()/r;
END "/"; 
PROCEDURE "/"*(CONST l:REAL;r: WMProperties.Int32Property ):REAL; 
BEGIN
RETURN l/r.Get();
END "/"; 
PROCEDURE "\"*(CONST l:LONGINT;r: WMProperties.Int32Property ):LONGINT; 
BEGIN
RETURN l DIV r.Get();
END "\"; 
PROCEDURE "\"*(CONST l: WMProperties.Int32Property;r:LONGINT ):LONGINT; 
BEGIN
RETURN l.Get() DIV r;
END "\"; 
END PropertyHelper.
Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #1 on: April 23, 2008, 11:51:36 AM »

Code:
PROCEDURE "+"*(CONST l,r: Utilities.String ):Utilities.String; 
VAR
s:Utilities.String;
BEGIN
NEW(s, Utilities.Length(l^) + Utilities.Length(r^) + 1);
Utilities.Concat(l^, r^, s^);
RETURN s;
END "+"; 

PROCEDURE "+"*(CONST l: Utilities.String;r:ARRAY OF CHAR):Utilities.String; 
VAR s:Utilities.String;
BEGIN
NEW(s, Utilities.Length(l^) + Utilities.Length(r) + 1);
Utilities.Concat(l^, r, s^);
RETURN s;
END "+"; 

PROCEDURE "+"*(CONST l, r:ARRAY OF CHAR):Utilities.String; 
VAR
s:Utilities.String;
BEGIN
NEW(s, Utilities.Length(l) + Utilities.Length(r) + 1);
Utilities.Concat(l, r, s^);
RETURN s;
END "+";
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!