Commit c8c1df20 authored by Rinus Plasmeijer's avatar Rinus Plasmeijer
Browse files

Made macro such that GERDA can optionally be switched off

parent 18dddf59
......@@ -15,7 +15,7 @@ import Gerda
:: *NWorld // io interface
= { worldC :: !*World // world for any io
, inout :: !*HtmlStream // to read from stdin and write to stdout
, gerda :: !*Gerda // to read and write to the database
, gerda :: *Gerda // to read and write to the database
}
instance FileSystem NWorld
appWorldNWorld :: !.(*World -> *World) !*NWorld -> *NWorld
......
......@@ -3,6 +3,7 @@ implementation module PrintUtil
import StdEnv, ArgEnv
import StdGeneric
import StdStrictLists
import Gerda
:: Url :== String
......
......@@ -26,6 +26,14 @@ gPrint{|(->)|} gArg gRes _ _ = abort "functions can only be used with dynamic s
:: FormUpdate :== (InputId,UpdValue) // info obtained when form is updated
// OPTIONS
openGerda` database world
:== IF_GERDA (openGerda database world) (abort "Trying to open database while options is switched off",world)
closeGerda` gerda world
:== IF_GERDA (closeGerda gerda world) world
// top level function given to end user
// it collects all the html forms to display, adds clean styles and hidden forms, ands prints the html code to stdout
// assumes that the application is used by a server
......@@ -33,7 +41,7 @@ gPrint{|(->)|} gArg gRes _ _ = abort "functions can only be used with dynamic s
doHtml :: .(*HSt -> (Html,!*HSt)) *World -> *World
doHtml userpage world
# inout = [|]
# (gerda,world) = openGerda MyDataBase world
# (gerda,world) = openGerda` MyDataBase world
# nworld = { worldC = world, inout = inout, gerda = gerda}
# (initforms,nworld) = retrieveFormStates External Nothing nworld
# (Html (Head headattr headtags) (Body attr bodytags),{states,world})
......@@ -43,7 +51,7 @@ doHtml userpage world
(Html (Head headattr [extra_style:headtags])
(Body (extra_body_attr ++ attr) [debugInput,allformbodies:bodytags]))
world
# worldC = closeGerda gerda worldC
# worldC = closeGerda` gerda worldC
= worldC
where
stuf = "Hello world"
......@@ -68,7 +76,7 @@ where
doHtmlServer2 :: String .(*HSt -> (Html,!*HSt)) *World -> ([String],String,*World)
doHtmlServer2 args userpage world
# temp = [|]
# (gerda,world) = openGerda MyDataBase world
# (gerda,world) = openGerda` MyDataBase world
# nworld = { worldC = world, inout = temp, gerda = gerda }
# (initforms,nworld) = retrieveFormStates Internal (Just args) nworld
# (Html (Head headattr headtags) (Body attr bodytags),{states,world})
......@@ -79,7 +87,7 @@ where
(Body (extra_body_attr ++ attr) [debugInput,allformbodies:bodytags]))
world
# world = worldC
# world = closeGerda gerda world
# world = closeGerda` gerda world
# reversed_strings = inout
# n_chars = count_chars reversed_strings 0
with
......@@ -109,7 +117,6 @@ where
// swiss army nife editor that makes coffee too ...
mkViewForm :: !(InIDataId d) !(HBimap d v) !*HSt -> (Form d,!*HSt) | iData v
//mkViewForm :: !(InIDataId d) !(HBimap d v) !*HSt -> (Form d,!*HSt) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, gerda{|*|}, TC v
mkViewForm (init,formid) bm=:{toForm, updForm, fromForm, resetForm} hst=:{states,world}
| init == Const && formid.lifespan <> Temp
= mkViewForm (init,{formid & lifespan = Temp}) bm hst // constant i-data are never stored
......
......@@ -7,15 +7,27 @@ import htmlHandler
class iData a // The collection of generic functions needed to make iData:
| gForm {|*|} // Creates an Html Form
, gUpd {|*|} // Makes it possible to edit the form and updates the corresponding value
, gPrint{|*|} // To serialize a form to a String
, gParse{|*|} // To de-serialize the string back to a value
, gerda {|*|} // To store and retrieve a value in a database
, iDataSerAndDeSerialize a
class iDataSerialize a
| gPrint{|*|} // To serialize a value to a String
// , gerda {|*|} // OPTION: To store and retrieve a value in a database
, TC a // To be able to store values in a dynamic
// TC is a special class cannot be included here
class iDataSerAndDeSerialize a
| gParse{|*|} // To de-serialize a string back to a value
, iDataSerialize a
TraceInput :== False // set it to True if you want to see what kind of information is stored
MyDataBase :== "iDataDatabase" // name of database being used by iData applications
iDataIdSeparator :== "." // used as separator when combining iData form id's
radioButtonSeparator :== '.' // used as extension for family of radiobuttons
\ No newline at end of file
iDataIdSeparator :== "." // used as separator when combining iData form id's
radioButtonSeparator :== '.' // used as extension for family of radiobuttons
// OPTIONS WHICH CAN BE SET OFF AND ON
//IF_GERDA gerda no_gerda :== gerda // If Gerda option is chosen
IF_GERDA gerda no_gerda :== no_gerda // otherwise, BUT manually flag of ", gerda{|*|}" in the class definition above
......@@ -15,9 +15,9 @@ emptyFormStates :: *FormStates // creates emtpy states
findState :: !(FormId a) *FormStates *NWorld // find the state value given FormId and a correct type
-> (Bool, Maybe a,*FormStates,*NWorld) // true if form has not yet been previously inspected
| gPrint {|*|}, gParse{|*|}, gerda{|*|}, TC a
| iDataSerAndDeSerialize a
replaceState :: !(FormId a) a *FormStates *NWorld // replace state given FormId
-> (*FormStates,*NWorld) | gPrint{|*|}, gerda{|*|}, TC a
-> (*FormStates,*NWorld) | iDataSerialize a
getUpdateId :: *FormStates -> (String,*FormStates) // id of previously changed form
getUpdate :: *FormStates -> (String,*FormStates) // value typed in by user as string
......
......@@ -41,6 +41,17 @@ derive gPrint UpdValue, (,,)
| StatDyn !Dynamic // Or a dynamic which enables serialization of functions defined in the application (no plug ins yet)
| DBStr !.String (*Gerda -> *Gerda) // In case a new value has to bestored in the database
// Options
readGerda` id gerda
:== IF_GERDA (readGerda id gerda)
(abort "Reading Database, yet option is swiched off\n",
abort "Reading Database, yet option is swiched off\n")
writeGerda` id val
:== IF_GERDA (writeGerda id val)
(\_ -> abort "Writing Database, yet option is swiched off\n")
// functions defined on the FormStates abstract data type
instance < FormState
......@@ -61,12 +72,12 @@ getUpdateId formStates=:{updateid} = (updateid,formStates)
getUpdate :: *FormStates -> (String,*FormStates)
getUpdate formStates=:{update} = (update,formStates)
findState :: !(FormId a) *FormStates *NWorld -> (Bool,Maybe a,*FormStates,*NWorld) | gPrint {|*|}, gParse{|*|}, gerda{|*|}, TC a
findState :: !(FormId a) *FormStates *NWorld -> (Bool,Maybe a,*FormStates,*NWorld) | iDataSerAndDeSerialize a
findState formid formstates=:{fstates,server} world
# (bool,ma,fstates,world) = findState` formid fstates world
= (bool,ma,{formstates & fstates = fstates},world)
where
findState` :: !(FormId a) *FStates *NWorld -> (Bool,Maybe a,*FStates,*NWorld)| gPrint {|*|}, gParse{|*|}, gerda{|*|}, TC a
findState` :: !(FormId a) *FStates *NWorld -> (Bool,Maybe a,*FStates,*NWorld)| iDataSerAndDeSerialize a
findState` formid formstate=:(Node_ left (fid,info) right) world
| formid.id == fid = case info of
(OldState state) = (True, fetchFState state,formstate,world)
......@@ -89,7 +100,7 @@ where
// read out database and store as string
findState` {id,lifespan = Database,storage = PlainString} Leaf_ world=:{gerda}
# (value,gerda) = readGerda id gerda
# (value,gerda) = readGerda` id gerda
# world = {world & gerda = gerda}
= case value of
Just a -> (True,Just a,Node_ Leaf_ (id,OldState {format = PlainStr (printToString a), life = Database}) Leaf_,world)
......@@ -98,7 +109,7 @@ where
// read out database and store as dynamic
findState` {id,lifespan = Database,storage = StaticDynamic} Leaf_ world=:{gerda}
# (value,gerda) = readGerda id gerda
# (value,gerda) = readGerda` id gerda
# world = {world & gerda = gerda}
= case value of
Nothing = (False,Nothing,Leaf_,world)
......@@ -146,12 +157,12 @@ where
string_to_dynamic` :: {#Char} -> Dynamic // just to make a unique copy as requested by string_to_dynamic
string_to_dynamic` s = string_to_dynamic {s` \\ s` <-: s}
replaceState :: !(FormId a) a *FormStates *NWorld -> (*FormStates,*NWorld) | gPrint{|*|}, gerda{|*|}, TC a
replaceState :: !(FormId a) a *FormStates *NWorld -> (*FormStates,*NWorld) | iDataSerialize a
replaceState formid val formstates=:{fstates} world
# (fstates,world) = replaceState` formid val fstates world
= ({formstates & fstates = fstates},world)
where
replaceState` :: !(FormId a) a *FStates *NWorld -> (*FStates,*NWorld) | gPrint{|*|}, gerda{|*|}, TC a
replaceState` :: !(FormId a) a *FStates *NWorld -> (*FStates,*NWorld) | iDataSerialize a
replaceState` formid val Leaf_ world // id not part of tree yet
= (Node_ Leaf_ (formid.id,NewState (initNewState formid.id (adjustlife formid.lifespan) Temp formid.storage val)) Leaf_,world)
replaceState` formid val (Node_ left a=:(fid,fstate) right) world
......@@ -165,8 +176,8 @@ where
// NewState Handling routines
initNewState :: !String !Lifespan !Lifespan !StorageFormat !a -> FState | gPrint{|*|}, gerda{|*|}, TC a
initNewState id Database olifespan PlainString nv = {format = DBStr (printToString nv) (writeGerda id nv), life = order Database olifespan}
initNewState :: !String !Lifespan !Lifespan !StorageFormat !a -> FState | iDataSerialize a
initNewState id Database olifespan PlainString nv = {format = DBStr (printToString nv) (writeGerda` id nv), life = order Database olifespan}
initNewState id lifespan olifespan PlainString nv = {format = PlainStr (printToString nv), life = order lifespan olifespan}
initNewState id lifespan olifespan StaticDynamic nv = {format = StatDyn (dynamic nv), life = order lifespan olifespan}// convert the hidden state information stored in the html page
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment