Replace boost features with C++11 equivalents (#58)

* Replace boost features with C++11 equivalents

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Include <cmath> in util.h

Needed for std::abs

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
This commit is contained in:
Jacob Perron 2020-11-01 18:05:17 -08:00 committed by GitHub
parent 850b011a55
commit 2b9591f0f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 95 additions and 87 deletions

View file

@ -32,9 +32,9 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef CREATE_H
#define CREATE_H
#include <boost/shared_ptr.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <chrono>
#include <memory>
#include <string>
#include <unistd.h>
@ -96,8 +96,8 @@ namespace create {
bool updateLEDs();
protected:
boost::shared_ptr<create::Data> data;
boost::shared_ptr<create::Serial> serial;
std::shared_ptr<create::Data> data;
std::shared_ptr<create::Serial> serial;
public:
/**

View file

@ -32,9 +32,8 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef CREATE_DATA_H
#define CREATE_DATA_H
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <map>
#include <memory>
#include <vector>
#include "create/packet.h"
@ -43,7 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace create {
class Data {
private:
std::map<uint8_t, boost::shared_ptr<Packet> > packets;
std::map<uint8_t, std::shared_ptr<Packet> > packets;
uint32_t totalDataBytes;
std::vector<uint8_t> ids;
@ -52,7 +51,7 @@ namespace create {
~Data();
bool isValidPacketID(const uint8_t id) const;
boost::shared_ptr<Packet> getPacket(const uint8_t id);
std::shared_ptr<Packet> getPacket(const uint8_t id);
void validateAll();
uint32_t getTotalDataBytes() const;
uint8_t getNumPackets() const;

View file

@ -31,15 +31,15 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef CREATE_PACKET_H
#define CREATE_PACKET_H
#include <boost/thread/mutex.hpp>
#include <mutex>
namespace create {
class Packet {
private:
uint16_t data;
uint16_t tmpData;
mutable boost::mutex dataMutex;
mutable boost::mutex tmpDataMutex;
mutable std::mutex dataMutex;
mutable std::mutex tmpDataMutex;
protected:
// Thread safe

View file

@ -35,19 +35,20 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef CREATE_SERIAL_H
#define CREATE_SERIAL_H
#include <condition_variable>
#include <functional>
#include <memory>
#include <mutex>
#include <thread>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include "create/data.h"
#include "create/types.h"
#include "create/util.h"
namespace create {
class Serial : public boost::enable_shared_from_this<Serial> {
class Serial : public std::enable_shared_from_this<Serial> {
protected:
boost::asio::io_service io;
@ -55,9 +56,9 @@ namespace create {
boost::asio::serial_port port;
private:
boost::thread ioThread;
boost::condition_variable dataReadyCond;
boost::mutex dataReadyMut;
std::thread ioThread;
std::condition_variable dataReadyCond;
std::mutex dataReadyMut;
bool dataReady;
bool isReading;
bool firstRead;
@ -66,13 +67,13 @@ namespace create {
// Callback executed when data arrives from Create
void onData(const boost::system::error_code& e, const std::size_t& size);
// Callback to execute once data arrives
boost::function<void()> callback;
std::function<void()> callback;
// Start and stop reading data from Create
bool startReading();
void stopReading();
protected:
boost::shared_ptr<Data> data;
std::shared_ptr<Data> data;
// These are for possible diagnostics
uint64_t corruptPackets;
uint64_t totalPackets;
@ -85,9 +86,9 @@ namespace create {
void notifyDataReady();
public:
Serial(boost::shared_ptr<Data> data);
Serial(std::shared_ptr<Data> data);
~Serial();
bool connect(const std::string& port, const int& baud = 115200, boost::function<void()> cb = 0);
bool connect(const std::string& port, const int& baud = 115200, std::function<void()> cb = 0);
void disconnect();
inline bool connected() const { return port.is_open(); };
bool send(const uint8_t* bytes, const uint32_t numBytes);

View file

@ -36,11 +36,9 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef CREATE_SERIAL_QUERY_H
#define CREATE_SERIAL_QUERY_H
#include <memory>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include "create/data.h"
#include "create/types.h"
@ -69,7 +67,7 @@ namespace create {
void processByte(uint8_t byteRead);
public:
SerialQuery(boost::shared_ptr<Data> data);
SerialQuery(std::shared_ptr<Data> data);
};
} // namespace create

View file

@ -35,11 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef CREATE_SERIAL_STREAM_H
#define CREATE_SERIAL_STREAM_H
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>
#include "create/data.h"
#include "create/types.h"
@ -73,7 +69,7 @@ namespace create {
void processByte(uint8_t byteRead);
public:
SerialStream(boost::shared_ptr<Data> data, const uint8_t& header = create::util::STREAM_HEADER);
SerialStream(std::shared_ptr<Data> data, const uint8_t& header = create::util::STREAM_HEADER);
};
} // namespace create

View file

@ -32,6 +32,8 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef CREATE_UTIL_H
#define CREATE_UTIL_H
#include <cmath>
#define COUT(prefix,msg) (std::cout<<prefix<<msg<<std::endl)
#define CERR(prefix,msg) (std::cerr<<prefix<<msg<<std::endl)