Last active
March 18, 2019 10:52
-
-
Save wi7a1ian/5a3519dd04e0f9d0d9668ac720659218 to your computer and use it in GitHub Desktop.
Base for C++ API #cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "FooAPIDefs.h" | |
#define FOOINTERFACES_VERSION 7 | |
extern "C" FOOINTERFACES_API IFooFactory* GetFooFactoryPtr(const uchar* options = nullptr, uint32_t version = FOOINTERFACES_VERSION) noexcept; | |
// API entry point | |
inline IFooFactory::Ptr GetFooFactory(const uchar* options = nullptr, uint32_t version = FOOINTERFACES_VERSION) { | |
return IFooFactory::Ptr(GetFooFactoryPtr(options, version)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef _WIN32 | |
# ifdef FOOINTERFACES_EXPORTS | |
# define FOOINTERFACES_API __declspec(dllexport) | |
# else | |
# define FOOINTERFACES_API __declspec(dllimport) | |
# endif | |
#else | |
# define FOOINTERFACES_API | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace FooImplementation | |
{ | |
extern "C" FOOINTERFACES_API IFooFactory* GetFooFactoryPtr(const uchar* options, uint32_t version) noexcept | |
{ | |
assert(options != nullptr); | |
assert(version == FOOINTERFACES_VERSION); | |
IFooFactory* outPtr = nullptr; | |
try | |
{ | |
if (version == FOOINTERFACES_VERSION) | |
{ | |
outPtr = new SomeFooFactoryImplementation(options); | |
} | |
} | |
catch (...) | |
{ | |
assert(false && "Failed to create factory object"); | |
} | |
return outPtr; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment