-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolumn_layout.cpp
57 lines (45 loc) · 1.6 KB
/
column_layout.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
#include <unity/scopes/ColumnLayout.h>
#include <unity/scopes/Variant.h>
#include <unity/UnityExceptions.h>
extern "C" {
#include "_cgo_export.h"
}
#include <cstring>
#include "helpers.h"
#include "smartptr_helper.h"
using namespace unity::scopes;
using namespace gounityscopes::internal;
void destroy_column_layout(_ColumnLayout *layout) {
delete reinterpret_cast<ColumnLayout*>(layout);
}
_ColumnLayout *new_column_layout(int num_columns) {
return reinterpret_cast<_ColumnLayout*>(new ColumnLayout(num_columns));
}
void column_layout_add_column(_ColumnLayout *layout, const StrData widget_list, char **error) {
std::vector<std::string> widgets = split_strings(widget_list);
try {
reinterpret_cast<ColumnLayout*>(layout)->add_column(widgets);
} catch(unity::LogicException & e) {
*error = strdup(e.what());
}
}
int column_layout_number_of_columns(_ColumnLayout *layout) {
return reinterpret_cast<ColumnLayout*>(layout)->number_of_columns();
}
int column_layout_size(_ColumnLayout *layout) {
return reinterpret_cast<ColumnLayout*>(layout)->size();
}
void *column_layout_column(_ColumnLayout *layout, int column, int *length, char **error) {
try {
auto columns = reinterpret_cast<ColumnLayout*>(layout)->column(column);
VariantArray var_array;
for (auto item: columns) {
var_array.push_back(Variant(item));
}
std::string json_data = Variant(var_array).serialize_json();
return as_bytes(json_data, length);
} catch(const std::exception & e) {
*error = strdup(e.what());
return nullptr;
}
}