Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
TestData.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
16#include "TestData.hpp"
18#include "shambase/string.hpp"
19
20namespace shamtest::details {
21
22 std::string TestData::serialize_json() {
23 std::string acc = "\n{\n";
24
25 acc += R"( "dataset_name" : ")" + dataset_name + "\",\n";
26 acc += R"( "dataset" : )"
27 "\n [\n";
28
29 for (u32 i = 0; i < dataset.size(); i++) {
31 if (i < dataset.size() - 1) {
32 acc += ",";
33 }
34 }
35
36 acc += "]";
37
38 acc += "\n}";
39 return acc;
40 }
41
42 void TestData::serialize(std::basic_stringstream<byte> &stream) {
43 shambase::stream_write_string(stream, dataset_name);
45 }
46
47 TestData TestData::deserialize(std::basic_stringstream<byte> &stream) {
48
49 TestData out;
50
51 shambase::stream_read_string(stream, out.dataset_name);
52 shambase::stream_read_vector(stream, out.dataset);
53
54 return out;
55 }
56
57} // namespace shamtest::details
std::uint32_t u32
32 bit unsigned integer
void stream_read_vector(std::basic_stringstream< byte > &stream, std::vector< T > &vec)
read a vector from the bytestream Note : this appends read objects to the vector without resetting it
std::string increase_indent(std::string in, std::string delim="\n ")
Increase indentation of a string.
Definition string.hpp:197
void stream_write_vector(std::basic_stringstream< byte > &stream, std::vector< T > &vec)
write the vector into the bytestream
implementation details of the test library
Definition DataNode.hpp:23
static TestData deserialize(std::basic_stringstream< byte > &stream)
DeSerialize the assertion from binary format.
std::string serialize_json()
Serialize the assertion in JSON.
std::vector< DataNode > dataset
Dataset.
Definition TestData.hpp:25
std::string dataset_name
Name of the dataset.
Definition TestData.hpp:24
void serialize(std::basic_stringstream< byte > &stream)
Serialize the assertion in binary format.