mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-27 12:49:35 +08:00
Replace more GenericVector by std::vector for src/unittest
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
9eab1d60c1
commit
48fe1e0232
@ -5,7 +5,6 @@
|
||||
// Description: Double-ended pointer that keeps pointing correctly even
|
||||
// when reallocated or copied.
|
||||
// Author: Ray Smith
|
||||
// Created: Wed Mar 14 12:22:57 PDT 2012
|
||||
//
|
||||
// (C) Copyright 2012, Google Inc.
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -34,7 +33,7 @@ namespace tesseract {
|
||||
// For this reason both the copy constructor and the operator= take a non-const
|
||||
// reference argument, and the const reference versions cannot be used.
|
||||
// DoublePtr is useful to incorporate into structures that are part of a
|
||||
// collection such as GenericVector or STL containers, where reallocs can
|
||||
// collection such as STL containers, where reallocs can
|
||||
// relocate the members. DoublePtr is also useful in a GenericHeap, where it
|
||||
// can correctly maintain the pointer to an element of the heap despite it
|
||||
// getting moved around on the heap.
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
#include "doubleptr.h"
|
||||
#include "genericheap.h"
|
||||
#include "genericvector.h"
|
||||
#include "kdpair.h"
|
||||
|
||||
#include <string>
|
||||
@ -135,7 +134,7 @@ TEST_F(HeapTest, RevalueTest) {
|
||||
// in the vector and heap, and we test a MAX heap.
|
||||
typedef KDPairDec<int, DoublePtr> PtrPair;
|
||||
GenericHeap<PtrPair> heap;
|
||||
GenericVector<PtrPair> v;
|
||||
std::vector<PtrPair> v;
|
||||
// Push the test data onto both the heap and the vector.
|
||||
for (size_t i = 0; i < countof(test_data); ++i) {
|
||||
PtrPair h_pair;
|
||||
@ -162,7 +161,7 @@ TEST_F(HeapTest, RevalueTest) {
|
||||
heap.Reshuffle(pair_ptr);
|
||||
// After the changes, popping the heap should still match the sorted order
|
||||
// of the vector.
|
||||
v.sort();
|
||||
std::sort(v.begin(), v.end());
|
||||
EXPECT_GT(v[0].key(), v.back().key());
|
||||
for (int i = 0; i < v.size(); ++i) {
|
||||
EXPECT_EQ(v[i].key(), heap.PeekTop().key());
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "include_gunit.h" // for TEST
|
||||
#include "log.h" // for LOG
|
||||
|
||||
#include "genericvector.h"
|
||||
// ccmain
|
||||
#include "paragraphs.h"
|
||||
#include "paragraphs_internal.h"
|
||||
|
@ -9,7 +9,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "genericvector.h"
|
||||
#include "serialis.h"
|
||||
|
||||
#include "include_gunit.h"
|
||||
@ -52,22 +51,22 @@ protected:
|
||||
bool Serialize(TFile *fp) {
|
||||
if (fp->FWrite(&num_squares_, sizeof(num_squares_), 1) != 1)
|
||||
return false;
|
||||
if (!squares_.Serialize(fp))
|
||||
if (!fp->Serialize(squares_))
|
||||
return false;
|
||||
if (fp->FWrite(&num_triangles_, sizeof(num_triangles_), 1) != 1)
|
||||
return false;
|
||||
if (!triangles_.Serialize(fp))
|
||||
if (!fp->Serialize(triangles_))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool DeSerialize(TFile *fp) {
|
||||
if (fp->FReadEndian(&num_squares_, sizeof(num_squares_), 1) != 1)
|
||||
return false;
|
||||
if (!squares_.DeSerialize(fp))
|
||||
if (!fp->DeSerialize(squares_))
|
||||
return false;
|
||||
if (fp->FReadEndian(&num_triangles_, sizeof(num_triangles_), 1) != 1)
|
||||
return false;
|
||||
if (!triangles_.DeSerialize(fp))
|
||||
if (!fp->DeSerialize(triangles_))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@ -81,44 +80,44 @@ protected:
|
||||
return false;
|
||||
for (int i = 0; i < squares_.size(); ++i)
|
||||
ReverseN(&squares_[i], sizeof(squares_[i]));
|
||||
if (!squares_.Serialize(fp))
|
||||
if (!fp->Serialize(squares_))
|
||||
return false;
|
||||
ReverseN(&num_triangles_, sizeof(num_triangles_));
|
||||
if (fp->FWrite(&num_triangles_, sizeof(num_triangles_), 1) != 1)
|
||||
return false;
|
||||
if (fp->FWrite(&num_triangles_, sizeof(num_triangles_), 1) != 1)
|
||||
return false;
|
||||
for (int i = 0; i < triangles_.size(); ++i)
|
||||
ReverseN(&triangles_[i], sizeof(triangles_[i]));
|
||||
return triangles_.Serialize(fp);
|
||||
for (auto &triangle : triangles_)
|
||||
ReverseN(&triangle, sizeof(triangles_[0]));
|
||||
return fp->Serialize(triangles_);
|
||||
}
|
||||
bool DeSerializeBigEndian(TFile *fp) {
|
||||
if (fp->FReadEndian(&num_squares_, sizeof(num_squares_), 1) != 1)
|
||||
return false;
|
||||
if (!squares_.DeSerialize(fp))
|
||||
if (!fp->DeSerialize(squares_))
|
||||
return false;
|
||||
// The first element is the size that was written, so we will delete it
|
||||
// and read the last element separately.
|
||||
int last_element;
|
||||
if (fp->FReadEndian(&last_element, sizeof(last_element), 1) != 1)
|
||||
return false;
|
||||
squares_.remove(0);
|
||||
squares_.erase(squares_.begin());
|
||||
squares_.push_back(last_element);
|
||||
if (fp->FReadEndian(&num_triangles_, sizeof(num_triangles_), 1) != 1)
|
||||
return false;
|
||||
if (!triangles_.DeSerialize(fp))
|
||||
if (!fp->DeSerialize(triangles_))
|
||||
return false;
|
||||
if (fp->FReadEndian(&last_element, sizeof(last_element), 1) != 1)
|
||||
return false;
|
||||
triangles_.remove(0);
|
||||
triangles_.erase(triangles_.begin());
|
||||
triangles_.push_back(last_element);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
GenericVector<int> squares_;
|
||||
std::vector<int> squares_;
|
||||
int num_squares_;
|
||||
GenericVector<int> triangles_;
|
||||
std::vector<int> triangles_;
|
||||
int num_triangles_;
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user