Libsockcanpp
A complete C++ wrapper around socketcan.
Namespaces | Data Structures | Functions
sockcanpp Namespace Reference

Main library namespace. More...

Namespaces

namespace  exceptions
 

Data Structures

class  CanDriver
 CanDriver class; handles communication via CAN. More...
 
struct  CanId
 Represents a CAN ID in a simple and easy-to-use manner. More...
 
class  CanMessage
 Represents a CAN message that was received. More...
 

Functions

template<typename... Args>
string formatString (const string &format, Args... args)
 Formats a std string object. More...
 

Detailed Description

Main library namespace.

This namespace contains the library's main code.

Function Documentation

◆ formatString()

template<typename... Args>
string sockcanpp::formatString ( const string &  format,
Args...  args 
)

Formats a std string object.

Remarks
Yoinked from https://github.com/Beatsleigher/liblogpp :)
Template Parameters
ArgsThe formatting argument types.
Parameters
formatThe format string.
argsThe format arguments (strings must be converted to C-style strings!)
Returns
string The formatted string.

Definition at line 131 of file CanDriver.hpp.

131 {
132 using std::unique_ptr;
133 auto stringSize = snprintf(NULL, 0, format.c_str(), args...) + 1; // +1 for \0
134 unique_ptr<char[]> buffer(new char[stringSize]);
135
136 snprintf(buffer.get(), stringSize, format.c_str(), args...);
137
138 return string(buffer.get(), buffer.get() + stringSize - 1); // std::string handles termination for us.
139 }

Referenced by sockcanpp::CanDriver::initialiseSocketCan(), sockcanpp::CanDriver::readMessageLock(), sockcanpp::CanDriver::sendMessage(), sockcanpp::CanDriver::setCanFilterMask(), and sockcanpp::CanDriver::uninitialiseSocketCan().