farm-ng-core
proto_conv.h File Reference
Include dependency graph for proto_conv.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  farm_ng::ToProtoTrait< TCpp >
 Trait to associate one concrete Proto type with given C++ type TCpp. More...
 
struct  farm_ng::FromProtoTrait< TProto >
 Trait to associate one concrete Cpp type with given proto type TProto. More...
 

Namespaces

 farm_ng
 

Macros

#define FARM_PROTO_CONV_TRAIT(TCpp, TProto)
 Convenience macro to define the ToProtoTrait and FromProtoTrait as well as the toProt and fromProt function templates instantiation declarations for a given C++ type TCpp and a given proto type TProto. Hence, this macro is typically used in a header file. More...
 

Functions

template<class TProto >
auto farm_ng::fromProt (TProto const &proto) -> Expected< typename FromProtoTrait< TProto >::CppType >
 Function template to convert a C++ object to a proto object. More...
 
template<class TCpp >
auto farm_ng::toProt (TCpp const &cpp) -> typename ToProtoTrait< TCpp >::ProtoType
 Function template to convert a proto object to a C++ object. More...
 

Macro Definition Documentation

◆ FARM_PROTO_CONV_TRAIT

#define FARM_PROTO_CONV_TRAIT (   TCpp,
  TProto 
)
Value:
template <> \
struct ToProtoTrait<TCpp> { \
using ProtoType = TProto; \
}; \
template <> \
struct FromProtoTrait<TProto> { \
using CppType = TCpp; \
}; \
template <> \
auto fromProt<TProto>(TProto const& proto)->Expected<TCpp>; \
\
template <> \
auto toProt<TCpp>(TCpp const& cpp)->TProto

Convenience macro to define the ToProtoTrait and FromProtoTrait as well as the toProt and fromProt function templates instantiation declarations for a given C++ type TCpp and a given proto type TProto. Hence, this macro is typically used in a header file.

Example:

FARM_PROTO_CONV_TRAIT(Eigen::Vector3d, proto::Vec3F64);

produces the following code:

template <>
struct ToProtoTrait<Eigen::Vector3d> {
  using ProtoType = proto::Vec3F64;
};

template <>
struct FromProtoTrait<proto::Vec3F64> {
  using CppType = Eigen::Vector3d;
};

template <>
auto fromProt<proto::Vec3F64>(proto::Vec3F64 const& proto)
    -> Expected<Eigen::Vector3d>;

template <>
auto toProt<Eigen::Vector3d>(Eigen::Vector3d const& cpp)
    -> proto::Vec3F64;