/usr/include/choreonoid-1.1/cnoid/src/Util/EigenYaml.h is in libcnoid-dev 1.1.0+dfsg-6.1+b4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | /**
@author Shin'ichiro Nakaoka
*/
#ifndef CNOID_UTIL_YAML_EIGEN_H_INCLUDED
#define CNOID_UTIL_YAML_EIGEN_H_INCLUDED
#include "YamlNodes.h"
#include <Eigen/Core>
namespace cnoid {
template<typename Derived>
bool read(const YamlMapping& mapping, const std::string& key, Eigen::MatrixBase<Derived>& x)
{
const YamlSequence& s = *mapping.findSequence(key);
if(s.isValid()){
const int nr = x.rows();
const int nc = x.cols();
const int n = s.size();
int index = 0;
if(n > 0){
for(int i=0; i < nr; ++i){
for(int j=0; j < nc; ++j){
x(i, j) = s[index++].toDouble();
if(index == n){
break;
}
}
}
}
return (index == nr * nc);
}
return false;
}
template<typename Derived>
inline void readEx(const YamlMapping& mapping, const std::string& key, Eigen::MatrixBase<Derived>& x)
{
if(!read(mapping, key, x)){
mapping.throwKeyNotFoundException(key);
}
}
template<typename Derived>
YamlSequence& write(YamlMapping& mapping, const std::string& key, const Eigen::MatrixBase<Derived>& x)
{
YamlSequence& s = *mapping.createFlowStyleSequence(key);
const int nr = x.rows();
const int nc = x.cols();
if(nc == 1){
for(int i=0; i < nr; ++i){
s.append(x(i));
}
} else {
for(int i=0; i < nr; ++i){
s.appendLF();
for(int j=0; j < nc; ++j){
s.append(x(i, j));
}
}
}
return s;
}
}
#endif
|