Skip to content

Commit

Permalink
Issue #7: OCLint fixes for header files
Browse files Browse the repository at this point in the history
  • Loading branch information
branoholy committed Dec 29, 2016
1 parent e9c6c1c commit e815546
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 81 deletions.
5 changes: 4 additions & 1 deletion .oclint
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
disable-rules:
- LongMethod # HighNcssMethod is enough
rule-paths: []
- AvoidDefaultArgumentsOnVirtualMethods
rule-paths:
- /usr/local/lib/oclint/rules
- libs/oclint/oclint-rules/build/rules.dl
rule-configurations:
- key: LONG_LINE
value: 120
52 changes: 31 additions & 21 deletions include/regilo/hokuyocontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ class HokuyoController : public IHokuyoController, public ScanController<Protoco
double startAngle = -135 * M_PI / 180;

protected:
virtual inline std::string getScanCommand() const override { return this->createFormattedCommand(CMD_GET_SCAN, fromStep, toStep, clusterCount); }
virtual bool parseScanData(std::istream& in, ScanData& data) override;
virtual inline std::string getScanCommand() const override
{
return this->createFormattedCommand(CMD_GET_SCAN, fromStep, toStep, clusterCount);
}

virtual bool parseScanData(std::istream& input, ScanData& data) override;

public:
static std::string CMD_GET_VERSION; ///< A command for getting the scanner version.
Expand Down Expand Up @@ -126,45 +130,51 @@ HokuyoController<ProtocolController>::HokuyoController() : ScanController<Protoc
}

template<typename ProtocolController>
HokuyoController<ProtocolController>::HokuyoController(const std::string& logPath) : ScanController<ProtocolController>(logPath)
HokuyoController<ProtocolController>::HokuyoController(const std::string& logPath) :
ScanController<ProtocolController>(logPath)
{
this->RESPONSE_END = "\n\n";
}

template<typename ProtocolController>
HokuyoController<ProtocolController>::HokuyoController(std::iostream& logStream) : ScanController<ProtocolController>(logStream)
HokuyoController<ProtocolController>::HokuyoController(std::iostream& logStream) :
ScanController<ProtocolController>(logStream)
{
this->RESPONSE_END = "\n\n";
}

template<typename ProtocolController>
std::map<std::string, std::string> HokuyoController<ProtocolController>::getVersionInfo()
{
if(ProtocolController::template sendCommand<char>(CMD_GET_VERSION) != '0')
{
return std::map<std::string, std::string>();
}

std::map<std::string, std::string> versionInfo;
std::string line;

if(ProtocolController::template sendCommand<char>(CMD_GET_VERSION) == '0')
while(std::getline(this->deviceOutput, line))
{
std::string line;
while(std::getline(this->deviceOutput, line))
{
if(line.empty()) continue;
if(line.empty()) continue;

std::size_t colonPos = line.find(':');
std::string name = line.substr(0, colonPos);
std::string value = line.substr(colonPos + 1);
std::size_t colonPos = line.find(':');
std::string name = line.substr(0, colonPos);
std::string value = line.substr(colonPos + 1);

boost::algorithm::trim(name);
boost::algorithm::trim(value);
boost::algorithm::trim(name);
boost::algorithm::trim(value);

versionInfo[name] = value;
}
versionInfo[name] = value;
}

return versionInfo;
}

