Skip to content
This repository has been archived by the owner on Aug 6, 2022. It is now read-only.

Commit

Permalink
removed abseil
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed Sep 30, 2019
1 parent 2348d4f commit ed02e39
Show file tree
Hide file tree
Showing 14 changed files with 1,644 additions and 99 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ find_package(catkin REQUIRED COMPONENTS
roscpp
rostime
roscpp_serialization
abseil_cpp
)

# Build flags
Expand All @@ -20,7 +19,6 @@ catkin_package(
roscpp
rostime
roscpp_serialization
abseil_cpp
DEPENDS
)

Expand Down
14 changes: 8 additions & 6 deletions include/ros_type_introspection/helper_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
#define ROS_INTROSPECTION_HELPER_H

#include <functional>
#include "ros_type_introspection/utils/variant.hpp"
#include "absl/types/span.h"
#include <ros_type_introspection/utils/variant.hpp>
#include <ros_type_introspection/utils/span.hpp>

namespace RosIntrospection{

template< class T>
using Span = nonstd::span<T>;

// Brutally faster for numbers below 100
inline int print_number(char* buffer, uint16_t value)
Expand Down Expand Up @@ -75,7 +77,7 @@ inline int print_number(char* buffer, uint16_t value)


// helper function to deserialize raw memory
template <typename T> inline void ReadFromBuffer( const absl::Span<uint8_t>& buffer, size_t& offset, T& destination)
template <typename T> inline void ReadFromBuffer( const Span<uint8_t>& buffer, size_t& offset, T& destination)
{
if ( offset + sizeof(T) > buffer.size() )
{
Expand All @@ -85,7 +87,7 @@ template <typename T> inline void ReadFromBuffer( const absl::Span<uint8_t>& buf
offset += sizeof(T);
}

template <> inline void ReadFromBuffer( const absl::Span<uint8_t>& buffer, size_t& offset, std::string& destination)
template <> inline void ReadFromBuffer( const Span<uint8_t>& buffer, size_t& offset, std::string& destination)
{
uint32_t string_size = 0;
ReadFromBuffer( buffer, offset, string_size );
Expand All @@ -102,14 +104,14 @@ template <> inline void ReadFromBuffer( const absl::Span<uint8_t>& buffer, size_
}

template <typename T> inline
Variant ReadFromBufferToVariant( const absl::Span<uint8_t>& buffer, size_t& offset)
Variant ReadFromBufferToVariant( const Span<uint8_t>& buffer, size_t& offset)
{
T destination;
ReadFromBuffer(buffer, offset, destination);
return Variant(destination);
}

inline Variant ReadFromBufferToVariant(BuiltinType id, const absl::Span<uint8_t>& buffer, size_t& offset)
inline Variant ReadFromBufferToVariant(BuiltinType id, const Span<uint8_t>& buffer, size_t& offset)
{
switch(id)
{
Expand Down
17 changes: 8 additions & 9 deletions include/ros_type_introspection/ros_introspection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
#define ROS_INTROSPECTION_HPP

#include <unordered_set>
#include "ros_type_introspection/stringtree_leaf.hpp"
#include "ros_type_introspection/substitution_rule.hpp"
#include "ros_type_introspection/helper_functions.hpp"
#include "absl/types/span.h"
#include <ros_type_introspection/stringtree_leaf.hpp>
#include <ros_type_introspection/substitution_rule.hpp>
#include <ros_type_introspection/helper_functions.hpp>

namespace RosIntrospection{

Expand Down Expand Up @@ -141,7 +140,7 @@ class Parser{
* skipped because an array has (size > max_array_size)
*/
bool deserializeIntoFlatContainer(const std::string& msg_identifier,
absl::Span<uint8_t> buffer,
Span<uint8_t> buffer,
FlatMessage* flat_container_output,
const uint32_t max_array_size ) const;

Expand Down Expand Up @@ -169,7 +168,7 @@ class Parser{
const FlatMessage& container,
RenamedValues* renamed_value , bool dont_add_topicname = false);

typedef std::function<void(const ROSType&, absl::Span<uint8_t>&)> VisitingCallback;
typedef std::function<void(const ROSType&, Span<uint8_t>&)> VisitingCallback;

/**
* @brief applyVisitorToBuffer is used to pass a callback that is invoked every time
Expand All @@ -184,11 +183,11 @@ class Parser{
* @param callback The callback.
*/
void applyVisitorToBuffer(const std::string& msg_identifier, const ROSType &monitored_type,
absl::Span<uint8_t> &buffer,
Span<uint8_t> &buffer,
VisitingCallback callback) const;

template <typename T>
T extractField(const std::string& msg_identifier, const absl::Span<uint8_t> &buffer);
T extractField(const std::string& msg_identifier, const Span<uint8_t> &buffer);


/// Change where the warning messages are displayed.
Expand Down Expand Up @@ -229,7 +228,7 @@ class Parser{

template<typename T> inline
T Parser::extractField(const std::string &msg_identifier,
const absl::Span<uint8_t> &buffer)
const Span<uint8_t> &buffer)
{
T out;
bool found = false;
Expand Down
20 changes: 10 additions & 10 deletions include/ros_type_introspection/ros_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ROSType {

ROSType(){}

ROSType(absl::string_view name);
ROSType(boost::string_ref name);

ROSType(const ROSType& other) { *this = other; }

Expand All @@ -67,12 +67,12 @@ class ROSType {
const std::string& baseName() const;

/// ex.: geometry_msgs/Pose -> "Pose"
const absl::string_view& msgName() const;
const boost::string_ref& msgName() const;

/// ex.: geometry_msgs/Pose -> "geometry_msgs"
const absl::string_view& pkgName() const;
const boost::string_ref& pkgName() const;

void setPkgName(absl::string_view new_pkg);
void setPkgName(boost::string_ref new_pkg);

/// True if the type is ROS builtin
bool isBuiltin() const;
Expand Down Expand Up @@ -101,8 +101,8 @@ class ROSType {

BuiltinType _id;
std::string _base_name;
absl::string_view _msg_name;
absl::string_view _pkg_name;
boost::string_ref _msg_name;
boost::string_ref _pkg_name;
size_t _hash;

};
Expand All @@ -114,12 +114,12 @@ inline const std::string &ROSType::baseName() const
return _base_name;
}

inline const absl::string_view& ROSType::msgName() const
inline const boost::string_ref& ROSType::msgName() const
{
return _msg_name;
}

inline const absl::string_view &ROSType::pkgName() const
inline const boost::string_ref &ROSType::pkgName() const
{
return _pkg_name;
}
Expand Down Expand Up @@ -147,8 +147,8 @@ inline std::ostream& operator<<(std::ostream &os, const ROSType& t )
return os;
}

inline BuiltinType toBuiltinType(const absl::string_view& s) {
static std::map<absl::string_view, BuiltinType> string_to_builtin_map {
inline BuiltinType toBuiltinType(const boost::string_ref& s) {
static std::map<boost::string_ref, BuiltinType> string_to_builtin_map {
{ "bool", BOOL },
{ "byte", BYTE },
{ "char", CHAR },
Expand Down
27 changes: 5 additions & 22 deletions include/ros_type_introspection/stringtree_leaf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,12 @@
#include <vector>
#include <map>
#include <iostream>
#include <absl/container/inlined_vector.h>
#include <absl/container/fixed_array.h>
#include <boost/container/small_vector.hpp>
#include <boost/container/static_vector.hpp>
#include "ros_type_introspection/ros_message.hpp"

namespace RosIntrospection{

// Still faster in my benchmark than absl::InlinedVector

template <typename T, size_t N>
class InlinedVector{
public:
InlinedVector(): _size(0) {}
void push_back(T val) { _array[_size++] = val; }
const T& back() const { return _array[_size-1]; }
T& back() { return _array[_size-1]; }
size_t size() const { return _size; }
const T& operator[](size_t index) const { return _array[index]; }
T& operator[](size_t index) { return _array[index]; }
private:
std::array<T,N> _array;
size_t _size;
};

/**
* @brief The StringTreeLeaf is, as the name suggests, a leaf (terminal node)
* of a StringTree.
Expand All @@ -85,7 +68,7 @@ struct StringTreeLeaf{

const StringTreeNode* node_ptr;

InlinedVector<uint16_t,8> index_array;
boost::container::static_vector<uint16_t,8> index_array;

/// Utility functions to print the entire branch
bool toStr(std::string &destination) const;
Expand All @@ -98,8 +81,8 @@ struct StringTreeLeaf{
constexpr static const char SEPARATOR = '/';
constexpr static const char NUM_PLACEHOLDER = '#';

static const absl::string_view& num_placeholder() {
constexpr static const absl::string_view nph("#");
static const boost::string_ref& num_placeholder() {
static const boost::string_ref nph("#");
return nph;
}
};
Expand Down
14 changes: 7 additions & 7 deletions include/ros_type_introspection/substitution_rule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#define ROS_INTROSPECTION_SUBSTITUTION_RULE_H

#include "ros_type_introspection/ros_type.hpp"
#include <absl/strings/string_view.h>
#include <boost/utility/string_ref.hpp>


namespace RosIntrospection{
Expand Down Expand Up @@ -117,9 +117,9 @@ class SubstitutionRule {

SubstitutionRule& operator= (const SubstitutionRule& other);

const std::vector<absl::string_view>& pattern() const { return _pattern; }
const std::vector<absl::string_view>& alias() const { return _alias; }
const std::vector<absl::string_view>& substitution() const { return _substitution; }
const std::vector<boost::string_ref>& pattern() const { return _pattern; }
const std::vector<boost::string_ref>& alias() const { return _alias; }
const std::vector<boost::string_ref>& substitution() const { return _substitution; }

bool operator == (const SubstitutionRule& other) const
{
Expand All @@ -131,9 +131,9 @@ class SubstitutionRule {
std::string _full_pattern;
std::string _full_alias;
std::string _full_substitution;
std::vector<absl::string_view> _pattern;
std::vector<absl::string_view> _alias;
std::vector<absl::string_view> _substitution;
std::vector<boost::string_ref> _pattern;
std::vector<boost::string_ref> _alias;
std::vector<boost::string_ref> _substitution;
size_t _hash;
} ;

Expand Down

0 comments on commit ed02e39

Please sign in to comment.