Add ability to retrieve errors to fixed size buffers

This commit is contained in:
Alex Harker
2019-11-24 22:19:26 +00:00
parent 09f02fbdb5
commit 678e987a40
2 changed files with 36 additions and 0 deletions
+33
View File
@@ -20,6 +20,39 @@ void FrameLib_ErrorReporter::ErrorReport::getErrorText(std::string& text) const
}
}
void FrameLib_ErrorReporter::ErrorReport::getErrorText(char *text, size_t N) const
{
const char *errorPtr = mError;
const char *itemsPtr = mItems;
size_t j = 0, k = 0;
for (unsigned long i = 0; i < mNumItems; i++, errorPtr += j + 1, itemsPtr += k + 1)
{
for (j = 0; errorPtr[j]; j++)
if (errorPtr[j] == '#')
break;
if (!errorPtr[j])
break;
k = strlen(itemsPtr);
copy(text, errorPtr, j, N);
copy(text, itemsPtr, k, N);
}
copy(text, errorPtr, strlen(errorPtr), N);
}
void FrameLib_ErrorReporter::ErrorReport::copy(char*& dest, const char *str, size_t length, size_t& left) const
{
size_t size = std::min(length, left - 1);
std::copy(str, str + size, dest);
dest += size;
left -= size;
dest[0] = 0;
}
// Retrieve errors (passes ownership to the host)
std::unique_ptr<FrameLib_ErrorReporter::ErrorList> FrameLib_ErrorReporter::getErrors()
+3
View File
@@ -70,11 +70,14 @@ public:
ErrorReport() : mSource(kErrorObject), mReporter(nullptr), mError(nullptr), mItems(nullptr), mItemSize(0), mNumItems(0) {}
void getErrorText(std::string& text) const;
void getErrorText(char *text, size_t N) const;
ErrorSource getSource() const { return mSource; }
FrameLib_Proxy* getReporter() const { return mReporter; }
private:
void copy(char*& dest, const char *str, size_t length, size_t& left) const;
// Data
ErrorSource mSource;