mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-02-07 16:01:52 +08:00
102 lines
6.7 KiB
Django/Jinja
102 lines
6.7 KiB
Django/Jinja
/*[# This is the original template, thus the warning below does not apply to this file #]
|
|
* ============================ WARNING ============================
|
|
* ==== This is an autogenerated file. ====
|
|
* ==== Any changes to this file will be lost when recompiling. ====
|
|
* =================================================================
|
|
*
|
|
* This file contains base classes that correspond to the interfaces defined in
|
|
* your interface file. The objects you publish should inherit from these
|
|
* interfaces.
|
|
*
|
|
*/
|
|
#ifndef __FIBRE_INTERFACES_HPP
|
|
#define __FIBRE_INTERFACES_HPP
|
|
|
|
[[userdata.c_preamble]]
|
|
|
|
#include <fibre/../../protocol.hpp>
|
|
|
|
#pragma GCC push_options
|
|
#pragma GCC optimize ("s")
|
|
|
|
[%- macro rettype(func) %]
|
|
[%- if not func.out -%]
|
|
void
|
|
[%- elif func.out | length == 1 -%]
|
|
[[(func.out.values() | first).type.c_name]]
|
|
[%- else -%]
|
|
std::tuple<[% for arg in func.out.values() %][[arg.type.c_name]][[', ' if not loop.last]][% endfor %]>
|
|
[%- endif -%]
|
|
[%- endmacro %]
|
|
|
|
[%- macro render_interface(intf) %]
|
|
class [[intf.name | to_pascal_case]]Intf[% if intf.implements %] :[%- for base_intf in intf.implements %] public [[base_intf.c_name]][% endfor %][% endif %] {
|
|
public:
|
|
[%- for intf in intf.interfaces -%]
|
|
[[render_interface(intf) | indent(4)]]
|
|
[%- endfor %]
|
|
[%- for enum in intf.enums %]
|
|
enum [[enum.name | to_pascal_case]] {
|
|
[%- for k, value in enum['values'].items() %]
|
|
[[((enum.name | to_macro_case) + "_" + (k | to_macro_case)).ljust(32)]] = [% if enum.is_flags %]0x[['%08x' | format(value.value)]][% else %][[value.value]][% endif %],
|
|
[%- endfor %]
|
|
};
|
|
[%- endfor %]
|
|
|
|
[%- for property in intf.attributes.values() %]
|
|
[%- if property.type.fullname.startswith("fibre.Property") %]
|
|
[%- if not property.c_getter and not property.c_setter %]
|
|
template<typename T> static inline auto get_[[property.name]](T* obj) { return [[property.type.c_name]]{&obj->[[property.c_name]]}; }
|
|
template<typename T> static inline void get_[[property.name]](T* obj, void* ptr) { new (ptr) [[property.type.c_name]]{&obj->[[property.c_name]]}; }[# these are for the set_endpoint_from_float function. This is unmaintainable and should go away #]
|
|
[%- elif not property.c_setter %]
|
|
template<typename T> static inline auto get_[[property.name]](T* obj) { return [[property.type.c_name]]{obj, [](void* ctx){ return ([[property.type.value_type.c_name]])((T*)ctx)->[[property.c_getter]]; }}; }
|
|
template<typename T> static inline void get_[[property.name]](T* obj, void* ptr) { new (ptr) [[property.type.c_name]]{obj, [](void* ctx){ return ([[property.type.value_type.c_name]])((T*)ctx)->[[property.c_getter]]; }}; }
|
|
[%- else %]
|
|
template<typename T> static inline auto get_[[property.name]](T* obj) { return [[property.type.c_name]]{obj, [](void* ctx){ return ([[property.type.value_type.c_name]])((T*)ctx)->[[property.c_getter]]; }, [](void* ctx, [[property.type.value_type.c_name]] value){ ((T*)ctx)->[[property.c_setter]](value); }}; }
|
|
template<typename T> static inline void get_[[property.name]](T* obj, void* ptr) { new (ptr) [[property.type.c_name]]{obj, [](void* ctx){ return ([[property.type.value_type.c_name]])((T*)ctx)->[[property.c_getter]]; }, [](void* ctx, [[property.type.value_type.c_name]] value){ ((T*)ctx)->[[property.c_setter]](value); }}; }
|
|
[%- endif %]
|
|
[%- else %]
|
|
template<typename T> static inline auto get_[[property.name]](T* obj) { return &obj->[[property.c_name]]; }
|
|
[%- endif %]
|
|
[%- endfor %]
|
|
|
|
[%- for func in intf.functions.values() %]
|
|
virtual [[rettype(func)]] [[func.name | to_snake_case]]([% for in in func.in.values() %][% if loop.index0 %][[in.type.c_name]] [[in.name]][[', ' if not loop.last]][% endif %][% endfor %]) = 0;
|
|
[%- endfor %]
|
|
[%- for func in intf.functions.values() %]
|
|
[%- for k, arg in func.in.items() | skip_first %]
|
|
[[arg.type.c_name]] [[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_name]]>{&obj->[[func.name | to_snake_case]]_in_[[arg.name]]_}; }
|
|
template<typename T> static void get_[[func.name | to_snake_case]]_in_[[arg.name]]_(T* obj, void* ptr) { new (ptr) Property<[[arg.type.c_name]]>{&obj->[[func.name | to_snake_case]]_in_[[arg.name]]_}; }
|
|
[%- endfor %]
|
|
[%- for k, arg in func.out.items() %]
|
|
[[arg.type.c_name]] [[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_name]]>{&obj->[[func.name | to_snake_case]]_out_[[arg.name]]_}; }
|
|
template<typename T> static void get_[[func.name | to_snake_case]]_out_[[arg.name]]_(T* obj, void* ptr) { new (ptr) Property<const [[arg.type.c_name]]>{&obj->[[func.name | to_snake_case]]_out_[[arg.name]]_}; }
|
|
[%- endfor %]
|
|
[%- endfor %]
|
|
};
|
|
[%- endmacro %]
|
|
|
|
[% for intf in toplevel_interfaces %]
|
|
[[render_interface(intf)]]
|
|
[% endfor %]
|
|
|
|
[%- for _, enum in value_types.items() %]
|
|
[%- if enum.is_flags %]
|
|
// this is technically not thread-safe but practically it might be
|
|
inline [[enum.c_name]] operator | ([[enum.c_name]] a, [[enum.c_name]] b) { return static_cast<[[enum.c_name]]>(static_cast<std::underlying_type_t<[[enum.c_name]]>>(a) | static_cast<std::underlying_type_t<[[enum.c_name]]>>(b)); }
|
|
inline [[enum.c_name]] operator & ([[enum.c_name]] a, [[enum.c_name]] b) { return static_cast<[[enum.c_name]]>(static_cast<std::underlying_type_t<[[enum.c_name]]>>(a) & static_cast<std::underlying_type_t<[[enum.c_name]]>>(b)); }
|
|
inline [[enum.c_name]] operator ^ ([[enum.c_name]] a, [[enum.c_name]] b) { return static_cast<[[enum.c_name]]>(static_cast<std::underlying_type_t<[[enum.c_name]]>>(a) ^ static_cast<std::underlying_type_t<[[enum.c_name]]>>(b)); }
|
|
inline [[enum.c_name]]& operator |= ([[enum.c_name]] &a, [[enum.c_name]] b) { return reinterpret_cast<[[enum.c_name]]&>(reinterpret_cast<std::underlying_type_t<[[enum.c_name]]>&>(a) |= static_cast<std::underlying_type_t<[[enum.c_name]]>>(b)); }
|
|
inline [[enum.c_name]]& operator &= ([[enum.c_name]] &a, [[enum.c_name]] b) { return reinterpret_cast<[[enum.c_name]]&>(reinterpret_cast<std::underlying_type_t<[[enum.c_name]]>&>(a) &= static_cast<std::underlying_type_t<[[enum.c_name]]>>(b)); }
|
|
inline [[enum.c_name]]& operator ^= ([[enum.c_name]] &a, [[enum.c_name]] b) { return reinterpret_cast<[[enum.c_name]]&>(reinterpret_cast<std::underlying_type_t<[[enum.c_name]]>&>(a) ^= static_cast<std::underlying_type_t<[[enum.c_name]]>>(b)); }
|
|
inline [[enum.c_name]] operator ~ ([[enum.c_name]] a) { return static_cast<[[enum.c_name]]>(~static_cast<std::underlying_type_t<[[enum.c_name]]>>(a)); }
|
|
[%- endif %]
|
|
[%- endfor %]
|
|
|
|
|
|
|
|
#pragma GCC pop_options
|
|
|
|
#endif // __FIBRE_INTERFACES_HPP |