Created
March 26, 2017 17:34
-
-
Save bartlomiejn/8ffa67d40dd54bc9324999e348ebf0a3 to your computer and use it in GitHub Desktop.
C++ class with C bridge definition file for swift-explorations.ghost.io
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
class CppClass { | |
public: | |
CppClass(const char* value) { | |
storedValue = value; | |
} | |
const char* storedValue; | |
}; | |
extern "C" void* makeObject(const char* storedValue) { | |
return (void*) new CppClass(storedValue); | |
} | |
extern "C" void setNewStoredValue(void* object, const char* newValue) { | |
auto castedObject = static_cast<CppClass*>(object); | |
castedObject->storedValue = newValue; | |
} | |
extern "C" const char* getStoredValue(void* object) { | |
auto castedObject = static_cast<CppClass*>(object); | |
return castedObject->storedValue; | |
} | |
extern "C" void removeObject(void* object) { | |
delete static_cast<CppClass*>(object); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment