RagePhoto: remove static library functions from the class

This commit is contained in:
Syping 2021-11-18 18:00:09 +01:00
parent b900df55cc
commit 285df4893d
2 changed files with 47 additions and 47 deletions

View file

@ -41,6 +41,51 @@
#include <stringapiset.h> #include <stringapiset.h>
#endif #endif
/* BEGIN OF STATIC LIBRARY FUNCTIONS */
inline size_t readBuffer(const char *input, void *output, size_t *pos, size_t outputLen, size_t inputLen)
{
size_t readLen = 0;
if (*pos >= inputLen)
return 0;
readLen = inputLen - *pos;
if (readLen > outputLen)
readLen = outputLen;
std::memcpy(output, &input[*pos], readLen);
*pos = *pos + readLen;
return readLen;
}
inline size_t writeBuffer(const void *input, char *output, size_t *pos, size_t outputLen, size_t inputLen)
{
const size_t maxLen = outputLen - *pos;
size_t writeLen = inputLen;
if (*pos >= outputLen)
return 0;
if (inputLen > maxLen)
writeLen = maxLen;
std::memcpy(&output[*pos], input, writeLen);
*pos = *pos + writeLen;
return writeLen;
}
inline uint32_t charToUInt32LE(char *x)
{
return (static_cast<unsigned char>(x[3]) << 24 |
static_cast<unsigned char>(x[2]) << 16 |
static_cast<unsigned char>(x[1]) << 8 |
static_cast<unsigned char>(x[0]));
}
inline void uInt32ToCharLE(uint32_t x, char *y)
{
y[0] = x;
y[1] = x >> 8;
y[2] = x >> 16;
y[3] = x >> 24;
}
/* END OF STATIC LIBRARY FUNCTIONS */
/* BEGIN OF RAGEPHOTO CLASS */
RagePhoto::RagePhoto() RagePhoto::RagePhoto()
{ {
m_data.photoLoaded = false; m_data.photoLoaded = false;
@ -894,48 +939,6 @@ void RagePhoto::setTitle(const std::string &title, uint32_t bufferSize)
} }
} }
inline size_t RagePhoto::readBuffer(const char *input, void *output, size_t *pos, size_t len, size_t inputLen)
{
size_t readLen = 0;
if (*pos >= inputLen)
return 0;
readLen = inputLen - *pos;
if (readLen > len)
readLen = len;
std::memcpy(output, &input[*pos], readLen);
*pos = *pos + readLen;
return readLen;
}
inline size_t RagePhoto::writeBuffer(const void *input, char *output, size_t *pos, size_t len, size_t inputLen)
{
const size_t maxLen = len - *pos;
size_t writeLen = inputLen;
if (*pos >= len)
return 0;
if (inputLen > maxLen)
writeLen = maxLen;
std::memcpy(&output[*pos], input, writeLen);
*pos = *pos + writeLen;
return writeLen;
}
inline uint32_t RagePhoto::charToUInt32LE(char *x)
{
return (static_cast<unsigned char>(x[3]) << 24 |
static_cast<unsigned char>(x[2]) << 16 |
static_cast<unsigned char>(x[1]) << 8 |
static_cast<unsigned char>(x[0]));
}
inline void RagePhoto::uInt32ToCharLE(uint32_t x, char *y)
{
y[0] = x;
y[1] = x >> 8;
y[2] = x >> 16;
y[3] = x >> 24;
}
#ifdef LIBRAGEPHOTO_C_API #ifdef LIBRAGEPHOTO_C_API
ragephoto_t ragephoto_open() ragephoto_t ragephoto_open()
{ {
@ -1123,3 +1126,4 @@ const char* ragephoto_version()
return RAGEPHOTO_VERSION; return RAGEPHOTO_VERSION;
} }
#endif #endif
/* END OF RAGEPHOTO CLASS */

View file

@ -167,11 +167,7 @@ public:
bool setPhoto(const std::string &data, uint32_t bufferSize = 0); bool setPhoto(const std::string &data, uint32_t bufferSize = 0);
void setTitle(const std::string &title, uint32_t bufferSize = 0); /**< Sets the Photo title. */ void setTitle(const std::string &title, uint32_t bufferSize = 0); /**< Sets the Photo title. */
protected: private:
static size_t readBuffer(const char *input, void *output, size_t *pos, size_t len, size_t inputLen);
static size_t writeBuffer(const void *input, char *output, size_t *pos, size_t len, size_t inputLen);
static uint32_t charToUInt32LE(char *x);
static void uInt32ToCharLE(uint32_t x, char *y);
std::unordered_map<uint8_t, RagePhotoLoadFunc> m_loadFuncs; std::unordered_map<uint8_t, RagePhotoLoadFunc> m_loadFuncs;
RagePhotoData m_data; RagePhotoData m_data;
}; };