diff options
Diffstat (limited to 'meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp')
| -rw-r--r-- | meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp b/meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp new file mode 100644 index 0000000000..d3dc976864 --- /dev/null +++ b/meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | /* | ||
| 2 | * Copyright OpenEmbedded Contributors | ||
| 3 | * | ||
| 4 | * SPDX-License-Identifier: MIT | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <iostream> | ||
| 8 | #include <string> | ||
| 9 | #include <json-c/json.h> | ||
| 10 | #include "cpp-example-lib.hpp" | ||
| 11 | |||
| 12 | const std::string &CppExample::get_string() | ||
| 13 | { | ||
| 14 | return test_string; | ||
| 15 | } | ||
| 16 | |||
| 17 | const char *CppExample::get_json_c_version() | ||
| 18 | { | ||
| 19 | return json_c_version(); | ||
| 20 | } | ||
| 21 | |||
| 22 | void CppExample::print_json() | ||
| 23 | { | ||
| 24 | struct json_object *jobj; | ||
| 25 | const int flag = JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY; | ||
| 26 | |||
| 27 | jobj = json_object_new_object(); | ||
| 28 | json_object_object_add(jobj, "test_string", json_object_new_string(test_string.c_str())); | ||
| 29 | |||
| 30 | std::cout << json_object_to_json_string_ext(jobj, flag) << std::endl; | ||
| 31 | |||
| 32 | json_object_put(jobj); // Delete the json object | ||
| 33 | } | ||
