Skip to content

Commit 4bdc2b7

Browse files
committed
add wrapper class
1 parent c679ab4 commit 4bdc2b7

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/cpp/bin/testml-cpp-tap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ testml-run-file() {
2222
$lib/runtime.cpp \
2323
$lib/stdlib.cpp \
2424
$lib/bridge.cpp \
25+
$lib/wrapper.cpp \
2526
$bridge_file || return
2627

2728
chmod +x $testml_runner

src/cpp/lib/testml/wrapper.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "wrapper.hpp"
2+
3+
namespace testml {
4+
namespace wrapper {
5+
6+
using json = nlohmann::json;
7+
8+
template<>
9+
nlohmann::json cook(std::string s) {
10+
return nlohmann::json::string_t{s};
11+
}
12+
13+
template<>
14+
nlohmann::json cook(int i) {
15+
return nlohmann::json::number_integer_t{i};
16+
}
17+
18+
template<>
19+
std::string uncook(nlohmann::json s) {
20+
return s;
21+
}
22+
23+
template<>
24+
int uncook(nlohmann::json i) {
25+
return i;
26+
}
27+
28+
}
29+
}

src/cpp/lib/testml/wrapper.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include "../../ext/nlohmann/json.hpp"
4+
5+
namespace testml {
6+
namespace wrapper {
7+
8+
template<typename T>
9+
nlohmann::json cook(T);
10+
11+
template<typename T>
12+
T uncook(nlohmann::json);
13+
14+
15+
}
16+
}

0 commit comments

Comments
 (0)