s.getstruct(var [flags]) s.setstruct(var [flags2])
s - str variable.
var - variable of a user-defined type.
Add member names. If this flag not used, the string will contain only values.
Use this flag if s includes member names. When using this flag, the order of members in s is not important. Some members in s may be missing. Some lines in s may be empty or contain any data. This is useful when the string may be edited by the user. If this flag not used, the string must contain only values, exactly as generated by getstruct without flag 1.
|2||Member names in the string don't have to match case.|
|4||Don't clear var members that are missing in s.|
|8||Error if some members are missing in s.|
getstruct converts and stores values of all members of a variable of a user-defined type (var) into a single string (s).
setstruct extracts values from s (which is previously generated by getstruct or other code) and populates var.
For example, if var is of a type that has two int members x and y, an example of s may be:
If using flag 1, it will be:
x 10 y 20
Member name and value are separated by one or more spaces.
The variable also can contain strings. For example, if var is of a type that has four str members s1, s2, s3 and s4, an example of s may be:
s1 string1 s2 "string that contains spacesor ''escape sequences''" s3 s4 ""
If a string contains spaces or characters that must be escaped, in s it is or must be escaped and enclosed in double quotes, like s2 in the example. Otherwise enclosing is not necessary. setstruct does not unescape strings that are not enclosed. Empty strings are like s3 in the example. Zero length strings are like s4 in the example.
Embedded arrays look like:
array_of_int_word_byte_long_double 2 -5 184 0 array_of_byte_also_can_be "string" array_of_str string1 array_of_str string2 array_of_POINT.x 10 array_of_POINT.y 20 array_of_POINT.x 30 array_of_POINT.y 40
If an int/word/byte member name contains "flags", getstruct formats its value in hexadecimal format.
The functions are slightly slower when using flag 1.
The string generated by getstruct with flag 1 can be passed to AddList function of IStrinMap. Don't forget to remove quotes and unescape enclosed values.
Not all types are supported. Restrictions:
QM 2.3.2. The restriction 2 is not applied to getstruct. It allows you to convert these types for debugging purposes.
Added in QM 2.2.1.
out type T1 byte'x word'y str's type T2 int'i str's T1't double'd long'k byte'b T2 t tt t.i=-5 t.s="''string''line2" t.t.x=200 t.t.y=50000 t.t.s="string2" t.d=1.55 t.k=0x100000000 t.b=3 t.b=4 str s s.getstruct(t 1) out s out "---" s.setstruct(tt 1) out tt.i out tt.s out tt.t.x out tt.t.y out tt.t.s out tt.d out tt.k out tt.b out tt.b Output: i -5 s "''string''line2" t.x 200 t.y 50000 t.s string2 d 1.55 k 4294967296 b 3 b 4 --- -5 "string" line2 200 50000 string2 1.55 4294967296 3 4