I am developing a C ++ library where the user will provide complex inputs such as matrices and quaternions. I do not want to override these types, therefore, internally I will use the Eigen library .
I am trying to decide how to best expose these types in my libraries, clients, and have suggested several options for my API. I use a quaternion type, but this can apply equally to matrices and the like. Also, although I specifically talk about exposing Eigen types, I think this question can equally well apply to other external libraries used.
1) Use only basic C ++ types
This parameter requires clients to pass data through the base types. For example, for passing in a quaternion (4 elements) one could do:
void my_func(double my_quat[4])
2) Derive own types
Eigen provides several template types for arrays and quaternions. For example, if a function requires a quaternion, I could use the Eigen Quaterniond
type (which is really typedef for Quaternion<double>):
void my_func(const Eigen::Quaterniond& my_quat)
3) Create a simple wrapper for various types for clients
I could create a very simple type of quaternion (say, some simple structure) that clients would need to create (possibly through some kind of factory function) in order to go to my API:
void my_func(const quaternion_t& my_quat)
My library converts the type quaternion_tto my internal Eigen representation.
1 , ,
API. 2 Eigen,
,
Eigen (, Eigen - ,
). 3.
? ? - ?
,
, , .