MCPcopy Create free account
hub / github.com/devosoft/avida / Load

Method Load

avida-core/source/tools/cArgContainer.cc:31–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30
31cArgContainer* cArgContainer::Load(cString args, const cArgSchema& schema, Feedback& feedback)
32{
33 Apto::Array<bool> set_ints;
34 Apto::Array<bool> set_doubles;
35 Apto::Array<bool> set_strings;
36
37 cArgContainer* ret = new cArgContainer();
38
39 set_ints.Resize(schema.GetNumIntArgs(), false);
40 ret->m_ints.Resize(schema.GetNumIntArgs());
41 set_doubles.Resize(schema.GetNumDoubleArgs(), false);
42 ret->m_doubles.Resize(schema.GetNumDoubleArgs());
43 set_strings.Resize(schema.GetNumStringArgs(), false);
44 ret->m_strings.Resize(schema.GetNumStringArgs());
45
46 cString arg_ent;
47 Apto::String arg_name;
48 bool success = true;
49
50 arg_ent = args.Pop(schema.GetEntrySeparator());
51 while (arg_ent.GetSize() > 0) {
52 arg_name = arg_ent.Pop(schema.GetValueSeparator());
53 schema.AdjustArgName(arg_name);
54
55 cArgSchema::tType type;
56 int index;
57 if (schema.FindEntry(arg_name, type, index)) {
58 switch (type) {
59 case cArgSchema::SCHEMA_INT:
60 set_ints[index] = true;
61 ret->m_ints[index] = arg_ent.AsInt();
62 if (!schema.ValidateInt(index, ret->m_ints[index])) {
63 Apto::String name;
64 if (schema.GetIntName(index, name)) {
65 feedback.Error("value of '%s' exceeds its defined range", static_cast<const char*>(name));
66 } else {
67 feedback.Error("invalid int schema entry at index %d", index);
68 }
69 }
70 break;
71 case cArgSchema::SCHEMA_DOUBLE:
72 set_doubles[index] = true;
73 ret->m_doubles[index] = arg_ent.AsDouble();
74 if (!schema.ValidateDouble(index, ret->m_doubles[index])) {
75 Apto::String name;
76 if (schema.GetDoubleName(index, name)) {
77 feedback.Error("value of '%s' exceeds its defined range", static_cast<const char*>(name));
78 } else {
79 feedback.Error("invalid double schema entry at index %d", index);
80 }
81 }
82 break;
83 case cArgSchema::SCHEMA_STRING:
84 set_strings[index] = true;
85 arg_ent.Trim();
86 ret->m_strings[index] = arg_ent;
87 break;
88 default:

Callers 2

processCommandMethod · 0.45
GetLineAsDictMethod · 0.45

Calls 15

GetNumIntArgsMethod · 0.80
GetNumDoubleArgsMethod · 0.80
GetNumStringArgsMethod · 0.80
GetEntrySeparatorMethod · 0.80
GetValueSeparatorMethod · 0.80
AdjustArgNameMethod · 0.80
FindEntryMethod · 0.80
ValidateIntMethod · 0.80
GetIntNameMethod · 0.80
ValidateDoubleMethod · 0.80
GetDoubleNameMethod · 0.80
TrimMethod · 0.80

Tested by

no test coverage detected