mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-19 15:03:45 +08:00
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:
parent
90c09a3df3
commit
6b7cb1cbc6
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user