template<typename ProtocolController>
void HokuyoController<ProtocolController>::setScanParameters(std::size_t fromStep, std::size_t toStep, std::size_t clusterCount)
void HokuyoController<ProtocolController>::setScanParameters(
std::size_t fromStep, std::size_t toStep, std::size_t clusterCount
)
{
if(fromStep > maxStep) throw std::invalid_argument("Invalid fromStep argument.");
if(toStep > maxStep) throw std::invalid_argument("Invalid fromStep argument.");
Expand All @@ -177,22 +187,22 @@ void HokuyoController<ProtocolController>::setScanParameters(std::size_t fromSte
}

template<typename ProtocolController>
bool HokuyoController<ProtocolController>::parseScanData(std::istream& in, ScanData& data)
bool HokuyoController<ProtocolController>::parseScanData(std::istream& input, ScanData& data)
{
char status;
in >> status;
input >> status;
if(status != '0') return false;

double resolution = M_PI / 512;

int lastIndex = 0;
std::size_t step = fromStep - 1;
while(in)
while(input)
{
step++;

char high, low;
in >> high >> low;
input >> high >> low;

if(step < validFromStep || step > validToStep) continue;

Expand Down
96 changes: 51 additions & 45 deletions include/regilo/neatocontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

namespace regilo {

namespace balg = boost::algorithm;

/**
* @brief The INeatoController interface is used for the NeatoController class.
*/
Expand Down Expand Up @@ -80,7 +82,8 @@ class INeatoController : public virtual IScanController
/**
* @brief Set the specified motor to run in a direction at a requested speed.
* @param left Distance in millimeters to drive the left wheel (pos = forward, neg = backward).
* @param right Distance in millimeters to drive the right wheel (pos = forward, neg = backward).
* @param right Distance in millimeters to drive the right wheel (pos = forward,
* neg = backward).
* @param speed Speed in millimeters/second.
*/
virtual void setMotor(int left, int right, int speed) = 0;
Expand All @@ -104,11 +107,11 @@ class NeatoController : public INeatoController, public ScanController<ProtocolC

protected:
virtual inline std::string getScanCommand() const override { return CMD_GET_LDS_SCAN; }
virtual bool parseScanData(std::istream& in, ScanData& data) override;
virtual bool parseScanData(std::istream& input, ScanData& data) override;

public:
static std::string ON; ///< A string that represents the ON value.
static std::string OFF; ///< A string that represents the OFF value.
static std::string ON_VALUE; ///< A string that represents the ON value.
static std::string OFF_VALUE; ///< A string that represents the OFF value.
static std::string LDS_SCAN_HEADER; ///< A header of the LDS scan output.
static std::string LDS_SCAN_FOOTER; ///< A footer of the LDS scan output.

Expand Down Expand Up @@ -164,13 +167,14 @@ typedef NeatoController<SerialController> NeatoSerialController;
typedef NeatoController<SocketController> NeatoSocketController;

template<typename ProtocolController>
std::string NeatoController<ProtocolController>::ON = "on";
std::string NeatoController<ProtocolController>::ON_VALUE = "on";

template<typename ProtocolController>
std::string NeatoController<ProtocolController>::OFF = "off";
std::string NeatoController<ProtocolController>::OFF_VALUE = "off";

template<typename ProtocolController>
std::string NeatoController<ProtocolController>::LDS_SCAN_HEADER = "AngleInDegrees,DistInMM,Intensity,ErrorCodeHEX";
std::string NeatoController<ProtocolController>::LDS_SCAN_HEADER =
"AngleInDegrees,DistInMM,Intensity,ErrorCodeHEX";

template<typename ProtocolController>
std::string NeatoController<ProtocolController>::LDS_SCAN_FOOTER = "ROTATION_SPEED,";
Expand All @@ -197,28 +201,30 @@ NeatoController<ProtocolController>::NeatoController() : ScanController<Protocol
}

template<typename ProtocolController>
NeatoController<ProtocolController>::NeatoController(const std::string& logPath) : ScanController<ProtocolController>(logPath)
NeatoController<ProtocolController>::NeatoController(const std::string& logPath) :
ScanController<ProtocolController>(logPath)
{
this->RESPONSE_END = std::string(1, 0x1a);
}

template<typename ProtocolController>
NeatoController<ProtocolController>::NeatoController(std::iostream& logStream) : ScanController<ProtocolController>(logStream)
NeatoController<ProtocolController>::NeatoController(std::iostream& logStream) :
ScanController<ProtocolController>(logStream)
{
this->RESPONSE_END = std::string(1, 0x1a);
}

template<typename ProtocolController>
void NeatoController<ProtocolController>::setTestMode(bool testMode)
{
this->sendFormattedCommand(CMD_TEST_MODE, (testMode ? ON : OFF).c_str());
this->sendFormattedCommand(CMD_TEST_MODE, (testMode ? ON_VALUE : OFF_VALUE).c_str());
this->testMode = testMode;
}

template<typename ProtocolController>
void NeatoController<ProtocolController>::setLdsRotation(bool ldsRotation)
{
this->sendFormattedCommand(CMD_SET_LDS_ROTATION, (ldsRotation ? ON : OFF).c_str());
this->sendFormattedCommand(CMD_SET_LDS_ROTATION, (ldsRotation ? ON_VALUE : OFF_VALUE).c_str());
this->ldsRotation = ldsRotation;
}

Expand All @@ -243,52 +249,52 @@ void NeatoController<ProtocolController>::setMotor(int left, int right, int spee
}

template<typename ProtocolController>
bool NeatoController<ProtocolController>::parseScanData(std::istream& in, ScanData& data)
bool NeatoController<ProtocolController>::parseScanData(std::istream& input, ScanData& data)
{
int lastIndex = 0;
double M_PI_180 = M_PI / 180.0;

std::string line;
std::getline(in, line);
boost::algorithm::trim(line);
std::getline(input, line);
balg::trim(line);

if(line == NeatoController<ProtocolController>::LDS_SCAN_HEADER)
if(line != NeatoController<ProtocolController>::LDS_SCAN_HEADER)
{
while(true)
return false;
}

while(true)
{
std::getline(input, line);
balg::trim(line);

if(balg::starts_with(line, NeatoController<ProtocolController>::LDS_SCAN_FOOTER))
{
std::getline(in, line);
boost::algorithm::trim(line);

if(boost::algorithm::starts_with(line, NeatoController<ProtocolController>::LDS_SCAN_FOOTER))
{
std::vector<std::string> values;
boost::algorithm::split(values, line, boost::algorithm::is_any_of(","));
data.rotationSpeed = std::stod(values.at(1));

break;
}
else
{
std::vector<std::string> values;
boost::algorithm::split(values, line, boost::algorithm::is_any_of(","));

int index = lastIndex++;
double angle = std::stod(values.at(0)) * M_PI_180;
double distance = std::stod(values.at(1));
int intensity = std::stoi(values.at(2));
int errorCode = std::stoi(values.at(3));
bool error = (errorCode != 0);

if(error) distance = -1;

data.emplace_back(index, angle, distance, intensity, errorCode, error);
}
std::vector<std::string> values;
balg::split(values, line, balg::is_any_of(","));
data.rotationSpeed = std::stod(values.at(1));

break;
}
else
{
std::vector<std::string> values;
balg::split(values, line, balg::is_any_of(","));

int index = lastIndex++;
double angle = std::stod(values.at(0)) * M_PI_180;
double distance = std::stod(values.at(1));
int intensity = std::stoi(values.at(2));
int errorCode = std::stoi(values.at(3));
bool error = errorCode != 0;

return true;
if(error) distance = -1;

data.emplace_back(index, angle, distance, intensity, errorCode, error);
}
}

return false;
return true;
}

template<typename ProtocolController>
Expand Down
4 changes: 2 additions & 2 deletions include/regilo/scancontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ class ScanController : public virtual IScanController, public ProtocolController

/**
* @brief Parse the raw scan data.
* @param in The input stream that stores the raw scan data.
* @param input The input stream that stores the raw scan data.
* @param data Output for the scanned data.
* @return True if the parsing ends without an error.
*/
virtual bool parseScanData(std::istream& in, ScanData& data) = 0;
virtual bool parseScanData(std::istream& input, ScanData& data) = 0;

public:
using ProtocolController::ProtocolController;
Expand Down
24 changes: 17 additions & 7 deletions include/regilo/timedlog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ class ITimedLog : public virtual ILog
* @return Time since epoch as Duration.
*/
template<typename Duration>
inline Duration getLastCommandTimeAs() const { return std::chrono::duration_cast<Duration>(this->getLastCommandNanoseconds()); }
inline Duration getLastCommandTimeAs() const
{
return std::chrono::duration_cast<Duration>(this->getLastCommandNanoseconds());
}

/**
* @brief Sync command times with real time. It means that all read methods will block
Expand Down Expand Up @@ -151,7 +154,10 @@ class TimedLog : public Log, public ITimedLog
*/
virtual ~TimedLog() = default;

virtual inline const ITimedLogMetadata* getTimedMetadata() const override { return (TimedLogMetadata<DurationT>*)metadata; }
virtual inline const ITimedLogMetadata* getTimedMetadata() const override
{
return (TimedLogMetadata<DurationT>*)metadata;
}

inline virtual std::chrono::nanoseconds getLastCommandNanoseconds() const override
{
Expand All @@ -164,7 +170,10 @@ class TimedLog : public Log, public ITimedLog
*/
inline DurationT getLastCommandTime() const { return lastCommandTime; }

virtual inline void syncTime(bool sync = true) override { firstReadTime = (sync ? DurationT::max() : DurationT::zero()); }
virtual inline void syncTime(bool sync = true) override
{
firstReadTime = (sync ? DurationT::max() : DurationT::zero());
}
};

extern template class TimedLog<std::chrono::nanoseconds>;
Expand Down Expand Up @@ -195,7 +204,8 @@ void TimedLog<DurationT>::writeMetadata(std::ostream& metaStream)
if(metadata == nullptr) metadata = new TimedLogMetadata<DurationT>();
Log::writeMetadata(metaStream);

metaStream << "timeres " << DurationT::period::num << ' ' << DurationT::period::den << std::endl;
metaStream << "timeres " << DurationT::period::num << ' ' << DurationT::period::den
<< std::endl;
}

template<typename DurationT>
Expand All @@ -205,15 +215,15 @@ std::string TimedLog<DurationT>::readData(std::string& logCommand)

std::string response = Log::readData(logCommand);

std::int64_t commandTimeCount = 0;
std::int64_t timeCount = 0;
readName(stream, 't');
stream >> commandTimeCount;
stream >> timeCount;

if(stream)
{
long double numRatio = getTimedMetadata()->getNum() / (long double) DurationT::period::num;
long double denRation = DurationT::period::den / (long double) getTimedMetadata()->getDen();
lastCommandTime = DurationT(std::int64_t(std::round(commandTimeCount * numRatio * denRation)));
lastCommandTime = DurationT(std::int64_t(std::round(timeCount * numRatio * denRation)));

if(firstReadTime == DurationT::max()) firstReadTime = epoch<DurationT>();
else
Expand Down
16 changes: 11 additions & 5 deletions include/regilo/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ namespace regilo {
class Version
{
public:
static const std::string VERSION; ///< The whole version number in format <major>[.<minor>[.<patch>[.<tweak>]]].
static const std::string VERSION_MAJOR; ///< The major part of the version number (format <major>[.<minor>[.<patch>[.<tweak>]]]).
static const std::string VERSION_MINOR; ///< The minor part of the version number (format <major>[.<minor>[.<patch>[.<tweak>]]]).
static const std::string VERSION_PATCH; ///< The patch part of the version number (format <major>[.<minor>[.<patch>[.<tweak>]]]).
static const std::string VERSION_TWEAK; ///< The tweak part of the version number (format <major>[.<minor>[.<patch>[.<tweak>]]]).
///< The whole version number in format <major>[.<minor>[.<patch>]].
static const std::string VERSION;

///< The major part of the version number (format <major>[.<minor>[.<patch>]]).
static const std::string VERSION_MAJOR;

///< The minor part of the version number (format <major>[.<minor>[.<patch>]]).
static const std::string VERSION_MINOR;

///< The patch part of the version number (format <major>[.<minor>[.<patch>]]).
static const std::string VERSION_PATCH;
};

}
Expand Down

0 comments on commit e815546

Please sign in to comment.