Examples of Usage

The following examples were taken from the regression test script.

Object setup:

package require autoObject
set firstDefList {
    FieldOne    {0   4   uint32_t   1       }
    FieldTwo    {4   1   uint8_t    150     }
    FieldThree  {5   3   uint8_t[3] {1 2 3} }
    FieldFour   {8   4   float_t    3.141590118408203    }
    FieldFive   {12  2   uint16_t   50000   }
    FieldSix    {14  1   int8_t     -5      }
    FieldSeven  {15  4   time_t     ""      {"%Y-%m-%d %H:%M:%S"}  }
    StrField    {20  15  string_t   "How you like me now?"    15 }
}

set firstObject [autoObject new $firstDefList]

Human-readable output:

puts [$firstObject toString]

produces:

                              FieldOne: 1
                              FieldTwo: 150
                            FieldThree: 1   2   3
                             FieldFour: 3.141590
                             FieldFive: 50000
                              FieldSix: -5
                            FieldSeven: {"2017-08-03 16:12:09"}
                              StrField: "How you like me"

Changing field values, getting fields, and outputting list form:

$firstObject set FieldThree {4 5 6} FieldOne 987654321
puts [$firstObject get]
puts "Twice FieldTwo is: [expr {[$firstObject get FieldTwo] * 2}]"
puts "To List: [$firstObject toList]"

produces:

FieldOne 987654321 FieldTwo 150 FieldThree {4 5 6} FieldFour 3.141590118408203 FieldFive 50000 FieldSix -5 FieldSeven {"1969-12-31 16:00:00"}
Twice FieldTwo is: 300
To List: 177 104 222 58 150 4 5 6 208 15 73 64 80 195 251 201 173 131 89 1 72 111 119 32 121 111 117 32 108 105 107 101 32 109 101 

And setting all fields from a byte stream:

set list1 {1 0 1 0 96 10 9 -10 -48 99 73 64 120 232 175 0 0 0 0 2 \
            110 111 119 44 32 109 111 116 104 101 114 102 42 42 42}
$firstObject fromList $list1
puts "From modified list:"
puts [$firstObject toString]
puts "Twice FieldTwo is: [expr {[$firstObject get FieldTwo] * 2}]"

produces:

From modified list:
                              FieldOne: 65537
                              FieldTwo: 96
                            FieldThree: 10  9   246
                             FieldFour: 3.146717
                             FieldFive: 59512
                              FieldSix: -81
                            FieldSeven: {"1969-12-31 16:00:00"}
                              StrField: "now, motherf***"
Twice FieldTwo is: 192