GCC Code Coverage Report


Directory: ./
File: include/multicontact-api/serialization/eigen-matrix.hpp
Date: 2025-03-10 16:17:01
Exec Total Coverage
Lines: 15 15 100.0%
Branches: 11 26 42.3%

Line Branch Exec Source
1 // Copyright (c) 2015-2018, CNRS
2 // Authors: Justin Carpentier <jcarpent@laas.fr>
3
4 /*
5 Code adapted from:
6 https://gist.githubusercontent.com/mtao/5798888/raw/5be9fa9b66336c166dba3a92c0e5b69ffdb81501/eigen_boost_serialization.hpp
7 Copyright (c) 2015 Michael Tao
8
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 */
27
28 #ifndef EIGEN_BOOST_SERIALIZATION
29 #define EIGEN_BOOST_SERIALIZATION
30
31 #include <Eigen/Dense>
32 #include <boost/serialization/split_free.hpp>
33 #include <boost/serialization/vector.hpp>
34
35 namespace boost {
36 namespace serialization {
37 template <class Archive, typename _Scalar, int _Rows, int _Cols, int _Options,
38 int _MaxRows, int _MaxCols>
39 1966 void save(
40 Archive& ar,
41 const Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& m,
42 const unsigned int version) {
43 if (version) {
44 // Do something
45 }
46 1966 Eigen::DenseIndex rows(m.rows()), cols(m.cols());
47
1/2
✓ Branch 2 taken 983 times.
✗ Branch 3 not taken.
1966 ar& BOOST_SERIALIZATION_NVP(rows);
48
1/2
✓ Branch 2 taken 983 times.
✗ Branch 3 not taken.
1966 ar& BOOST_SERIALIZATION_NVP(cols);
49
3/8
✓ Branch 2 taken 983 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 983 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 983 times.
✗ Branch 10 not taken.
1966 ar& make_nvp("data", make_array(m.data(), (size_t)m.size()));
50 1966 }
51
52 template <class Archive, typename _Scalar, int _Rows, int _Cols, int _Options,
53 int _MaxRows, int _MaxCols>
54 1966 void load(Archive& ar,
55 Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& m,
56 const unsigned int version) {
57 if (version) {
58 // Do something
59 }
60 Eigen::DenseIndex rows, cols;
61
1/2
✓ Branch 2 taken 983 times.
✗ Branch 3 not taken.
1966 ar >> BOOST_SERIALIZATION_NVP(rows);
62
1/2
✓ Branch 2 taken 983 times.
✗ Branch 3 not taken.
1966 ar >> BOOST_SERIALIZATION_NVP(cols);
63
1/2
✓ Branch 1 taken 983 times.
✗ Branch 2 not taken.
1966 m.resize(rows, cols);
64 // if(m.size() > 0)
65
3/8
✓ Branch 2 taken 983 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 983 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 983 times.
✗ Branch 10 not taken.
1966 ar >> make_nvp("data", make_array(m.data(), (size_t)m.size()));
66 1966 }
67
68 template <class Archive, typename _Scalar, int _Rows, int _Cols, int _Options,
69 int _MaxRows, int _MaxCols>
70 3932 void serialize(
71 Archive& ar,
72 Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& m,
73 const unsigned int version) {
74 3932 split_free(ar, m, version);
75 3932 }
76
77 } // namespace serialization
78 } // namespace boost
79
80 #endif // ifndef __multicontact_api_serialization_eigen_matrix_hpp__
81