-1

I have a library that uses classes from another library (dll)

//DLL External library API: Foo library
namespace foo{
class Component( Elemement e ) {
...
}
} //foo namespace

Now my library needs to use the foo dll and use some of its functionality and classes, but without exposing the Foo library types but some "translation"

// my developed library "Core"
namespace core{
class Component( Element e ){
...
}
}

The public API will expose the class core::Component and core::Element, but actually those should be direct translations to the foo::Component and foo::Element. Imagine also that this translation needs to be done for many other classes that need to be wrapped to be exposed. What would be the best way to handle this?

FCR
  • 1,027
  • 8
  • 21
  • What do you mean when you write "translation"? – Karoly Horvath Oct 22 '15 at 14:50
  • I need a class core::Element that is acutally the same as foo::Element, I just do not want to expose the foo classes but a wapper of it. In this case, the wrapper is just to hide that the underlying class is not developed in my library but in the external library (foo) is there any trick to be done? like typedefs, or using (in c++11)? – FCR Oct 22 '15 at 14:54
  • 1
    If it's the *same*, why would you hide it? – Karoly Horvath Oct 22 '15 at 14:55
  • Different customer, same functionality to deliver. – FCR Oct 22 '15 at 14:59
  • Sounds like you want a PIMPL: http://stackoverflow.com/questions/60570/why-should-the-pimpl-idiom-be-used – RyanP Oct 22 '15 at 15:00
  • Btw, can you guarantee your customer is using the same compiler/version? You can run into issues with DLL's using C++ interfaces due to name-mangling differences. – RyanP Oct 22 '15 at 15:01
  • Mmmm not sure what would be the issue here. We state minimum requirements to link with our library (like gcc 4.8 and so on ) – FCR Oct 22 '15 at 15:21

1 Answers1

1

Is using directive what you are looking for?

namespace foo {
    class A {};
}

namespace core {
    using foo::A;
}

// use like
core::A a;
Petr
  • 9,051
  • 1
  • 25
  • 47
  • If class A has method getValue() and setValue(), for example, how the final user of my library will see those? If I use your solution and do not expose the headers from the foo library, how can it be possible? – FCR Oct 22 '15 at 15:28
  • 1
    @FCR, you will anyway have to expose library headers if you do not want to duplicate them. – Petr Oct 22 '15 at 15:31
  • Thanks, what if then Foo library ( and headers ) contain a lot of other public classes that I dont want the customer to use. Since I want the customer to use the Foo library but through my Core library, by shipping the Foo headers and library I am letting the user to use the whole functionality of Foo, avoiding my Core library, right? Should it be possible to then ship onle a subset of all headers of Foo? – FCR Oct 23 '15 at 08:06