开发者

Making a passthrough interface to library

开发者 https://www.devze.com 2023-03-08 12:22 出处:网络
Sorry if this question has been asked before. I\'m really not sure how to search for it. What I\'m trying to do is build up a library of functions for myself to make life easier in my future school w

Sorry if this question has been asked before. I'm really not sure how to search for it.

What I'm trying to do is build up a library of functions for myself to make life easier in my future school wor开发者_如何转开发k. I built up a set of functions that handle Geometry based things, like 3D vectors and points and planes along with all of their associated methods (dot, cross, scale).

Through some googling, I found the Eigen library which implements everything I want, including alot of SSE stuff to make it fast.

I don't understand SSE and alot of the stuff they did in that library, so I don't want to use it as my development library. What I mean by that is, I want to code everything using my dumb, slow versions that I know how they work so I can make sure I'm doing everything right. Then once I'm sure the math is coming out right, I'd like to switch it over to using the Eigen library for efficiency.

Is there some way to make it so I can set a flag, or pass a variable, (maybe some template thing?) so that I can switch my code from my stuff to the Eigen stuff without having to rewrite my applications?

Basically I'd like to make a standard interface between the two libraries.

The Eigen library code would be included in the same directory. I'd have my Geometry.h, and then a Eigen folder that contains all of that library.

I don't know how to bridge the gap between the two. Would I need to write wrapper methods for all of their stuff so it has a common API?

EDIT ::

I should also add that I'd like this to be as fast as possible. For things like dot, cross, and matrix functions that could get called many times, I'd like to not have to go through virtual functions or too complex of wrapper methods that could negatively impact performance.

Am I asking too much?

END EDIT

Something like this is what I want in effect. But I'm pretty sure this doesn't do what I want.


#ifdef BASIC_LIBRARY
  class Vector3
  {
    float x,y,z;
    float dot(Vector3);
  }
#endif
#ifdef EIGEN_LIBRARY
  //some sort of passthrough to eigen library
#endif


I'd suggest using namespaces for this:

namespace geometry {
    class Vector3 {
       ...
    };
}

namespace eigen {
    using geometry::Vector3;

    ...
}

Basically this would allow you to define your basic geometry types & operations, and then use selected portions directly from within the other namespace.

0

精彩评论

暂无评论...
验证码 换一张
取 消