Commit 8ccc5ad5f7ce13609c1fb0c0780dfca711bc1420
1 parent
85496d9f
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
Showing
2 changed files
with
222 additions
and
64 deletions
Show diff stats
generic/session.anubis
| @@ -81,6 +81,55 @@ public define List(Session_Field_No_Var) | @@ -81,6 +81,55 @@ public define List(Session_Field_No_Var) | ||
| 81 | ) | 81 | ) |
| 82 | . | 82 | . |
| 83 | 83 | ||
| 84 | + /************************************************/ | ||
| 85 | + | ||
| 86 | +public define String dump_Session_Field_list(List(Session_Field) _fields, String indent). | ||
| 87 | + | ||
| 88 | +public define String | ||
| 89 | + dump_Session_Field | ||
| 90 | + ( | ||
| 91 | + Session_Field _field, | ||
| 92 | + String indent | ||
| 93 | + )= | ||
| 94 | + with name = "Name = ["+_field.field_name+"]", | ||
| 95 | + if *_field.field_datum is | ||
| 96 | + { | ||
| 97 | + string(_string) then name+", Type = String, Value = ["+_string+"]", | ||
| 98 | + bool(_bool) then name+", Type = Bool, Value = ["+to_String(_bool)+"]", | ||
| 99 | + int(_int) then name+", Type = Int, Value = ["+_int+"]", | ||
| 100 | + db_id(_db_id) then name+", Type = DB_id, Value = ["+_db_id+"]", | ||
| 101 | + message(_message) then name+", Type = Message, Value = ["+dump(_message)+"]", | ||
| 102 | + byte_array(_byte_array) then name+", Type = ByteArray", | ||
| 103 | + float(_float) then name+", Type = Float, Value = ["+float_to_string(_float, 10)+"]", | ||
| 104 | + word128(_word128) then name+", Type = Word128, Value = ["+to_decimal(_word128)+"]", | ||
| 105 | + word64(_word64) then name+", Type = Word64, Value = ["+to_decimal(_word64)+"]", | ||
| 106 | + word32(_word32) then name+", Type = Word32, Value = ["+to_decimal(_word32)+"]", | ||
| 107 | + word16(_word16) then name+", Type = Word16, Value = ["+to_decimal(_word16)+"]", | ||
| 108 | + word8(_word8) then name+", Type = Word8, Value = ["+to_decimal(_word8)+"]", | ||
| 109 | + word4(_word4) then name+", Type = Word4, Value = ["+to_decimal(_word4)+"]", | ||
| 110 | + fields_set(_fields) then name+", Type = Fields_set, \n"+dump_Session_Field_list(*_fields, indent+" "), | ||
| 111 | + session(_session) then name+", Type = Session, session id = ["+_session.id+"]\n"+dump_Session_Field_list(*_session.fields, indent+" "), | ||
| 112 | + } | ||
| 113 | +. | ||
| 114 | + | ||
| 115 | +public define String | ||
| 116 | + dump_Session_Field_list | ||
| 117 | + ( | ||
| 118 | + List(Session_Field) _fields, | ||
| 119 | + String indent | ||
| 120 | + )= | ||
| 121 | + join("\n", map((Session_Field _field) |-> dump_Session_Field(_field, indent), _fields)) | ||
| 122 | +. | ||
| 123 | + | ||
| 124 | +public define String | ||
| 125 | + dump_Session | ||
| 126 | + ( | ||
| 127 | + Session _session, | ||
| 128 | + String indent | ||
| 129 | + )= | ||
| 130 | + dump_Session_Field_list(*_session.fields, indent) | ||
| 131 | +. | ||
| 132 | + | ||
| 84 | 133 | ||
| 85 | public define Maybe(Session_Field_Datum) | 134 | public define Maybe(Session_Field_Datum) |
| 86 | get_field | 135 | get_field |
| @@ -93,12 +142,45 @@ public define Maybe(Session_Field_Datum) | @@ -93,12 +142,45 @@ public define Maybe(Session_Field_Datum) | ||
| 93 | { | 142 | { |
| 94 | [] then failure, | 143 | [] then failure, |
| 95 | [h . t] then | 144 | [h . t] then |
| 145 | + //println("testing get_field h.field_name "+dump_Session_Field(h, "")+" looking of _field_name ["+_field_name+"] of type "+to_String(_field_type)); | ||
| 96 | if h.field_name = _field_name & h.field_type = _field_type then | 146 | if h.field_name = _field_name & h.field_type = _field_type then |
| 147 | + //println("OK"); | ||
| 97 | success(*h.field_datum) | 148 | success(*h.field_datum) |
| 98 | else | 149 | else |
| 99 | get_field(t, _field_type, _field_name) | 150 | get_field(t, _field_type, _field_name) |
| 100 | } | 151 | } |
| 101 | . | 152 | . |
| 153 | + | ||
| 154 | + | ||
| 155 | +public define List(Session_Field_Datum) | ||
| 156 | + get_fields_list | ||
| 157 | + ( | ||
| 158 | + List(Session_Field) fields, | ||
| 159 | + Session_Field_Type _field_type, | ||
| 160 | + String _field_name, | ||
| 161 | + List(Session_Field_Datum) so_far | ||
| 162 | + ) = | ||
| 163 | + if fields is | ||
| 164 | + { | ||
| 165 | + [] then so_far, | ||
| 166 | + [h . t] then | ||
| 167 | + if h.field_name = _field_name & h.field_type = _field_type then | ||
| 168 | + get_fields_list(t, _field_type, _field_name, [*h.field_datum . so_far]) | ||
| 169 | + else | ||
| 170 | + get_fields_list(t, _field_type, _field_name, so_far) | ||
| 171 | + } | ||
| 172 | +. | ||
| 173 | + | ||
| 174 | +public define List(Session_Field_Datum) | ||
| 175 | + get_fields_list | ||
| 176 | + ( | ||
| 177 | + List(Session_Field) fields, | ||
| 178 | + Session_Field_Type _field_type, | ||
| 179 | + String _field_name | ||
| 180 | + ) = | ||
| 181 | + get_fields_list(fields, _field_type, _field_name, []) | ||
| 182 | +. | ||
| 183 | + | ||
| 102 | /******** ANY functions ***************/ | 184 | /******** ANY functions ***************/ |
| 103 | 185 | ||
| 104 | 186 | ||
| @@ -160,20 +242,20 @@ define One | @@ -160,20 +242,20 @@ define One | ||
| 160 | Session_Field_Type _field_type, | 242 | Session_Field_Type _field_type, |
| 161 | String _field_name, | 243 | String _field_name, |
| 162 | Session_Field_Datum _field_value | 244 | Session_Field_Datum _field_value |
| 163 | - )= | 245 | + )= |
| 164 | replace_any(*fields, _field_type, _field_name, _field_value, fields) | 246 | replace_any(*fields, _field_type, _field_name, _field_value, fields) |
| 165 | . | 247 | . |
| 166 | 248 | ||
| 167 | /*************** String *****************/ | 249 | /*************** String *****************/ |
| 168 | 250 | ||
| 169 | - Maybe(String) get_String(fields, _field_name) | 251 | + Maybe(String) get_mb_String(fields, _field_name) |
| 170 | String get_String(fields, _field_name, default_value) | 252 | String get_String(fields, _field_name, default_value) |
| 171 | 253 | ||
| 172 | public define Maybe(String) | 254 | public define Maybe(String) |
| 173 | - get_String | 255 | + get_mb_String |
| 174 | ( | 256 | ( |
| 175 | Var(List(Session_Field)) fields, | 257 | Var(List(Session_Field)) fields, |
| 176 | - String _field_name | 258 | + String _field_name |
| 177 | ) = | 259 | ) = |
| 178 | if get_field(*fields, string_t, _field_name) is | 260 | if get_field(*fields, string_t, _field_name) is |
| 179 | { | 261 | { |
| @@ -193,12 +275,28 @@ public define String | @@ -193,12 +275,28 @@ public define String | ||
| 193 | String _field_name, | 275 | String _field_name, |
| 194 | String default_value | 276 | String default_value |
| 195 | ) = | 277 | ) = |
| 196 | - if get_String(fields, _field_name) is | 278 | + if get_mb_String(fields, _field_name) is |
| 197 | { | 279 | { |
| 198 | failure then default_value | 280 | failure then default_value |
| 199 | success(value) then value | 281 | success(value) then value |
| 200 | }. | 282 | }. |
| 201 | 283 | ||
| 284 | +public define List(String) | ||
| 285 | + get_List_String | ||
| 286 | + ( | ||
| 287 | + Var(List(Session_Field)) fields, | ||
| 288 | + String _field_name | ||
| 289 | + ) = | ||
| 290 | + map_select((Session_Field_Datum datum) |-> | ||
| 291 | + if datum is string(value) then | ||
| 292 | + success(value) | ||
| 293 | + else | ||
| 294 | + failure | ||
| 295 | + , | ||
| 296 | + get_fields_list(*fields, string_t, _field_name) | ||
| 297 | + ) | ||
| 298 | +. | ||
| 299 | + | ||
| 202 | public define One | 300 | public define One |
| 203 | put_String | 301 | put_String |
| 204 | ( | 302 | ( |
| @@ -210,13 +308,39 @@ public define One | @@ -210,13 +308,39 @@ public define One | ||
| 210 | . | 308 | . |
| 211 | 309 | ||
| 212 | public define One | 310 | public define One |
| 311 | + put_List_String | ||
| 312 | + ( | ||
| 313 | + Var(List(Session_Field)) fields, | ||
| 314 | + String _field_name, | ||
| 315 | + List(String) _field_values | ||
| 316 | + )= | ||
| 317 | + map_forget((String value) |-> | ||
| 318 | + fields <- [session_field(_field_name, string_t, var(string(value))) . *fields] | ||
| 319 | + , | ||
| 320 | + _field_values | ||
| 321 | + ) | ||
| 322 | +. | ||
| 323 | + | ||
| 324 | +public define One | ||
| 325 | + replace_List_String | ||
| 326 | + ( | ||
| 327 | + Var(List(Session_Field)) fields, | ||
| 328 | + String _field_name, | ||
| 329 | + List(String) _field_values | ||
| 330 | + )= | ||
| 331 | + remove_any(fields, string_t, _field_name); | ||
| 332 | + put_List_String(fields, _field_name, _field_values) | ||
| 333 | +. | ||
| 334 | + | ||
| 335 | +public define One | ||
| 213 | replace_String | 336 | replace_String |
| 214 | ( | 337 | ( |
| 215 | Var(List(Session_Field)) fields, | 338 | Var(List(Session_Field)) fields, |
| 216 | String _field_name, | 339 | String _field_name, |
| 217 | String _field_value | 340 | String _field_value |
| 218 | )= | 341 | )= |
| 219 | - replace_any(fields, string_t, _field_name, string(_field_value)) | 342 | + remove_any(fields, string_t, _field_name); |
| 343 | + put_String(fields, _field_name, _field_value) | ||
| 220 | . | 344 | . |
| 221 | 345 | ||
| 222 | 346 | ||
| @@ -365,10 +489,10 @@ public define One | @@ -365,10 +489,10 @@ public define One | ||
| 365 | String get_DB_id(fields, _field_name, default_value) | 489 | String get_DB_id(fields, _field_name, default_value) |
| 366 | 490 | ||
| 367 | public define Maybe(DB_id) | 491 | public define Maybe(DB_id) |
| 368 | - get_DB_id | 492 | + get_mb_DB_id |
| 369 | ( | 493 | ( |
| 370 | Var(List(Session_Field)) fields, | 494 | Var(List(Session_Field)) fields, |
| 371 | - String _field_name, | 495 | + String _field_name, |
| 372 | ) = | 496 | ) = |
| 373 | if get_field(*fields, db_id_t, _field_name) is | 497 | if get_field(*fields, db_id_t, _field_name) is |
| 374 | { | 498 | { |
| @@ -385,14 +509,46 @@ public define DB_id | @@ -385,14 +509,46 @@ public define DB_id | ||
| 385 | get_DB_id | 509 | get_DB_id |
| 386 | ( | 510 | ( |
| 387 | Var(List(Session_Field)) fields, | 511 | Var(List(Session_Field)) fields, |
| 388 | - String _field_name, | ||
| 389 | - DB_id default_value | 512 | + String _field_name, |
| 513 | + ) = | ||
| 514 | + if get_mb_DB_id(fields, _field_name) is | ||
| 515 | + { | ||
| 516 | + failure then | ||
| 517 | + println("get_DB_id field_name ["+_field_name+"] not found"); | ||
| 518 | + none | ||
| 519 | + success(value) then value | ||
| 520 | + } | ||
| 521 | +. | ||
| 522 | + | ||
| 523 | +public define DB_id | ||
| 524 | + get_DB_id | ||
| 525 | + ( | ||
| 526 | + Var(List(Session_Field)) fields, | ||
| 527 | + String _field_name, | ||
| 528 | + DB_id default_value | ||
| 390 | ) = | 529 | ) = |
| 391 | - if get_DB_id(fields, _field_name) is | 530 | + if get_mb_DB_id(fields, _field_name) is |
| 392 | { | 531 | { |
| 393 | failure then default_value | 532 | failure then default_value |
| 394 | success(value) then value | 533 | success(value) then value |
| 395 | - }. | 534 | + } |
| 535 | +. | ||
| 536 | + | ||
| 537 | +public define List(DB_id) | ||
| 538 | + get_List_DB_id | ||
| 539 | + ( | ||
| 540 | + Var(List(Session_Field)) fields, | ||
| 541 | + String _field_name | ||
| 542 | + ) = | ||
| 543 | + map_select((Session_Field_Datum datum) |-> | ||
| 544 | + if datum is db_id(value) then | ||
| 545 | + success(value) | ||
| 546 | + else | ||
| 547 | + failure | ||
| 548 | + , | ||
| 549 | + get_fields_list(*fields, db_id_t, _field_name) | ||
| 550 | + ) | ||
| 551 | +. | ||
| 396 | 552 | ||
| 397 | public define One | 553 | public define One |
| 398 | put_DB_id | 554 | put_DB_id |
| @@ -401,25 +557,50 @@ public define One | @@ -401,25 +557,50 @@ public define One | ||
| 401 | String _field_name, | 557 | String _field_name, |
| 402 | DB_id _field_value | 558 | DB_id _field_value |
| 403 | )= | 559 | )= |
| 404 | - fields <- [session_field(_field_name, int_t, var(db_id(_field_value))) . *fields] | 560 | + fields <- [session_field(_field_name, db_id_t, var(db_id(_field_value))) . *fields] |
| 405 | . | 561 | . |
| 406 | 562 | ||
| 563 | + | ||
| 407 | public define One | 564 | public define One |
| 408 | replace_DB_id | 565 | replace_DB_id |
| 409 | ( | 566 | ( |
| 410 | Var(List(Session_Field)) fields, | 567 | Var(List(Session_Field)) fields, |
| 411 | - String _field_name, | ||
| 412 | - DB_id _field_value | 568 | + String _field_name, |
| 569 | + DB_id _field_value | ||
| 413 | )= | 570 | )= |
| 414 | replace_any(fields, db_id_t, _field_name, db_id(_field_value)) | 571 | replace_any(fields, db_id_t, _field_name, db_id(_field_value)) |
| 415 | . | 572 | . |
| 416 | 573 | ||
| 574 | +public define One | ||
| 575 | + put_List_DB_id | ||
| 576 | + ( | ||
| 577 | + Var(List(Session_Field)) fields, | ||
| 578 | + String _field_name, | ||
| 579 | + List(DB_id) _field_values | ||
| 580 | + )= | ||
| 581 | + map_forget((DB_id value) |-> | ||
| 582 | + fields <- [session_field(_field_name, db_id_t, var(db_id(value))) . *fields] | ||
| 583 | + , | ||
| 584 | + _field_values | ||
| 585 | + ) | ||
| 586 | +. | ||
| 587 | + | ||
| 588 | +public define One | ||
| 589 | + replace_List_DB_id | ||
| 590 | + ( | ||
| 591 | + Var(List(Session_Field)) fields, | ||
| 592 | + String _field_name, | ||
| 593 | + List(DB_id) _field_values | ||
| 594 | + )= | ||
| 595 | + remove_any(fields, db_id_t, _field_name); | ||
| 596 | + put_List_DB_id(fields, _field_name, _field_values) | ||
| 597 | +. | ||
| 417 | 598 | ||
| 418 | public define One | 599 | public define One |
| 419 | remove_DB_id | 600 | remove_DB_id |
| 420 | ( | 601 | ( |
| 421 | Var(List(Session_Field)) fields, | 602 | Var(List(Session_Field)) fields, |
| 422 | - String _field_name | 603 | + String _field_name |
| 423 | )= | 604 | )= |
| 424 | remove_any(fields, db_id_t, _field_name) | 605 | remove_any(fields, db_id_t, _field_name) |
| 425 | . | 606 | . |
| @@ -1195,51 +1376,3 @@ public define $T | @@ -1195,51 +1376,3 @@ public define $T | ||
| 1195 | } | 1376 | } |
| 1196 | . | 1377 | . |
| 1197 | 1378 | ||
| 1198 | - /************************************************/ | ||
| 1199 | - | ||
| 1200 | -public define String dump_Session_Field_list(List(Session_Field) _fields, String indent). | ||
| 1201 | - | ||
| 1202 | -public define String | ||
| 1203 | - dump_Session_Field | ||
| 1204 | - ( | ||
| 1205 | - Session_Field _field, | ||
| 1206 | - String indent | ||
| 1207 | - )= | ||
| 1208 | - with name = "Name = ["+_field.field_name+"]", | ||
| 1209 | - if *_field.field_datum is | ||
| 1210 | - { | ||
| 1211 | - string(_string) then name+", Type = String, Value = ["+_string+"]", | ||
| 1212 | - bool(_bool) then name+", Type = Bool, Value = ["+to_String(_bool)+"]", | ||
| 1213 | - int(_int) then name+", Type = Int, Value = ["+_int+"]", | ||
| 1214 | - db_id(_db_id) then name+", Type = DB_id, Value = ["+_db_id+"]", | ||
| 1215 | - message(_message) then name+", Type = Message, Value = ["+dump(_message)+"]", | ||
| 1216 | - byte_array(_byte_array) then name+", Type = ByteArray", | ||
| 1217 | - float(_float) then name+", Type = Float, Value = ["+float_to_string(_float, 10)+"]", | ||
| 1218 | - word128(_word128) then name+", Type = Word128, Value = ["+to_decimal(_word128)+"]", | ||
| 1219 | - word64(_word64) then name+", Type = Word64, Value = ["+to_decimal(_word64)+"]", | ||
| 1220 | - word32(_word32) then name+", Type = Word32, Value = ["+to_decimal(_word32)+"]", | ||
| 1221 | - word16(_word16) then name+", Type = Word16, Value = ["+to_decimal(_word16)+"]", | ||
| 1222 | - word8(_word8) then name+", Type = Word8, Value = ["+to_decimal(_word8)+"]", | ||
| 1223 | - word4(_word4) then name+", Type = Word4, Value = ["+to_decimal(_word4)+"]", | ||
| 1224 | - fields_set(_fields) then name+", Type = Fields_set, \n"+dump_Session_Field_list(*_fields, indent+" "), | ||
| 1225 | - session(_session) then name+", Type = Session, session id = ["+_session.id+"]\n"+dump_Session_Field_list(*_session.fields, indent+" "), | ||
| 1226 | - } | ||
| 1227 | -. | ||
| 1228 | - | ||
| 1229 | -public define String | ||
| 1230 | - dump_Session_Field_list | ||
| 1231 | - ( | ||
| 1232 | - List(Session_Field) _fields, | ||
| 1233 | - String indent | ||
| 1234 | - )= | ||
| 1235 | - join("\n", map((Session_Field _field) |-> dump_Session_Field(_field, indent), _fields)) | ||
| 1236 | -. | ||
| 1237 | - | ||
| 1238 | -public define String | ||
| 1239 | - dump_Session | ||
| 1240 | - ( | ||
| 1241 | - Session _session, | ||
| 1242 | - String indent | ||
| 1243 | - )= | ||
| 1244 | - dump_Session_Field_list(*_session.fields, indent) | ||
| 1245 | -. |
generic/types/session.anubis
| @@ -70,6 +70,31 @@ public type Session_Field_Type: | @@ -70,6 +70,31 @@ public type Session_Field_Type: | ||
| 70 | session_t | 70 | session_t |
| 71 | . | 71 | . |
| 72 | 72 | ||
| 73 | +public define String | ||
| 74 | + to_String | ||
| 75 | + ( | ||
| 76 | + Session_Field_Type field_type | ||
| 77 | + )= | ||
| 78 | + if field_type is | ||
| 79 | + { | ||
| 80 | + string_t then "string_t", | ||
| 81 | + bool_t then "bool_t", | ||
| 82 | + int_t then "int_t", | ||
| 83 | + db_id_t then "db_id_t", | ||
| 84 | + message_t then "message_t", | ||
| 85 | + byte_array_t then "byte_array_t", | ||
| 86 | + float_t then "float_t", | ||
| 87 | + word128_t then "word128_t", | ||
| 88 | + word64_t then "word64_t", | ||
| 89 | + word32_t then "word32_t", | ||
| 90 | + word16_t then "word16_t", | ||
| 91 | + word8_t then "word8_t", | ||
| 92 | + word4_t then "word4_t", | ||
| 93 | + fields_set_t then "fields_set_t", | ||
| 94 | + session_t then "session_t" | ||
| 95 | + } | ||
| 96 | +. | ||
| 97 | + | ||
| 73 | public type Session_Field: | 98 | public type Session_Field: |
| 74 | session_field( | 99 | session_field( |
| 75 | String field_name, | 100 | String field_name, |