C API: more functions added, improve C++ references

This commit is contained in:
Syping 2021-10-30 17:40:58 +02:00
parent 7bc3cabc89
commit b4d65b24af
2 changed files with 74 additions and 19 deletions

View file

@ -387,17 +387,17 @@ bool RagePhoto::load(const std::string &data)
return load(data.data(), data.size()); return load(data.data(), data.size());
} }
RagePhoto::Error RagePhoto::error() RagePhoto::Error RagePhoto::error() const
{ {
return static_cast<Error>(m_data.error); return static_cast<Error>(m_data.error);
} }
uint32_t RagePhoto::format() uint32_t RagePhoto::format() const
{ {
return m_data.photoFormat; return m_data.photoFormat;
} }
const std::string RagePhoto::photo() const std::string RagePhoto::photo() const
{ {
if (m_data.photoLoaded) if (m_data.photoLoaded)
return std::string(m_data.photoData, m_data.photoSize); return std::string(m_data.photoData, m_data.photoSize);
@ -405,7 +405,7 @@ const std::string RagePhoto::photo()
return std::string(); return std::string();
} }
const char* RagePhoto::photoData() const char* RagePhoto::photoData() const
{ {
if (m_data.photoLoaded) if (m_data.photoLoaded)
return m_data.photoData; return m_data.photoData;
@ -413,7 +413,7 @@ const char* RagePhoto::photoData()
return nullptr; return nullptr;
} }
uint32_t RagePhoto::photoSize() uint32_t RagePhoto::photoSize() const
{ {
if (m_data.photoLoaded) if (m_data.photoLoaded)
return m_data.photoSize; return m_data.photoSize;
@ -421,22 +421,22 @@ uint32_t RagePhoto::photoSize()
return 0UL; return 0UL;
} }
const std::string RagePhoto::description() const std::string& RagePhoto::description() const
{ {
return m_data.description; return m_data.description;
} }
const std::string RagePhoto::json() const std::string& RagePhoto::json() const
{ {
return m_data.json; return m_data.json;
} }
const std::string RagePhoto::header() const std::string& RagePhoto::header() const
{ {
return m_data.header; return m_data.header;
} }
const std::string RagePhoto::title() const std::string& RagePhoto::title() const
{ {
return m_data.title; return m_data.title;
} }
@ -868,7 +868,7 @@ inline void RagePhoto::uInt32ToCharLE(uint32_t x, char *y)
#ifdef LIBRAGEPHOTO_C_API #ifdef LIBRAGEPHOTO_C_API
ragephoto_t ragephoto_open() ragephoto_t ragephoto_open()
{ {
return new RagePhoto; return static_cast<ragephoto_t>(new RagePhoto);
} }
int ragephoto_load(ragephoto_t instance, const char *data, size_t size) 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); return ragePhoto->load(data, size);
} }
uint8_t ragephoto_error(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return static_cast<uint8_t>(ragePhoto->error());
}
const char* ragephoto_getphotodata(ragephoto_t instance) const char* ragephoto_getphotodata(ragephoto_t instance)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->photoData(); return ragePhoto->photoData();
} }
const char* ragephoto_getphotodesc(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->description().data();
}
uint32_t ragephoto_getphotoformat(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->format();
}
const char* ragephoto_getphotojson(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->json().data();
}
uint32_t ragephoto_getphotosize(ragephoto_t instance) uint32_t ragephoto_getphotosize(ragephoto_t instance)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->photoSize(); return ragePhoto->photoSize();
} }
const char* ragephoto_getphototitle(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->title().data();
}
void ragephoto_close(ragephoto_t instance) void ragephoto_close(ragephoto_t instance)
{ {
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance); RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);

View file

@ -107,15 +107,15 @@ public:
* \param data Photo data * \param data Photo data
*/ */
bool load(const std::string &data); bool load(const std::string &data);
Error error(); /**< Returns the last error occurred. */ Error error() const; /**< Returns the last error occurred. */
uint32_t format(); /**< Returns the Photo Format (GTA V or RDR 2). */ uint32_t format() const; /**< Returns the Photo Format (GTA V or RDR 2). */
const std::string photo(); /**< Returns the Photo JPEG data. */ const std::string photo() const; /**< Returns the Photo JPEG data. */
const char *photoData(); /**< Returns the Photo JPEG data. */ const char *photoData() const; /**< Returns the Photo JPEG data. */
uint32_t photoSize(); /**< Returns the Photo JPEG data size. */ uint32_t photoSize() const; /**< Returns the Photo JPEG data size. */
const std::string description(); /**< Returns the Photo description. */ const std::string& description() const; /**< Returns the Photo description. */
const std::string json(); /**< Returns the Photo JSON data. */ const std::string& json() const; /**< Returns the Photo JSON data. */
const std::string header(); /**< Returns the Photo header. */ const std::string& header() const; /**< Returns the Photo header. */
const std::string title(); /**< Returns the Photo title. */ const std::string& title() const; /**< Returns the Photo title. */
/** Saves a Photo to a char*. /** Saves a Photo to a char*.
* \param data Photo data * \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2) * \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); 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. /** Returns the Photo JPEG data.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */
LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotodata(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. /** Returns the Photo JPEG data size.
* \param instance \p ragephoto_t instance * \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); 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. /** Closes a \p ragephoto_t instance.
* \param instance \p ragephoto_t instance * \param instance \p ragephoto_t instance
*/ */