From b4d65b24afc0fc01c4cc4456cf826b576f4a1de5 Mon Sep 17 00:00:00 2001 From: Syping Date: Sat, 30 Oct 2021 17:40:58 +0200 Subject: [PATCH] C API: more functions added, improve C++ references --- src/RagePhoto.cpp | 50 +++++++++++++++++++++++++++++++++++++---------- src/RagePhoto.h | 43 +++++++++++++++++++++++++++++++--------- 2 files changed, 74 insertions(+), 19 deletions(-) diff --git a/src/RagePhoto.cpp b/src/RagePhoto.cpp index 48f200e..3134137 100644 --- a/src/RagePhoto.cpp +++ b/src/RagePhoto.cpp @@ -387,17 +387,17 @@ bool RagePhoto::load(const std::string &data) return load(data.data(), data.size()); } -RagePhoto::Error RagePhoto::error() +RagePhoto::Error RagePhoto::error() const { return static_cast(m_data.error); } -uint32_t RagePhoto::format() +uint32_t RagePhoto::format() const { return m_data.photoFormat; } -const std::string RagePhoto::photo() +const std::string RagePhoto::photo() const { if (m_data.photoLoaded) return std::string(m_data.photoData, m_data.photoSize); @@ -405,7 +405,7 @@ const std::string RagePhoto::photo() return std::string(); } -const char* RagePhoto::photoData() +const char* RagePhoto::photoData() const { if (m_data.photoLoaded) return m_data.photoData; @@ -413,7 +413,7 @@ const char* RagePhoto::photoData() return nullptr; } -uint32_t RagePhoto::photoSize() +uint32_t RagePhoto::photoSize() const { if (m_data.photoLoaded) return m_data.photoSize; @@ -421,22 +421,22 @@ uint32_t RagePhoto::photoSize() return 0UL; } -const std::string RagePhoto::description() +const std::string& RagePhoto::description() const { return m_data.description; } -const std::string RagePhoto::json() +const std::string& RagePhoto::json() const { return m_data.json; } -const std::string RagePhoto::header() +const std::string& RagePhoto::header() const { return m_data.header; } -const std::string RagePhoto::title() +const std::string& RagePhoto::title() const { return m_data.title; } @@ -868,7 +868,7 @@ inline void RagePhoto::uInt32ToCharLE(uint32_t x, char *y) #ifdef LIBRAGEPHOTO_C_API ragephoto_t ragephoto_open() { - return new RagePhoto; + return static_cast(new RagePhoto); } int ragephoto_load(ragephoto_t instance, const char *data, size_t size) @@ -877,18 +877,48 @@ int ragephoto_load(ragephoto_t instance, const char *data, size_t size) return ragePhoto->load(data, size); } +uint8_t ragephoto_error(ragephoto_t instance) +{ + RagePhoto *ragePhoto = static_cast(instance); + return static_cast(ragePhoto->error()); +} + const char* ragephoto_getphotodata(ragephoto_t instance) { RagePhoto *ragePhoto = static_cast(instance); return ragePhoto->photoData(); } +const char* ragephoto_getphotodesc(ragephoto_t instance) +{ + RagePhoto *ragePhoto = static_cast(instance); + return ragePhoto->description().data(); +} + +uint32_t ragephoto_getphotoformat(ragephoto_t instance) +{ + RagePhoto *ragePhoto = static_cast(instance); + return ragePhoto->format(); +} + +const char* ragephoto_getphotojson(ragephoto_t instance) +{ + RagePhoto *ragePhoto = static_cast(instance); + return ragePhoto->json().data(); +} + uint32_t ragephoto_getphotosize(ragephoto_t instance) { RagePhoto *ragePhoto = static_cast(instance); return ragePhoto->photoSize(); } +const char* ragephoto_getphototitle(ragephoto_t instance) +{ + RagePhoto *ragePhoto = static_cast(instance); + return ragePhoto->title().data(); +} + void ragephoto_close(ragephoto_t instance) { RagePhoto *ragePhoto = static_cast(instance); diff --git a/src/RagePhoto.h b/src/RagePhoto.h index 57661ec..d010ac6 100644 --- a/src/RagePhoto.h +++ b/src/RagePhoto.h @@ -107,15 +107,15 @@ public: * \param data Photo data */ bool load(const std::string &data); - Error error(); /**< Returns the last error occurred. */ - uint32_t format(); /**< Returns the Photo Format (GTA V or RDR 2). */ - const std::string photo(); /**< Returns the Photo JPEG data. */ - const char *photoData(); /**< Returns the Photo JPEG data. */ - uint32_t photoSize(); /**< Returns the Photo JPEG data size. */ - const std::string description(); /**< Returns the Photo description. */ - const std::string json(); /**< Returns the Photo JSON data. */ - const std::string header(); /**< Returns the Photo header. */ - const std::string title(); /**< Returns the Photo title. */ + Error error() const; /**< Returns the last error occurred. */ + uint32_t format() const; /**< Returns the Photo Format (GTA V or RDR 2). */ + const std::string photo() const; /**< Returns the Photo JPEG data. */ + const char *photoData() const; /**< Returns the Photo JPEG data. */ + uint32_t photoSize() const; /**< Returns the Photo JPEG data size. */ + const std::string& description() const; /**< Returns the Photo description. */ + const std::string& json() const; /**< Returns the Photo JSON data. */ + const std::string& header() const; /**< Returns the Photo header. */ + const std::string& title() const; /**< Returns the Photo title. */ /** Saves a Photo to a char*. * \param data Photo data * \param photoFormat Photo Format (GTA V or RDR 2) @@ -192,16 +192,41 @@ LIBRAGEPHOTO_EXPORT ragephoto_t ragephoto_open(); */ LIBRAGEPHOTO_EXPORT int ragephoto_load(ragephoto_t instance, const char *data, size_t size); +/** Returns the last error occurred. +* \param instance \p ragephoto_t instance +*/ +LIBRAGEPHOTO_EXPORT uint8_t ragephoto_error(ragephoto_t instance); + /** Returns the Photo JPEG data. * \param instance \p ragephoto_t instance */ LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotodata(ragephoto_t instance); +/** Returns the Photo description. +* \param instance \p ragephoto_t instance +*/ +LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotodesc(ragephoto_t instance); + /** Returns the Photo JPEG data size. * \param instance \p ragephoto_t instance */ +LIBRAGEPHOTO_EXPORT uint32_t ragephoto_getphotoformat(ragephoto_t instance); + +/** Returns the Photo JSON data. +* \param instance \p ragephoto_t instance +*/ +LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotojson(ragephoto_t instance); + +/** Returns the Photo Format (GTA V or RDR 2). +* \param instance \p ragephoto_t instance +*/ LIBRAGEPHOTO_EXPORT uint32_t ragephoto_getphotosize(ragephoto_t instance); +/** Returns the Photo title. +* \param instance \p ragephoto_t instance +*/ +LIBRAGEPHOTO_EXPORT const char* ragephoto_getphototitle(ragephoto_t instance); + /** Closes a \p ragephoto_t instance. * \param instance \p ragephoto_t instance */