-
Notifications
You must be signed in to change notification settings - Fork 21
/
array.go
158 lines (139 loc) · 3.91 KB
/
array.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package cwl
import (
"fmt"
//"reflect"
"encoding/json"
"github.com/davecgh/go-spew/spew"
)
type Array []CWLType
//type Array struct {
//CWLType_Impl `yaml:",inline" json:",inline" bson:",inline" mapstructure:",squash"` // Class, Id, Type
// Items []CWLType `yaml:"items,omitempty" json:"items,omitempty" bson:"items,omitempty"` // CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string | array<CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string>
//Items_Type CWLType_Type `yaml:"items_type,omitempty" json:"items_type,omitempty" bson:"items_type,omitempty"`
//}
func (c *Array) Is_CWL_object() {}
func (c *Array) GetClass() string { return "array" }
func (c *Array) GetId() string { return "foobar" }
func (c *Array) SetId(string) {}
func (c *Array) GetType() CWLType_Type { return CWL_array }
func (c *Array) Is_CWL_minimal() {}
//func (c *Array) Is_CommandInputParameterType() {}
//func (c *Array) Is_CommandOutputParameterType() {}
func NewArray(id string, native interface{}) (array_ptr *Array, err error) {
switch native.(type) {
case []interface{}:
native_array := native.([]interface{})
array := Array{}
for _, value := range native_array {
var value_cwl CWLType
value_cwl, err = NewCWLType("", value)
if err != nil {
fmt.Println("NewArray element:")
spew.Dump(value)
err = fmt.Errorf("(NewArray) NewCWLType returned: %s", err.Error())
return
}
array = append(array, value_cwl)
}
//if len(array.Items) > 0 {
// array.Items_Type = array.Items[0].GetType()
//}
array_ptr = &array
return
default:
}
return
}
//func (c *Array) GetClass() string { return c.Class }
// func NewArray(id string, native interface{}) (array *Array, err error) {
//
// //array = &Array{CWLType_Impl: CWLType_Impl{Id: id}}
// //array = &Array{}
// //array.Class = "array"
// //schema := NewArraySchema()
// //array.Type = CWL_array
// //array.Type =
//
// //if id != "" {
// // array.Id = id
// // }
//
// switch native.(type) {
// case map[string]interface{}:
// native_map := native.(map[string]interface{})
//
// obj_id, has_id := native_map["id"]
// if has_id {
// obj_id_str, ok := obj_id.(string)
// if !ok {
// err = fmt.Errorf("(NewArray) id is not of type string")
// return
// }
//
// array.Id = obj_id_str
// }
//
// items, has_items := native_map["items"]
// if has_items {
// var item_array *[]CWLType
// item_array, err = NewCWLTypeArray(items, array.Id)
// if err != nil {
// err = fmt.Errorf("(NewArray) NewCWLTypeArray failed: %s", err.Error())
// return
// }
//
// array.Items = *item_array
//
// //type_map := make(map[CWLType_Type]bool)
//
// // collect info about types used in the array, needed later for verification
// //for _, item := range array.Items {
//
// // item_type := item.GetType()
// // type_map[item_type] = true
//
// //}
//
// //for item_type, _ := range type_map {
// // schema.Items = append(schema.Items, item_type)
// //}
//
// //a_type := array.Items[0]
// //array.Items_Type = a_type.GetType()
// }
//
// case []interface{}:
// native_array := native.([]interface{})
// for _, value := range native_array {
//
// value_cwl, xerr := NewCWLType("", value)
// if xerr != nil {
// err = xerr
// return
// }
//
// array.Items = append(array.Items, value_cwl)
// }
// //if len(array.Items) > 0 {
// // array.Items_Type = array.Items[0].GetType()
// //}
// return
// default:
// err = fmt.Errorf("(NewArray) type %s unknown", reflect.TypeOf(native))
// return
// }
//
// return
// }
//
func (c *Array) String() string {
a_byte, err := json.Marshal(c)
if err != nil {
return err.Error()
}
return string(a_byte[:])
}
//
// func (c *Array) Add(ct CWLType) {
// c.Items = append(c.Items, ct)
// }