GenRecord.dcl 2.1 KB
Newer Older
1 2 3 4 5 6 7
definition module GenRecord
/**
* This module provides functions for generically copying record fields of similar record.
* An example is a record representing the data model and a similar one representing the view.
* All fields with the same name & type can be copied automatically, only different fields have to be mapped manually.
*/

8
import SystemTypes, GenUpdate
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

/**
* Copies all fields with same name & type from one record to another.
*
* @param The source record
* @param The destrination record
* @return The resulting record
*/
copyRecord :: !a !b -> b | GenRecord a & GenRecord b

/**
* Maps a record to another type.
* All fields with same name & type keep their value, for others default values are filled in.
*
* @param The record to be mapped
* @return The resulting record of another type
*/
26
mapRecord :: !a -> b | GenRecord a & GenRecord, gUpdate{|*|} b
27 28 29

class GenRecord r
	| gGetRecordFields{|*|}
30
	, gPutRecordFields{|*|} r
31 32 33 34 35 36
	
generic gGetRecordFields r :: !r ![GenType] !*RecordFields -> *RecordFields
generic gPutRecordFields r :: !r ![GenType] !*RecordFields -> (!r,!*RecordFields)

:: *RecordFields

37
derive gGetRecordFields UNIT, PAIR, EITHER, CONS, OBJECT, RECORD, FIELD
38 39
derive gGetRecordFields Int, Real, Char, Bool, String
derive gGetRecordFields Dynamic, [], Maybe, Either, (,), (,,), (,,,), (->), Void, Display, Editable, Hidden, VisualizationHint, Timestamp
40
derive gGetRecordFields Note, Password, Date, Time, DateTime, Document, FormButton, EUR, USD, User, RadioChoice, CheckMultiChoice, Map, TreeChoice, Tree, TreeNode, HtmlTag, HtmlAttr
41
derive gGetRecordFields EmailAddress, Action
42

43
derive gPutRecordFields UNIT, PAIR, EITHER, CONS, OBJECT, RECORD, FIELD
44 45
derive gPutRecordFields Int, Real, Char, Bool, String
derive gPutRecordFields Dynamic, [], Maybe, Either, (,), (,,), (,,,), (->), Void, Display, Editable, Hidden, VisualizationHint, Timestamp
46
derive gPutRecordFields Note, Password, Date, Time, DateTime, Document, FormButton, EUR, USD, User, RadioChoice, CheckMultiChoice, Map, TreeChoice, Tree, TreeNode, HtmlTag, HtmlAttr
47
derive gPutRecordFields EmailAddress, Action