Skip to content

Commit d8971cf

Browse files
committed
Add CI configuation file
1 parent 47f13a0 commit d8971cf

File tree

4 files changed

+75
-9
lines changed

4 files changed

+75
-9
lines changed

.gitlab-ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
image: base/devel
2+
3+
build:
4+
stage: build
5+
script:
6+
- g++ -o example example.cpp
7+
artifacts:
8+
paths:
9+
- example
10+
11+
test:
12+
stage: test
13+
script:
14+
- ./example >out.json
15+
- diff out.json example_result.json

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
JSON printer
22
============
33

4+
[![pipeline status](https://gitlab.com/gflegar/json-printer-ci/badges/master/pipeline.svg)](https://gitlab.com/gflegar/json-printer-ci/commits/master)
5+
46
JSON printer is a header-only C++11 library for printing JSON objects to C++
57
streams.
68
It tries to follow the KISS principle, so the entire library consists of 1

example_result.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"Tesla" : [
3+
{
4+
"name" : "K20",
5+
"cores" : 2496
6+
},
7+
{
8+
"name" : "K40",
9+
"cores" : 2880
10+
},
11+
{
12+
"name" : "K80",
13+
"cores" : 4992
14+
},
15+
{
16+
"name" : "P100",
17+
"cores" : 3584
18+
},
19+
{
20+
"name" : "V100",
21+
"cores" : 5120
22+
}
23+
],
24+
"GeForce" : [
25+
"GTX960",
26+
"GTX970",
27+
"GTX980",
28+
"GTX1050",
29+
"GTX1060",
30+
"GTX1070",
31+
"GTX1080"
32+
],
33+
"Quadro" : null
34+
}

json_printer.hpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ class json_printer {
4141
enum container_type { object, array };
4242

4343
json_printer(std::ostream &os = std::cout, bool pretty = false,
44-
int indent = 2, int base_nesting = 0)
45-
: os_(os), pretty_(pretty), indent_(indent),
46-
base_nesting_(base_nesting), have_separator_(true)
44+
int indent = 2, int base_nesting = 0)
45+
: os_(os),
46+
pretty_(pretty),
47+
indent_(indent),
48+
base_nesting_(base_nesting),
49+
have_separator_(true)
4750
{
4851
print(object);
4952
}
@@ -165,9 +168,14 @@ void print_as_json(json_printer &printer, const std::string &value)
165168
os << '"';
166169
for (const auto c : value) {
167170
switch (c) {
168-
case '\\': os << "\\\\"; break;
169-
case '\"': os << "\\\""; break;
170-
default: os << c;
171+
case '\\':
172+
os << "\\\\";
173+
break;
174+
case '\"':
175+
os << "\\\"";
176+
break;
177+
default:
178+
os << c;
171179
}
172180
}
173181
os << '"';
@@ -179,9 +187,14 @@ void print_as_json(json_printer &printer, const char *value)
179187
}
180188

181189
void print_as_json(json_printer &printer, bool value)
182-
{ printer.ostream() << (value ? "true" : "false"); }
190+
{
191+
printer.ostream() << (value ? "true" : "false");
192+
}
183193

184-
void print_as_json(json_printer &printer, std::nullptr_t) { printer.ostream() << "null"; }
194+
void print_as_json(json_printer &printer, std::nullptr_t)
195+
{
196+
printer.ostream() << "null";
197+
}
185198

186199
void print_as_json(json_printer &printer, json_printer::container_type t)
187200
{
@@ -197,7 +210,9 @@ template <typename T, typename = void>
197210
struct have_custom_printer : std::false_type {};
198211

199212
template <typename T>
200-
struct have_custom_printer<T, void_t<decltype(print_as_json(std::declval<json_printer&>(), std::declval<T>()))>> : std::true_type {};
213+
struct have_custom_printer<
214+
T, void_t<decltype(print_as_json(std::declval<json_printer &>(),
215+
std::declval<T>()))>> : std::true_type {};
201216

202217

203218
template <typename T>

0 commit comments

Comments
 (0)