-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.cpp
165 lines (160 loc) · 3.84 KB
/
Config.cpp
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
159
160
161
162
163
164
165
#include "Config.h"
#include "ClrVirtualmachine.h"
#include <configdata.h>
int SqfVm::Config::Count::get()
{
return (int)(*m_configdata)->size();
}
System::String^ SqfVm::Config::Name::get()
{
return gcnew System::String((*m_configdata)->name().c_str());
}
System::String^ SqfVm::Config::ParentName::get()
{
return gcnew System::String((*m_configdata)->inherited_parent_name().c_str());
}
SqfVm::EConfigNodeType SqfVm::Config::NodeType::get()
{
if ((*m_configdata)->is_null())
{
throw gcnew System::InvalidOperationException();
}
else if ((*m_configdata)->cfgvalue().dtype() == sqf::type::STRING)
{
return SqfVm::EConfigNodeType::String;
}
else if ((*m_configdata)->cfgvalue().dtype() == sqf::type::SCALAR)
{
return SqfVm::EConfigNodeType::Scalar;
}
else if ((*m_configdata)->cfgvalue().dtype() == sqf::type::NOTHING)
{
return SqfVm::EConfigNodeType::Config;
}
else if ((*m_configdata)->cfgvalue().dtype() == sqf::type::ARRAY)
{
return SqfVm::EConfigNodeType::Array;
}
else
{
throw gcnew System::InvalidOperationException();
}
}
System::Object^ SqfVm::Config::Value::get()
{
auto res = (*m_configdata)->cfgvalue();
return SqfVm::ClrVirtualmachine::FromValue(res);
}
SqfVm::Config^ SqfVm::Config::LogicalParent::get()
{
auto res = (*m_configdata)->logical_parent();
if (res.dtype() == sqf::type::CONFIG && !res.data<sqf::configdata>()->is_null())
{
return gcnew Config(res.data<sqf::configdata>());
}
else
{
return nullptr;
}
}
SqfVm::Config^ SqfVm::Config::InheritedParent::get()
{
auto res = (*m_configdata)->inherited_parent();
if (res.dtype() == sqf::type::CONFIG && !res.data<sqf::configdata>()->is_null())
{
return gcnew Config(res.data<sqf::configdata>());
}
else
{
return nullptr;
}
}
SqfVm::Config^ SqfVm::Config::default::get(int index)
{
auto res = (*m_configdata)->at((size_t)index);
if (res.dtype() == sqf::type::CONFIG)
{
return gcnew SqfVm::Config(res.data<sqf::configdata>());
}
else
{
return nullptr;
}
}
SqfVm::Config^ SqfVm::Config::default::get(System::String^ index)
{
auto key = msclr::interop::marshal_as<std::string>(index);
auto res = (*m_configdata)->navigate(key);
if (res.dtype() == sqf::type::CONFIG && !res.data<sqf::configdata>()->is_null())
{
return gcnew SqfVm::Config(res.data<sqf::configdata>());
}
else
{
return nullptr;
}
}
System::Collections::Generic::IEnumerable<System::String^>^ SqfVm::Config::Keys::get()
{
auto list = gcnew System::Collections::Generic::List<System::String^>((*m_configdata)->size());
for (int i = 0; i < (int)(*m_configdata)->size(); i++)
{
auto val = (*m_configdata)->at(i);
if (val.dtype() == sqf::type::CONFIG)
{
list->Add(gcnew System::String(val.data<sqf::configdata>()->name().c_str()));
}
else
{
// Unknown Cause.
throw gcnew System::Exception();
}
}
return list;
}
System::Collections::Generic::IEnumerable<SqfVm::Config^>^ SqfVm::Config::Values::get()
{
auto list = gcnew System::Collections::Generic::List<SqfVm::Config^>((*m_configdata)->size());
for (int i = 0; i < (int)(*m_configdata)->size(); i++)
{
list->Add(this[i]);
}
return list;
}
void SqfVm::Config::MergeWith(Config^ otherconfig)
{
if (otherconfig)
{
(*otherconfig->m_configdata)->mergeinto(*m_configdata);
}
else
{
throw gcnew System::ArgumentNullException(gcnew String("otherconfig"));
}
}
bool SqfVm::Config::ContainsKey(System::String^ key)
{
for (int i = 0; i < (int)(*m_configdata)->size(); i++)
{
auto val = (*m_configdata)->at(i);
if (val.dtype() == sqf::type::CONFIG)
{
return true;
}
}
return false;
}
bool SqfVm::Config::TryGetValue(System::String^ key, SqfVm::Config^% value)
{
for (int i = 0; i < (int)(*m_configdata)->size(); i++)
{
auto val = (*m_configdata)->at(i);
if (val.dtype() == sqf::type::CONFIG)
{
value = gcnew SqfVm::Config(val.data<sqf::configdata>());
return true;
}
}
value = nullptr;
return false;
}