Directory: | ./ |
---|---|
File: | include/hpp/core/parser/roadmap.hh |
Date: | 2024-12-13 16:14:03 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 17 | 17 | 100.0% |
Branches: | 5 | 10 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright (c) 2020 CNRS | ||
2 | // Authors: Joseph Mirabel | ||
3 | // | ||
4 | |||
5 | // Redistribution and use in source and binary forms, with or without | ||
6 | // modification, are permitted provided that the following conditions are | ||
7 | // met: | ||
8 | // | ||
9 | // 1. Redistributions of source code must retain the above copyright | ||
10 | // notice, this list of conditions and the following disclaimer. | ||
11 | // | ||
12 | // 2. Redistributions in binary form must reproduce the above copyright | ||
13 | // notice, this list of conditions and the following disclaimer in the | ||
14 | // documentation and/or other materials provided with the distribution. | ||
15 | // | ||
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
20 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
27 | // DAMAGE. | ||
28 | |||
29 | #ifndef HPP_CORE_PARSER_ROADMAP_HH | ||
30 | #define HPP_CORE_PARSER_ROADMAP_HH | ||
31 | |||
32 | #include <fstream> | ||
33 | #include <hpp/core/roadmap.hh> | ||
34 | #include <hpp/pinocchio/serialization.hh> | ||
35 | |||
36 | namespace hpp { | ||
37 | namespace core { | ||
38 | namespace parser { | ||
39 | namespace internal { | ||
40 | |||
41 | template <typename Parent, typename Child> | ||
42 | struct InsertChildClass : std::pair<std::string, Child*> { | ||
43 | using std::pair<std::string, Child>::pair; | ||
44 | }; | ||
45 | |||
46 | template <class Archive, class A> | ||
47 | 12 | inline void insert(Archive& ar, const std::pair<std::string, A*>& a) { | |
48 | 12 | ar.insert(a.first, a.second); | |
49 | 12 | } | |
50 | |||
51 | template <class Archive, class Parent, class Child> | ||
52 | inline void insert(Archive& ar, const InsertChildClass<Parent, Child>& a) { | ||
53 | ar.template insertChildClass<Parent, Child>(a.first, a.second); | ||
54 | } | ||
55 | |||
56 | template <class Archive> | ||
57 | 12 | inline void inserts(Archive&) {} | |
58 | template <class Archive, class A, class... B> | ||
59 | 12 | inline void inserts(Archive& ar, A& a, B&... b) { | |
60 | 12 | insert(ar, a); | |
61 | 12 | inserts(ar, b...); | |
62 | 12 | } | |
63 | } // namespace internal | ||
64 | |||
65 | /// \addtogroup roadmap | ||
66 | /// \{ | ||
67 | /// \tparam Archive an archive from | ||
68 | /// hpp::serialization::(xml|binary|text)_(i|o)archive. | ||
69 | /// The only requirement is that it derives from | ||
70 | /// hpp::serialization::archive_ptr_holder. | ||
71 | /// \tparam Args a list of std::pair<std::string, Object*> or InsertChildClass | ||
72 | /// \param roadmap the roadmap to save or fill. | ||
73 | /// \param filename the file to read or write. | ||
74 | /// \param args indicate the name and object pointer to insert in the archive | ||
75 | /// pointer holder. | ||
76 | template <class A> | ||
77 | 6 | std::pair<std::string, A*> make_nvp(const std::string& n, A* a) { | |
78 | 6 | return std::pair<std::string, A*>(n, a); | |
79 | } | ||
80 | template <class Parent, class Child> | ||
81 | internal::InsertChildClass<Parent, Child> make_nvp_with_parent( | ||
82 | const std::string& n, Child* a) { | ||
83 | return internal::InsertChildClass<Parent, Child>(n, a); | ||
84 | } | ||
85 | |||
86 | template <class Archive, class... Args> | ||
87 | 12 | void serializeRoadmap(RoadmapPtr_t& roadmap, const std::string& filename, | |
88 | Args... args) { | ||
89 | typename std::conditional<Archive::is_saving::value, std::ofstream, | ||
90 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
12 | std::ifstream>::type fs(filename); |
91 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
12 | Archive ar(fs); |
92 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
12 | internal::inserts(ar, args...); |
93 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
12 | ar.initialize(); |
94 |
1/2✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | ar& hpp::serialization::make_nvp("roadmap", roadmap); |
95 | 12 | } | |
96 | /// \} | ||
97 | } // namespace parser | ||
98 | } // namespace core | ||
99 | } // namespace hpp | ||
100 | #endif // HPP_CORE_PARSER_ROADMAP_HH | ||
101 |