Add missing serialization to FILE for vector of pointers (issue #3925)

It is required for mftraining which otherwise writes a wrong shapetable.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2022-12-11 16:35:37 +01:00
parent 90c09a3df3
commit 6b7cb1cbc6

View File

@ -31,6 +31,8 @@
#include <string>
#include <vector>
#include "serialis.h"
namespace tesseract {
template <class T>
@ -242,6 +244,19 @@ bool Serialize(FILE *fp, const std::vector<T> &data) {
return false;
}
}
} else if constexpr (std::is_pointer<T>::value) {
// Serialize pointers.
for (auto &item : data) {
uint8_t non_null = (item != nullptr);
if (!Serialize(fp, &non_null)) {
return false;
}
if (non_null) {
if (!item->Serialize(fp)) {
return false;
}
}
}
} else if (size > 0) {
if (fwrite(&data[0], sizeof(T), size, fp) != size) {
return false;