mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-22 16:14:37 +08:00
strip iostream from binary (~520'000 B -> ~380'000 B)
This commit is contained in:
@@ -50,7 +50,6 @@ bool endpoint_handler(int idx, cbufptr_t* input_buffer, bufptr_t* output_buffer)
|
||||
switch (idx) {
|
||||
[%- for endpoint in endpoints %]
|
||||
[%- if (endpoint.function.name == 'exchange' or endpoint.function.name == 'read') and endpoint.in_bindings | list == ['obj'] %]
|
||||
//case [[endpoint.id]]: return FibrePropertyTypeInfo<[[endpoint.function.in['obj'].type.c_type]]>::make_introspectable([[endpoint.in_bindings['obj']]]);
|
||||
case [[endpoint.id]]: { return [[endpoint.function.fullname | to_snake_case]]([% for k, arg in endpoint.function.in.items() %][% if k in endpoint.in_bindings %]static_cast<[[arg.type.c_type]]>([[endpoint.in_bindings[k]]])[% else %]std::nullopt[% endif %], [% endfor %][% for k, arg in endpoint.function.out.items() %][% if k in endpoint.out_bindings %]static_cast<[[arg.type.c_type]]*>([[endpoint.out_bindings[k]]])[% else %]nullptr[% endif %], [% endfor %]input_buffer, output_buffer); } break;
|
||||
[%- else %]
|
||||
case [[endpoint.id]]: { return [[endpoint.function.fullname | to_snake_case]]([% for k, arg in endpoint.function.in.items() %][% if k in endpoint.in_bindings %]static_cast<[[arg.type.c_type]]>([[endpoint.in_bindings[k]]])[% else %]std::nullopt[% endif %], [% endfor %][% for k, arg in endpoint.function.out.items() %][% if k in endpoint.out_bindings %]static_cast<[[arg.type.c_type]]*>([[endpoint.out_bindings[k]]])[% else %]nullptr[% endif %], [% endfor %]input_buffer, output_buffer); } break;
|
||||
|
||||
@@ -82,9 +82,6 @@ public:
|
||||
#include <tuple>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
//#include <cassert>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
/* Backport features from C++14 and C++17 ------------------------------------*/
|
||||
|
||||
@@ -950,69 +947,6 @@ bool hex_string_to_int_arr(const char * str, TInt (&output)[ICount]) {
|
||||
return hex_string_to_int_arr(str, hex_digits<TInt>() * ICount, output);
|
||||
}
|
||||
|
||||
namespace fibre {
|
||||
|
||||
// TODO: move to print_utils.hpp
|
||||
template<typename T>
|
||||
class HexPrinter {
|
||||
public:
|
||||
HexPrinter(T val, bool prefix) : val_(val) /*, prefix_(prefix)*/ {
|
||||
const char digits[] = "0123456789abcdef";
|
||||
size_t prefix_length = prefix ? 2 : 0;
|
||||
if (prefix) {
|
||||
str[0] = '0';
|
||||
str[1] = 'x';
|
||||
}
|
||||
str[prefix_length + hex_digits<T>()] = '\0';
|
||||
|
||||
for (size_t i = 0; i < hex_digits<T>(); ++i) {
|
||||
str[prefix_length + hex_digits<T>() - i - 1] = digits[val & 0xf];
|
||||
val >>= 4;
|
||||
}
|
||||
}
|
||||
std::string to_string() const { return str; }
|
||||
void to_string(char* buf) const {
|
||||
for (size_t i = 0; (i < sizeof(str)) && str[i]; ++i)
|
||||
buf[i] = str[i];
|
||||
}
|
||||
|
||||
T val_;
|
||||
//bool prefix_;
|
||||
char str[hex_digits<T>() + 3]; // 3 additional characters 0x and \0
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& stream, const HexPrinter<T>& printer) {
|
||||
// TODO: specialize for char
|
||||
return stream << printer.to_string();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
HexPrinter<T> as_hex(T val, bool prefix = true) { return HexPrinter<T>(val, prefix); }
|
||||
|
||||
template<typename T>
|
||||
class HexArrayPrinter {
|
||||
public:
|
||||
HexArrayPrinter(T* ptr, size_t length) : ptr_(ptr), length_(length) {}
|
||||
T* ptr_;
|
||||
size_t length_;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& stream, const HexArrayPrinter<T>& printer) {
|
||||
for (size_t pos = 0; pos < printer.length_; ++pos) {
|
||||
stream << " " << as_hex(printer.ptr_[pos]);
|
||||
if (((pos + 1) % 16) == 0)
|
||||
stream << std::endl;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
template<typename T, size_t ILength>
|
||||
HexArrayPrinter<T> as_hex(T (&val)[ILength]) { return HexArrayPrinter<T>(val, ILength); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<typename TDereferenceable, typename TResult>
|
||||
class simple_iterator : std::iterator<std::random_access_iterator_tag, TResult> {
|
||||
|
||||
@@ -57,11 +57,11 @@ public:
|
||||
[%- for func in intf.functions.values() %]
|
||||
[%- for k, arg in func.in.items() | skip_first %]
|
||||
[[arg.type.c_type]] [[func.name | to_snake_case]]_in_[[arg.name]]_; // for internal use by Fibre
|
||||
template<typename T> static auto get_[[func.name | to_snake_case]]_in_[[arg.name]]_(T* obj) { return Property<[[arg.type.c_type]]>{obj, [](void* ctx){ return ([[arg.type.c_type]])((T*)ctx)->[[func.name | to_snake_case]]_in_[[arg.name]]_; }, [](void* ctx, [[arg.type.c_type]] value){ ((T*)ctx)->[[func.name | to_snake_case]]_in_[[arg.name]]_ = value; }}; }
|
||||
template<typename T> static auto get_[[func.name | to_snake_case]]_in_[[arg.name]]_(T* obj) { return Property<[[arg.type.c_type]]>{&obj->[[func.name | to_snake_case]]_in_[[arg.name]]_}; }
|
||||
[%- endfor %]
|
||||
[%- for k, arg in func.out.items() %]
|
||||
[[arg.type.c_type]] [[func.name | to_snake_case]]_out_[[arg.name]]_; // for internal use by Fibre
|
||||
template<typename T> static auto get_[[func.name | to_snake_case]]_out_[[arg.name]]_(T* obj) { return Property<const [[arg.type.c_type]]>{obj, [](void* ctx){ return ([[arg.type.c_type]])((T*)ctx)->[[func.name | to_snake_case]]_out_[[arg.name]]_; }}; }
|
||||
template<typename T> static auto get_[[func.name | to_snake_case]]_out_[[arg.name]]_(T* obj) { return Property<const [[arg.type.c_type]]>{&obj->[[func.name | to_snake_case]]_out_[[arg.name]]_}; }
|
||||
[%- endfor %]
|
||||
[%- endfor %]
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user