Skip to content

Commit 870c6a6

Browse files
committed
Format
1 parent 764bbda commit 870c6a6

File tree

4 files changed

+87
-83
lines changed

4 files changed

+87
-83
lines changed

include/dynamic-graph/command-bind.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,9 @@ makeCommandReturnType0(E &entity, ReturnType (E::*function)(void),
433433
}
434434

435435
template <typename ReturnType>
436-
inline std::string docCommandReturnType0(const std::string &doc,
437-
const std::string & /* return_type */) {
436+
inline std::string
437+
docCommandReturnType0(const std::string &doc,
438+
const std::string & /* return_type */) {
438439
return std::string("\n") + doc + "\n\nNo input.\n" +
439440
typeid(ReturnType).name() + " return.\n\n";
440441
}

include/dynamic-graph/signal-caster.h

Lines changed: 80 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,92 +12,94 @@
1212

1313
#include "dynamic-graph/exception-signal.h"
1414
#include <dynamic-graph/dynamic-graph-api.h>
15-
#include <dynamic-graph/linear-algebra.h>
1615
#include <dynamic-graph/eigen-io.h>
16+
#include <dynamic-graph/linear-algebra.h>
1717

1818
namespace dynamicgraph {
1919

2020
/// Inherit from this class if you want to keep default implementation for some
2121
/// functions.
2222
template <typename T> struct signal_io_base {
23-
/// serialize a signal value.
24-
inline static void disp (const T &value, std::ostream &os) { os << value; }
25-
/// deserialize a signal value.
26-
inline static T cast (std::istringstream &is) {
27-
T inst;
28-
is >> inst;
29-
if (is.fail()) {
30-
throw ExceptionSignal(ExceptionSignal::GENERIC,
31-
"failed to serialize " + is.str());
23+
/// serialize a signal value.
24+
inline static void disp(const T &value, std::ostream &os) { os << value; }
25+
/// deserialize a signal value.
26+
inline static T cast(std::istringstream &is) {
27+
T inst;
28+
is >> inst;
29+
if (is.fail()) {
30+
throw ExceptionSignal(ExceptionSignal::GENERIC,
31+
"failed to serialize " + is.str());
32+
}
33+
return inst;
3234
}
33-
return inst;
34-
}
35-
/// write a signal value to log file
36-
inline static void trace(const T &value, std::ostream &os) { os << value; }
35+
/// write a signal value to log file
36+
inline static void trace(const T &value, std::ostream &os) { os << value; }
3737
};
3838

3939
/// Inherit from this class if tracing is not implemented for a given type.
4040
template <typename T> struct signal_io_unimplemented {
41-
inline static void disp (const T &, std::ostream &) {
42-
throw std::logic_error("this disp is not implemented.");
43-
}
44-
inline static T cast (std::istringstream &) {
45-
throw std::logic_error("this cast is not implemented.");
46-
}
47-
inline static void trace(const T &, std::ostream &) {
48-
throw std::logic_error("this trace is not implemented.");
49-
}
41+
inline static void disp(const T &, std::ostream &) {
42+
throw std::logic_error("this disp is not implemented.");
43+
}
44+
inline static T cast(std::istringstream &) {
45+
throw std::logic_error("this cast is not implemented.");
46+
}
47+
inline static void trace(const T &, std::ostream &) {
48+
throw std::logic_error("this trace is not implemented.");
49+
}
5050
};
5151

5252
/// Class used for I/O operations in Signal<T,Time>
5353
template <typename T> struct signal_io : signal_io_base<T> {};
5454

5555
/// Template specialization of signal_disp for Eigen objects
56-
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
57-
struct signal_io<Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >
58-
: signal_io_base <Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >
59-
{
60-
typedef Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > matrix_type;
61-
62-
inline static void disp(const matrix_type &value, std::ostream &os) {
63-
static const Eigen::IOFormat row_format (Eigen::StreamPrecision,
64-
Eigen::DontAlignCols, " ", " ", "", "", "", "");
65-
os << value.format(row_format);
66-
}
67-
68-
inline static void trace(const matrix_type &value, std::ostream &os) {
69-
static const Eigen::IOFormat row_format (Eigen::StreamPrecision,
70-
Eigen::DontAlignCols, "\t", "\t", "", "", "", "");
71-
os << value.format(row_format);
72-
}
56+
template <typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows,
57+
int _MaxCols>
58+
struct signal_io<
59+
Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>>
60+
: signal_io_base<
61+
Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>> {
62+
typedef Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
63+
matrix_type;
64+
65+
inline static void disp(const matrix_type &value, std::ostream &os) {
66+
static const Eigen::IOFormat row_format(
67+
Eigen::StreamPrecision, Eigen::DontAlignCols, " ", " ", "", "", "", "");
68+
os << value.format(row_format);
69+
}
70+
71+
inline static void trace(const matrix_type &value, std::ostream &os) {
72+
static const Eigen::IOFormat row_format(Eigen::StreamPrecision,
73+
Eigen::DontAlignCols, "\t", "\t",
74+
"", "", "", "");
75+
os << value.format(row_format);
76+
}
7377
};
7478

7579
/// Template specialization of signal_io for Eigen quaternion objects
76-
template<typename _Scalar, int _Options>
77-
struct signal_io<Eigen::Quaternion< _Scalar, _Options> >
78-
: signal_io_base<Eigen::Quaternion< _Scalar, _Options> >
79-
{
80-
typedef Eigen::Quaternion< _Scalar, _Options> quat_type;
81-
typedef Eigen::Matrix< _Scalar, 4, 1, _Options> matrix_type;
82-
83-
inline static void disp(const quat_type &value, std::ostream &os) {
84-
signal_io<matrix_type>::disp(value.coeffs(), os);
85-
}
86-
87-
inline static quat_type cast (std::istringstream &is) {
88-
return quat_type(signal_io<matrix_type>::cast(is));
89-
}
90-
91-
inline static void trace(const quat_type &value, std::ostream &os) {
92-
signal_io<matrix_type>::trace(value.coeffs(), os);
93-
}
80+
template <typename _Scalar, int _Options>
81+
struct signal_io<Eigen::Quaternion<_Scalar, _Options>>
82+
: signal_io_base<Eigen::Quaternion<_Scalar, _Options>> {
83+
typedef Eigen::Quaternion<_Scalar, _Options> quat_type;
84+
typedef Eigen::Matrix<_Scalar, 4, 1, _Options> matrix_type;
85+
86+
inline static void disp(const quat_type &value, std::ostream &os) {
87+
signal_io<matrix_type>::disp(value.coeffs(), os);
88+
}
89+
90+
inline static quat_type cast(std::istringstream &is) {
91+
return quat_type(signal_io<matrix_type>::cast(is));
92+
}
93+
94+
inline static void trace(const quat_type &value, std::ostream &os) {
95+
signal_io<matrix_type>::trace(value.coeffs(), os);
96+
}
9497
};
9598

9699
/// Template specialization of signal_io for std::string.
97100
/// Do not print '\n' at the end.
98-
template <> struct signal_io<std::string> : signal_io_base<std::string>
99-
{
100-
inline static std::string cast (std::istringstream &iss) { return iss.str(); }
101+
template <> struct signal_io<std::string> : signal_io_base<std::string> {
102+
inline static std::string cast(std::istringstream &iss) { return iss.str(); }
101103
};
102104

103105
/// Template specialization of signal_io for double
@@ -113,24 +115,24 @@ inline static std::string cast (std::istringstream &iss) { return iss.str(); }
113115
/// (the strings used are the one produces by displaying special
114116
/// values on a stream).
115117
template <> struct signal_io<double> : signal_io_base<double> {
116-
inline static double cast (std::istringstream &iss) {
117-
std::string tmp (iss.str());
118-
119-
if (tmp == "nan")
120-
return std::numeric_limits<double>::quiet_NaN();
121-
else if (tmp == "inf" || tmp == "+inf")
122-
return std::numeric_limits<double>::infinity();
123-
else if (tmp == "-inf")
124-
return -1. * std::numeric_limits<double>::infinity();
125-
126-
try {
127-
return boost::lexical_cast<double>(tmp);
128-
} catch (boost::bad_lexical_cast &) {
129-
boost::format fmt("failed to serialize %s (to double)");
130-
fmt % tmp;
131-
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
118+
inline static double cast(std::istringstream &iss) {
119+
std::string tmp(iss.str());
120+
121+
if (tmp == "nan")
122+
return std::numeric_limits<double>::quiet_NaN();
123+
else if (tmp == "inf" || tmp == "+inf")
124+
return std::numeric_limits<double>::infinity();
125+
else if (tmp == "-inf")
126+
return -1. * std::numeric_limits<double>::infinity();
127+
128+
try {
129+
return boost::lexical_cast<double>(tmp);
130+
} catch (boost::bad_lexical_cast &) {
131+
boost::format fmt("failed to serialize %s (to double)");
132+
fmt % tmp;
133+
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
134+
}
132135
}
133-
}
134136
};
135137

136138
} // end of namespace dynamicgraph.

src/mt/process-list.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void System::readProcStat() {
141141
if (!init_) {
142142
/// The number of CPU has been detected by going through /proc/stat.
143143
vCPUData_.resize(cpuNb_ + 1);
144-
for (unsigned long i = 0; i < (unsigned long )cpuNb_; i++)
144+
for (unsigned long i = 0; i < (unsigned long)cpuNb_; i++)
145145
vCPUData_[i].cpu_id_ = (int)i;
146146
}
147147
aif.close();

tests/debug-tracer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ struct MyEntity : public dynamicgraph::Entity {
4242
"MyEntity(" + name + ")::input(double)::out2double")
4343

4444
{
45-
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT << m_sigVTimeDepSOUT << m_sigdTwoTimeDepSOUT);
45+
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT << m_sigVTimeDepSOUT
46+
<< m_sigdTwoTimeDepSOUT);
4647
}
4748

4849
virtual void display(std::ostream &os) const {
@@ -60,7 +61,7 @@ struct MyEntity : public dynamicgraph::Entity {
6061
Vector &updateVector(Vector &res, const int &inTime) {
6162
const double &aDouble = m_sigdSIN(inTime);
6263
res.resize(2);
63-
res << aDouble, 2*aDouble;
64+
res << aDouble, 2 * aDouble;
6465
return res;
6566
}
6667
};

0 commit comments

Comments
 (0)