From 8ccc5ad5f7ce13609c1fb0c0780dfca711bc1420 Mon Sep 17 00:00:00 2001 From: totoro Date: Mon, 8 Jun 2020 11:47:18 +0900 Subject: [PATCH] add dump_Session_Field, dump_Session add get_mb_DB_id, get_List_DB_id, put_List_DB_id, replace_List_DB_id add get_List_String, put_List_String, replace_List_String --- generic/session.anubis | 261 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------- generic/types/session.anubis | 25 +++++++++++++++++++++++++ 2 files changed, 222 insertions(+), 64 deletions(-) diff --git a/generic/session.anubis b/generic/session.anubis index 8eb4157..cab3531 100644 --- a/generic/session.anubis +++ b/generic/session.anubis @@ -81,6 +81,55 @@ public define List(Session_Field_No_Var) ) . + /************************************************/ + +public define String dump_Session_Field_list(List(Session_Field) _fields, String indent). + +public define String + dump_Session_Field + ( + Session_Field _field, + String indent + )= + with name = "Name = ["+_field.field_name+"]", + if *_field.field_datum is + { + string(_string) then name+", Type = String, Value = ["+_string+"]", + bool(_bool) then name+", Type = Bool, Value = ["+to_String(_bool)+"]", + int(_int) then name+", Type = Int, Value = ["+_int+"]", + db_id(_db_id) then name+", Type = DB_id, Value = ["+_db_id+"]", + message(_message) then name+", Type = Message, Value = ["+dump(_message)+"]", + byte_array(_byte_array) then name+", Type = ByteArray", + float(_float) then name+", Type = Float, Value = ["+float_to_string(_float, 10)+"]", + word128(_word128) then name+", Type = Word128, Value = ["+to_decimal(_word128)+"]", + word64(_word64) then name+", Type = Word64, Value = ["+to_decimal(_word64)+"]", + word32(_word32) then name+", Type = Word32, Value = ["+to_decimal(_word32)+"]", + word16(_word16) then name+", Type = Word16, Value = ["+to_decimal(_word16)+"]", + word8(_word8) then name+", Type = Word8, Value = ["+to_decimal(_word8)+"]", + word4(_word4) then name+", Type = Word4, Value = ["+to_decimal(_word4)+"]", + fields_set(_fields) then name+", Type = Fields_set, \n"+dump_Session_Field_list(*_fields, indent+" "), + session(_session) then name+", Type = Session, session id = ["+_session.id+"]\n"+dump_Session_Field_list(*_session.fields, indent+" "), + } +. + +public define String + dump_Session_Field_list + ( + List(Session_Field) _fields, + String indent + )= + join("\n", map((Session_Field _field) |-> dump_Session_Field(_field, indent), _fields)) +. + +public define String + dump_Session + ( + Session _session, + String indent + )= + dump_Session_Field_list(*_session.fields, indent) +. + public define Maybe(Session_Field_Datum) get_field @@ -93,12 +142,45 @@ public define Maybe(Session_Field_Datum) { [] then failure, [h . t] then + //println("testing get_field h.field_name "+dump_Session_Field(h, "")+" looking of _field_name ["+_field_name+"] of type "+to_String(_field_type)); if h.field_name = _field_name & h.field_type = _field_type then + //println("OK"); success(*h.field_datum) else get_field(t, _field_type, _field_name) } . + + +public define List(Session_Field_Datum) + get_fields_list + ( + List(Session_Field) fields, + Session_Field_Type _field_type, + String _field_name, + List(Session_Field_Datum) so_far + ) = + if fields is + { + [] then so_far, + [h . t] then + if h.field_name = _field_name & h.field_type = _field_type then + get_fields_list(t, _field_type, _field_name, [*h.field_datum . so_far]) + else + get_fields_list(t, _field_type, _field_name, so_far) + } +. + +public define List(Session_Field_Datum) + get_fields_list + ( + List(Session_Field) fields, + Session_Field_Type _field_type, + String _field_name + ) = + get_fields_list(fields, _field_type, _field_name, []) +. + /******** ANY functions ***************/ @@ -160,20 +242,20 @@ define One Session_Field_Type _field_type, String _field_name, Session_Field_Datum _field_value - )= + )= replace_any(*fields, _field_type, _field_name, _field_value, fields) . /*************** String *****************/ - Maybe(String) get_String(fields, _field_name) + Maybe(String) get_mb_String(fields, _field_name) String get_String(fields, _field_name, default_value) public define Maybe(String) - get_String + get_mb_String ( Var(List(Session_Field)) fields, - String _field_name + String _field_name ) = if get_field(*fields, string_t, _field_name) is { @@ -193,12 +275,28 @@ public define String String _field_name, String default_value ) = - if get_String(fields, _field_name) is + if get_mb_String(fields, _field_name) is { failure then default_value success(value) then value }. +public define List(String) + get_List_String + ( + Var(List(Session_Field)) fields, + String _field_name + ) = + map_select((Session_Field_Datum datum) |-> + if datum is string(value) then + success(value) + else + failure + , + get_fields_list(*fields, string_t, _field_name) + ) +. + public define One put_String ( @@ -210,13 +308,39 @@ public define One . public define One + put_List_String + ( + Var(List(Session_Field)) fields, + String _field_name, + List(String) _field_values + )= + map_forget((String value) |-> + fields <- [session_field(_field_name, string_t, var(string(value))) . *fields] + , + _field_values + ) +. + +public define One + replace_List_String + ( + Var(List(Session_Field)) fields, + String _field_name, + List(String) _field_values + )= + remove_any(fields, string_t, _field_name); + put_List_String(fields, _field_name, _field_values) +. + +public define One replace_String ( Var(List(Session_Field)) fields, String _field_name, String _field_value )= - replace_any(fields, string_t, _field_name, string(_field_value)) + remove_any(fields, string_t, _field_name); + put_String(fields, _field_name, _field_value) . @@ -365,10 +489,10 @@ public define One String get_DB_id(fields, _field_name, default_value) public define Maybe(DB_id) - get_DB_id + get_mb_DB_id ( Var(List(Session_Field)) fields, - String _field_name, + String _field_name, ) = if get_field(*fields, db_id_t, _field_name) is { @@ -385,14 +509,46 @@ public define DB_id get_DB_id ( Var(List(Session_Field)) fields, - String _field_name, - DB_id default_value + String _field_name, + ) = + if get_mb_DB_id(fields, _field_name) is + { + failure then + println("get_DB_id field_name ["+_field_name+"] not found"); + none + success(value) then value + } +. + +public define DB_id + get_DB_id + ( + Var(List(Session_Field)) fields, + String _field_name, + DB_id default_value ) = - if get_DB_id(fields, _field_name) is + if get_mb_DB_id(fields, _field_name) is { failure then default_value success(value) then value - }. + } +. + +public define List(DB_id) + get_List_DB_id + ( + Var(List(Session_Field)) fields, + String _field_name + ) = + map_select((Session_Field_Datum datum) |-> + if datum is db_id(value) then + success(value) + else + failure + , + get_fields_list(*fields, db_id_t, _field_name) + ) +. public define One put_DB_id @@ -401,25 +557,50 @@ public define One String _field_name, DB_id _field_value )= - fields <- [session_field(_field_name, int_t, var(db_id(_field_value))) . *fields] + fields <- [session_field(_field_name, db_id_t, var(db_id(_field_value))) . *fields] . + public define One replace_DB_id ( Var(List(Session_Field)) fields, - String _field_name, - DB_id _field_value + String _field_name, + DB_id _field_value )= replace_any(fields, db_id_t, _field_name, db_id(_field_value)) . +public define One + put_List_DB_id + ( + Var(List(Session_Field)) fields, + String _field_name, + List(DB_id) _field_values + )= + map_forget((DB_id value) |-> + fields <- [session_field(_field_name, db_id_t, var(db_id(value))) . *fields] + , + _field_values + ) +. + +public define One + replace_List_DB_id + ( + Var(List(Session_Field)) fields, + String _field_name, + List(DB_id) _field_values + )= + remove_any(fields, db_id_t, _field_name); + put_List_DB_id(fields, _field_name, _field_values) +. public define One remove_DB_id ( Var(List(Session_Field)) fields, - String _field_name + String _field_name )= remove_any(fields, db_id_t, _field_name) . @@ -1195,51 +1376,3 @@ public define $T } . - /************************************************/ - -public define String dump_Session_Field_list(List(Session_Field) _fields, String indent). - -public define String - dump_Session_Field - ( - Session_Field _field, - String indent - )= - with name = "Name = ["+_field.field_name+"]", - if *_field.field_datum is - { - string(_string) then name+", Type = String, Value = ["+_string+"]", - bool(_bool) then name+", Type = Bool, Value = ["+to_String(_bool)+"]", - int(_int) then name+", Type = Int, Value = ["+_int+"]", - db_id(_db_id) then name+", Type = DB_id, Value = ["+_db_id+"]", - message(_message) then name+", Type = Message, Value = ["+dump(_message)+"]", - byte_array(_byte_array) then name+", Type = ByteArray", - float(_float) then name+", Type = Float, Value = ["+float_to_string(_float, 10)+"]", - word128(_word128) then name+", Type = Word128, Value = ["+to_decimal(_word128)+"]", - word64(_word64) then name+", Type = Word64, Value = ["+to_decimal(_word64)+"]", - word32(_word32) then name+", Type = Word32, Value = ["+to_decimal(_word32)+"]", - word16(_word16) then name+", Type = Word16, Value = ["+to_decimal(_word16)+"]", - word8(_word8) then name+", Type = Word8, Value = ["+to_decimal(_word8)+"]", - word4(_word4) then name+", Type = Word4, Value = ["+to_decimal(_word4)+"]", - fields_set(_fields) then name+", Type = Fields_set, \n"+dump_Session_Field_list(*_fields, indent+" "), - session(_session) then name+", Type = Session, session id = ["+_session.id+"]\n"+dump_Session_Field_list(*_session.fields, indent+" "), - } -. - -public define String - dump_Session_Field_list - ( - List(Session_Field) _fields, - String indent - )= - join("\n", map((Session_Field _field) |-> dump_Session_Field(_field, indent), _fields)) -. - -public define String - dump_Session - ( - Session _session, - String indent - )= - dump_Session_Field_list(*_session.fields, indent) -. diff --git a/generic/types/session.anubis b/generic/types/session.anubis index 5be1ec6..3a76eb6 100644 --- a/generic/types/session.anubis +++ b/generic/types/session.anubis @@ -70,6 +70,31 @@ public type Session_Field_Type: session_t . +public define String + to_String + ( + Session_Field_Type field_type + )= + if field_type is + { + string_t then "string_t", + bool_t then "bool_t", + int_t then "int_t", + db_id_t then "db_id_t", + message_t then "message_t", + byte_array_t then "byte_array_t", + float_t then "float_t", + word128_t then "word128_t", + word64_t then "word64_t", + word32_t then "word32_t", + word16_t then "word16_t", + word8_t then "word8_t", + word4_t then "word4_t", + fields_set_t then "fields_set_t", + session_t then "session_t" + } +. + public type Session_Field: session_field( String field_name, -- libgit2 0.21.4