Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cberge/dynamic-graph
  • ostasse/dynamic-graph
  • gsaurel/dynamic-graph
  • stack-of-tasks/dynamic-graph
4 results
Show changes
Showing
with 433 additions and 340 deletions
......@@ -5,6 +5,7 @@
//
#include "dynamic-graph/value.h"
#include "dynamic-graph/exception-abstract.h"
namespace dynamicgraph {
......@@ -21,7 +22,11 @@ EitherType::~EitherType() {
EitherType::operator bool() const { return value_->boolValue(); }
EitherType::operator unsigned() const { return value_->unsignedValue(); }
EitherType::operator unsigned long int() const {
return value_->unsignedlongintValue();
}
EitherType::operator int() const { return value_->intValue(); }
EitherType::operator long int() const { return value_->longintValue(); }
EitherType::operator float() const { return value_->floatValue(); }
EitherType::operator double() const { return value_->doubleValue(); }
EitherType::operator std::string() const { return value_->stringValue(); }
......@@ -33,37 +38,47 @@ EitherType::operator Values() const { return value_->valuesValue(); }
void Value::deleteValue() {
switch (type_) {
case BOOL:
delete (const bool *)value_;
break;
case UNSIGNED:
delete (const unsigned *)value_;
break;
case INT:
delete (const int *)value_;
break;
case FLOAT:
delete (const float *)value_;
break;
case DOUBLE:
delete (const double *)value_;
break;
case STRING:
delete (const std::string *)value_;
break;
case VECTOR:
delete (const Vector *)value_;
break;
case MATRIX:
delete (const Eigen::MatrixXd *)value_;
break;
case MATRIX4D:
delete (const Eigen::Matrix4d *)value_;
break;
case VALUES:
delete (const Values *)value_;
break;
default:;
case BOOL:
delete (const bool *)value_;
break;
case UNSIGNED:
delete (const unsigned *)value_;
break;
case UNSIGNEDLONGINT:
delete (const unsigned long int *)value_;
break;
case INT:
delete (const int *)value_;
break;
case LONGINT:
delete (const long int *)value_;
break;
case FLOAT:
delete (const float *)value_;
break;
case DOUBLE:
delete (const double *)value_;
break;
case STRING:
delete (const std::string *)value_;
break;
case VECTOR:
delete (const Vector *)value_;
break;
case MATRIX:
delete (const Eigen::MatrixXd *)value_;
break;
case MATRIX4D:
delete (const Eigen::Matrix4d *)value_;
break;
case VALUES:
delete (const Values *)value_;
break;
case NONE: /* Equivalent to void */
break;
default:
throw "Value::deleteValue : Undefined type";
;
}
}
......@@ -72,6 +87,8 @@ Value::~Value() { deleteValue(); }
Value::Value(const bool &value) : type_(BOOL), value_(new bool(value)) {}
Value::Value(const unsigned &value)
: type_(UNSIGNED), value_(new unsigned(value)) {}
Value::Value(const unsigned long int &value)
: type_(UNSIGNEDLONGINT), value_(new unsigned long int(value)) {}
Value::Value(const int &value) : type_(INT), value_(new int(value)) {}
Value::Value(const float &value) : type_(FLOAT), value_(new float(value)) {}
Value::Value(const double &value) : type_(DOUBLE), value_(new double(value)) {}
......@@ -90,42 +107,47 @@ Value::Value(const Value &value)
void *copyValue(const Value &value) {
void *copy;
switch (value.type()) {
case Value::NONE:
copy = NULL;
break;
case Value::BOOL:
copy = new bool(value.boolValue());
break;
case Value::UNSIGNED:
copy = new unsigned(value.unsignedValue());
break;
case Value::INT:
copy = new int(value.intValue());
break;
case Value::FLOAT:
copy = new float(value.floatValue());
break;
case Value::DOUBLE:
copy = new double(value.doubleValue());
break;
case Value::STRING:
copy = new std::string(value.stringValue());
break;
case Value::VECTOR:
copy = new Vector(value.vectorValue());
break;
case Value::MATRIX:
copy = new Eigen::MatrixXd(value.matrixXdValue());
break;
case Value::MATRIX4D:
copy = new Eigen::Matrix4d(value.matrix4dValue());
break;
case Value::VALUES:
copy = new Values(value.valuesValue());
break;
default:
abort();
case Value::NONE:
copy = NULL;
break;
case Value::BOOL:
copy = new bool(value.boolValue());
break;
case Value::UNSIGNED:
copy = new unsigned(value.unsignedValue());
break;
case Value::UNSIGNEDLONGINT:
copy = new unsigned long int(value.unsignedlongintValue());
break;
case Value::INT:
copy = new int(value.intValue());
break;
case Value::LONGINT:
copy = new long int(value.longintValue());
break;
case Value::FLOAT:
copy = new float(value.floatValue());
break;
case Value::DOUBLE:
copy = new double(value.doubleValue());
break;
case Value::STRING:
copy = new std::string(value.stringValue());
break;
case Value::VECTOR:
copy = new Vector(value.vectorValue());
break;
case Value::MATRIX:
copy = new Eigen::MatrixXd(value.matrixXdValue());
break;
case Value::MATRIX4D:
copy = new Eigen::Matrix4d(value.matrix4dValue());
break;
case Value::VALUES:
copy = new Values(value.valuesValue());
break;
default:
abort();
}
return copy;
}
......@@ -134,8 +156,7 @@ Value::Value() : type_(NONE), value_(NULL) {}
Value Value::operator=(const Value &value) {
if (&value != this) {
if (value_ != 0x0)
deleteValue();
if (value_ != 0x0) deleteValue();
type_ = value.type_;
void **ptValue = const_cast<void **>(&value_);
*ptValue = copyValue(value);
......@@ -144,33 +165,34 @@ Value Value::operator=(const Value &value) {
}
bool Value::operator==(const Value &other) const {
if (type_ != other.type_)
return false;
if (type_ != other.type_) return false;
switch (type_) {
case Value::BOOL:
return boolValue() == other.boolValue();
case Value::UNSIGNED:
return unsignedValue() == other.unsignedValue();
case Value::INT:
return intValue() == other.intValue();
case Value::DOUBLE:
return doubleValue() == other.doubleValue();
case Value::FLOAT:
return floatValue() == other.floatValue();
case Value::STRING:
return stringValue() == other.stringValue();
case Value::VECTOR:
return vectorValue() == other.vectorValue();
case Value::MATRIX:
return matrixXdValue() == other.matrixXdValue();
case Value::MATRIX4D:
return matrix4dValue() == other.matrix4dValue();
case Value::VALUES:
return constValuesValue() == other.constValuesValue();
case Value::NONE:
break;
default:
break;
case Value::BOOL:
return boolValue() == other.boolValue();
case Value::UNSIGNED:
return unsignedValue() == other.unsignedValue();
case Value::UNSIGNEDLONGINT:
return unsignedlongintValue() == other.unsignedlongintValue();
case Value::INT:
return intValue() == other.intValue();
case Value::DOUBLE:
return doubleValue() == other.doubleValue();
case Value::FLOAT:
return floatValue() == other.floatValue();
case Value::STRING:
return stringValue() == other.stringValue();
case Value::VECTOR:
return vectorValue() == other.vectorValue();
case Value::MATRIX:
return matrixXdValue() == other.matrixXdValue();
case Value::MATRIX4D:
return matrix4dValue() == other.matrix4dValue();
case Value::VALUES:
return constValuesValue() == other.constValuesValue();
case Value::NONE:
break;
default:
break;
}
return false;
}
......@@ -180,22 +202,30 @@ const EitherType Value::value() const { return EitherType(*this); }
Value::Type Value::type() const { return type_; }
bool Value::boolValue() const {
if (type_ == BOOL)
return *((const bool *)value_);
if (type_ == BOOL) return *((const bool *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an bool");
}
unsigned Value::unsignedValue() const {
if (type_ == UNSIGNED)
return *((const unsigned *)value_);
if (type_ == UNSIGNED) return *((const unsigned *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not an unsigned int");
}
unsigned long int Value::unsignedlongintValue() const {
if (type_ == UNSIGNEDLONGINT) return *((const unsigned long int *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not an unsigned long int");
}
long int Value::longintValue() const {
if (type_ == LONGINT) return *((const long int *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an long int");
}
int Value::intValue() const {
if (type_ == INT)
return *((const int *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an int int");
if (type_ == INT) return *((const int *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an int");
}
float Value::floatValue() const {
......@@ -215,127 +245,138 @@ double Value::doubleValue() const {
}
std::string Value::stringValue() const {
if (type_ == STRING)
return *((const std::string *)value_);
if (type_ == STRING) return *((const std::string *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an string");
}
Vector Value::vectorValue() const {
if (type_ == VECTOR)
return *((const Vector *)value_);
if (type_ == VECTOR) return *((const Vector *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an vector");
}
Eigen::MatrixXd Value::matrixXdValue() const {
if (type_ == MATRIX)
return *((const Eigen::MatrixXd *)value_);
if (type_ == MATRIX) return *((const Eigen::MatrixXd *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not a Eigen matrixXd");
}
Eigen::Matrix4d Value::matrix4dValue() const {
if (type_ == MATRIX4D)
return *((const Eigen::Matrix4d *)value_);
if (type_ == MATRIX4D) return *((const Eigen::Matrix4d *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not a Eigen matrix4d");
}
Values Value::valuesValue() const {
if (type_ == VALUES)
return *((const Values *)value_);
if (type_ == VALUES) return *((const Values *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not a vector of Value");
}
const Values &Value::constValuesValue() const {
if (type_ == VALUES)
return *((const Values *)value_);
if (type_ == VALUES) return *((const Values *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not a vector of Value");
}
std::string Value::typeName(Type type) {
switch (type) {
case BOOL:
return std::string("bool");
case UNSIGNED:
return std::string("unsigned int");
case INT:
return std::string("int");
case FLOAT:
return std::string("float");
case DOUBLE:
return std::string("double");
case STRING:
return std::string("string");
case VECTOR:
return std::string("vector");
case MATRIX:
return std::string("matrixXd");
case MATRIX4D:
return std::string("matrix4d");
case VALUES:
return std::string("values");
default:
return std::string("unknown");
case BOOL:
return std::string("bool");
case UNSIGNED:
return std::string("unsigned int");
case UNSIGNEDLONGINT:
return std::string("unsigned long int");
case INT:
return std::string("int");
case FLOAT:
return std::string("float");
case DOUBLE:
return std::string("double");
case STRING:
return std::string("string");
case VECTOR:
return std::string("vector");
case MATRIX:
return std::string("matrixXd");
case MATRIX4D:
return std::string("matrix4d");
case VALUES:
return std::string("values");
default:
return std::string("unknown");
}
}
std::ostream &operator<<(std::ostream &os, const Value &value) {
os << "Type=" << Value::typeName(value.type_) << ", value=";
switch (value.type_) {
case Value::BOOL:
os << value.boolValue();
break;
case Value::UNSIGNED:
os << value.unsignedValue();
break;
case Value::INT:
os << value.intValue();
break;
case Value::DOUBLE:
os << value.doubleValue();
break;
case Value::FLOAT:
os << value.floatValue();
break;
case Value::STRING:
os << value.stringValue();
break;
case Value::VECTOR:
os << value.vectorValue();
break;
case Value::MATRIX:
os << value.matrixXdValue();
break;
case Value::MATRIX4D:
os << value.matrix4dValue();
break;
case Value::VALUES: {
const std::vector<Value> &vals = value.constValuesValue();
os << "[ ";
for (std::size_t i = 0; i < vals.size(); ++i)
os << "Value(" << vals[i] << "), ";
os << "]";
} break;
default:
return os;
case Value::BOOL:
os << value.boolValue();
break;
case Value::UNSIGNED:
os << value.unsignedValue();
break;
case Value::UNSIGNEDLONGINT:
os << value.unsignedlongintValue();
break;
case Value::INT:
os << value.intValue();
break;
case Value::DOUBLE:
os << value.doubleValue();
break;
case Value::FLOAT:
os << value.floatValue();
break;
case Value::STRING:
os << value.stringValue();
break;
case Value::VECTOR:
os << value.vectorValue();
break;
case Value::MATRIX:
os << value.matrixXdValue();
break;
case Value::MATRIX4D:
os << value.matrix4dValue();
break;
case Value::VALUES: {
const std::vector<Value> &vals = value.constValuesValue();
os << "[ ";
for (std::size_t i = 0; i < vals.size(); ++i)
os << "Value(" << vals[i] << "), ";
os << "]";
} break;
default:
return os;
}
return os;
}
template <> const Value::Type ValueHelper<bool>::TypeID = Value::BOOL;
template <> const Value::Type ValueHelper<unsigned>::TypeID = Value::UNSIGNED;
template <> const Value::Type ValueHelper<int>::TypeID = Value::INT;
template <> const Value::Type ValueHelper<float>::TypeID = Value::FLOAT;
template <> const Value::Type ValueHelper<double>::TypeID = Value::DOUBLE;
template <> const Value::Type ValueHelper<std::string>::TypeID = Value::STRING;
template <> const Value::Type ValueHelper<Vector>::TypeID = Value::VECTOR;
template <>
const Value::Type ValueHelper<bool>::TypeID = Value::BOOL;
template <>
const Value::Type ValueHelper<unsigned>::TypeID = Value::UNSIGNED;
template <>
const Value::Type ValueHelper<unsigned long int>::TypeID =
Value::UNSIGNEDLONGINT;
template <>
const Value::Type ValueHelper<int>::TypeID = Value::INT;
template <>
const Value::Type ValueHelper<float>::TypeID = Value::FLOAT;
template <>
const Value::Type ValueHelper<double>::TypeID = Value::DOUBLE;
template <>
const Value::Type ValueHelper<std::string>::TypeID = Value::STRING;
template <>
const Value::Type ValueHelper<Vector>::TypeID = Value::VECTOR;
template <>
const Value::Type ValueHelper<Eigen::MatrixXd>::TypeID = Value::MATRIX;
template <>
const Value::Type ValueHelper<Eigen::Matrix4d>::TypeID = Value::MATRIX4D;
template <> const Value::Type ValueHelper<Values>::TypeID = Value::VALUES;
template <>
const Value::Type ValueHelper<Values>::TypeID = Value::VALUES;
} // namespace command
} // namespace dynamicgraph
} // namespace command
} // namespace dynamicgraph
......@@ -8,6 +8,7 @@
*/
#include <dynamic-graph/debug.h>
#include <fstream>
#include <ios>
......@@ -32,7 +33,7 @@ std::ofstream dg_debugfile("/tmp/dynamic-graph-traces.txt",
#else
std::ofstream dg_debugfile;
class dgDebug_init {
public:
public:
dgDebug_init() { dg_debugfile.setstate(std::ios::failbit); }
};
dgDebug_init dgDebug_initialisator;
......@@ -42,11 +43,10 @@ dgDebug_init dgDebug_initialisator;
namespace dynamicgraph {
DebugTrace dgDEBUGFLOW(dg_debugfile);
DebugTrace dgERRORFLOW(dg_debugfile);
} // namespace dynamicgraph
} // namespace dynamicgraph
void DebugTrace::openFile(const char *filename) {
if (dg_debugfile.good() && dg_debugfile.is_open())
dg_debugfile.close();
if (dg_debugfile.good() && dg_debugfile.is_open()) dg_debugfile.close();
dg_debugfile.clear();
dg_debugfile.open(filename, std::ios::trunc & std::ios::out);
}
......
......@@ -13,17 +13,18 @@
#define ENABLE_RT_LOG
#include <dynamic-graph/logger.h>
#include <iomanip> // std::setprecision
#include <iostream>
#include <sstream>
#include <dynamic-graph/real-time-logger.h>
#include <stdio.h>
#include <dynamic-graph/real-time-logger.h>
#include <iomanip> // std::setprecision
#include <iostream>
#include <sstream>
namespace dynamicgraph {
Logger::Logger(double timeSample, double streamPrintPeriod)
: m_timeSample(timeSample), m_streamPrintPeriod(streamPrintPeriod),
: m_timeSample(timeSample),
m_streamPrintPeriod(streamPrintPeriod),
m_printCountdown(0.0) {
m_lv = VERBOSITY_ERROR;
}
......@@ -34,8 +35,7 @@ void Logger::setVerbosity(LoggerVerbosity lv) { m_lv = lv; }
LoggerVerbosity Logger::getVerbosity() { return m_lv; }
void Logger::countdown() {
if (m_printCountdown < 0.0)
m_printCountdown = m_streamPrintPeriod;
if (m_printCountdown < 0.0) m_printCountdown = m_streamPrintPeriod;
m_printCountdown -= m_timeSample;
}
......@@ -51,15 +51,13 @@ void Logger::sendMsg(std::string msg, MsgType type, const std::string &file,
}
bool Logger::setTimeSample(double t) {
if (t <= 0.0)
return false;
if (t <= 0.0) return false;
m_timeSample = t;
return true;
}
bool Logger::setStreamPrintPeriod(double s) {
if (s <= 0.0)
return false;
if (s <= 0.0) return false;
m_streamPrintPeriod = s;
return true;
}
......@@ -79,9 +77,9 @@ bool Logger::checkStreamPeriod(const std::string &lineId) {
counter -= m_timeSample;
if (counter > 0.0) {
return false;
} else // otherwise reset counter and print
} else // otherwise reset counter and print
counter = m_streamPrintPeriod;
return true;
}
} // namespace dynamicgraph
} // namespace dynamicgraph
......@@ -13,21 +13,21 @@
namespace dynamicgraph {
RealTimeLogger::RealTimeLogger(const std::size_t &bufferSize)
: buffer_(bufferSize, NULL), frontIdx_(0), backIdx_(0), oss_(NULL),
: buffer_(bufferSize, NULL),
frontIdx_(0),
backIdx_(0),
oss_(NULL),
nbDiscarded_(0) {
for (std::size_t i = 0; i < buffer_.size(); ++i)
buffer_[i] = new Data;
for (std::size_t i = 0; i < buffer_.size(); ++i) buffer_[i] = new Data;
}
RealTimeLogger::~RealTimeLogger() {
// Check that we are not spinning...
for (std::size_t i = 0; i < buffer_.size(); ++i)
delete buffer_[i];
for (std::size_t i = 0; i < buffer_.size(); ++i) delete buffer_[i];
}
bool RealTimeLogger::spinOnce() {
if (empty())
return false;
if (empty()) return false;
Data *data = buffer_[frontIdx_];
frontIdx_ = (frontIdx_ + 1) % buffer_.size();
std::string str = data->buf.str();
......@@ -67,8 +67,11 @@ struct RealTimeLogger::thread {
boost::thread t_;
explicit thread(RealTimeLogger *logger)
: requestShutdown_(false), threadPolicy_(SCHED_OTHER), threadPriority_(0),
changedThreadParams(true), t_(&thread::spin, this, logger) {}
: requestShutdown_(false),
threadPolicy_(SCHED_OTHER),
threadPriority_(0),
changedThreadParams(true),
t_(&thread::spin, this, logger) {}
// void setThreadPolicy(int policy) {
// threadPolicy_ = policy;
......@@ -107,8 +110,7 @@ struct RealTimeLogger::thread {
// Do a pause
if (!logger->spinOnce())
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
if (changedThreadParams)
changeThreadParams();
if (changedThreadParams) changeThreadParams();
}
}
};
......@@ -125,11 +127,10 @@ RealTimeLogger &RealTimeLogger::instance() {
}
void RealTimeLogger::destroy() {
if (instance_ == NULL)
return;
if (instance_ == NULL) return;
thread_->requestShutdown_ = true;
thread_->t_.join();
delete instance_;
delete thread_;
}
} // namespace dynamicgraph
} // namespace dynamicgraph
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.