-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
116 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
|
||
#include "cereal/archives/json.hpp" | ||
#include "cereal/types/memory.hpp" | ||
#include "cereal/types/string.hpp" | ||
#include "cereal/types/unordered_map.hpp" | ||
|
||
using namespace std; | ||
|
||
struct MyRecord { | ||
int x, y; | ||
float z; | ||
|
||
template <class Archive> | ||
void serialize(Archive& ar) { | ||
ar(CEREAL_NVP(x), CEREAL_NVP(y), CEREAL_NVP(z)); | ||
} | ||
|
||
friend std::ostream& operator<<(std::ostream& os, const MyRecord& mr); | ||
}; | ||
|
||
std::ostream& operator<<(std::ostream& os, const MyRecord& mr) { | ||
os << "MyRecord(" << mr.x << ", " << mr.y << "," << mr.z << ")\n"; | ||
return os; | ||
} | ||
|
||
struct SomeData { | ||
int32_t id; | ||
std::shared_ptr<std::unordered_map<uint32_t, MyRecord>> data; | ||
|
||
SomeData(int32_t id_ = 0) : id(id_), data(new std::unordered_map<uint32_t, MyRecord>) {} | ||
|
||
template <class Archive> | ||
void save(Archive& ar) const { | ||
ar(CEREAL_NVP(id), CEREAL_NVP(data)); | ||
} | ||
|
||
template <class Archive> | ||
void load(Archive& ar) { | ||
ar(id, data); | ||
} | ||
|
||
void push(uint32_t, const MyRecord& mr) { data->insert(std::make_pair(100, mr)); } | ||
|
||
void print() { | ||
std::cout << "ID : " << id << "\n"; | ||
if (data->empty()) return; | ||
for (auto& item : *data) { | ||
std::cout << item.first << "\t" << item.second << "\n"; | ||
} | ||
} | ||
}; | ||
|
||
void test() { | ||
{ | ||
std::ofstream os("obj.json"); | ||
cereal::JSONOutputArchive archive(os); | ||
|
||
MyRecord mr = {1, 2, 3.0}; | ||
|
||
SomeData myData(1111); | ||
myData.push(100, mr); | ||
|
||
archive(myData); | ||
} | ||
{ | ||
std::ifstream is("obj.json"); | ||
cereal::JSONInputArchive archive(is); | ||
|
||
SomeData myData; | ||
archive(myData); | ||
myData.print(); | ||
} | ||
} | ||
|
||
int main() { | ||
test(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
add_requires("raylib") | ||
add_requires("catch2") | ||
add_requires("spdlog") | ||
add_requires("cereal") | ||
|
||
target("test_raylib") | ||
set_kind("binary") | ||
add_files("test_raylib.cpp") | ||
add_packages("raylib") | ||
|
||
|
||
target("test_catch2") | ||
set_kind("binary") | ||
add_files("test_catch2.cpp") | ||
add_packages("catch2") | ||
|
||
|
||
target("test_spdlog") | ||
set_kind("binary") | ||
add_files("test_spdlog.cpp") | ||
add_packages("spdlog") | ||
|
||
target("test_cereal") | ||
set_kind("binary") | ||
add_files("test_cereal.cpp") | ||
add_packages("cereal") | ||
set_languages("c++17") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,18 @@ | ||
|
||
|
||
add_requires("raylib") | ||
add_requires("catch2") | ||
add_requires("spdlog") | ||
|
||
|
||
add_repositories("my-repo myrepo") | ||
add_requires("raylibx") | ||
|
||
add_rules("mode.debug", "mode.release") | ||
|
||
target("test_raylib") | ||
set_kind("binary") | ||
add_files("tests/test_raylib.cpp") | ||
add_packages("raylib") | ||
|
||
|
||
target("test_catch2") | ||
set_kind("binary") | ||
add_files("tests/test_catch2.cpp") | ||
add_packages("catch2") | ||
|
||
|
||
target("test_spdlog") | ||
set_kind("binary") | ||
add_files("tests/test_spdlog.cpp") | ||
add_packages("spdlog") | ||
|
||
includes("tests/") | ||
|
||
includes("src/") | ||
|
||
|
||
target("test_jsoncpp") | ||
set_kind("binary") | ||
add_files("tmp.cpp") | ||
add_packages("raylibx") | ||
-- target("test_jsoncpp") | ||
-- set_kind("binary") | ||
-- add_files("tmp.cpp") | ||
-- add_packages("raylibx") |