Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor all code to use QSharePointer and std::vector #205

Merged
merged 18 commits into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
First working version of whole-project use of QSharedData
  • Loading branch information
ftylitak committed Aug 7, 2021
commit aee14aef71d34848df3d72df06cc2dcb3cf0fb7d
54 changes: 27 additions & 27 deletions src/zxing/zxing/common/Counted.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
//#include "Counted.h"
#include "Counted.h"

//namespace zxing {
namespace zxing {

//Counted::Counted() :
// count_(0)
//{
//}
Counted::Counted() :
count_(0)
{
}

//Counted::~Counted()
//{
//}
Counted::~Counted()
{
}

//Counted *Counted::retain()
//{
// count_++;
// return this;
//}
Counted *Counted::retain()
{
count_++;
return this;
}

//void Counted::release()
//{
// count_--;
// if (count_ == 0) {
// count_ = 0xDEADF001;
// delete this;
// }
//}
void Counted::release()
{
count_--;
if (count_ == 0) {
count_ = 0xDEADF001;
delete this;
}
}

//size_t Counted::count() const
//{
// return count_;
//}
size_t Counted::count() const
{
return count_;
}



//}
}
208 changes: 104 additions & 104 deletions src/zxing/zxing/common/Counted.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,109 +21,109 @@
#include <iostream>
#include <QSharedPointer>

//namespace zxing {

///* base class for reference-counted objects */
//class Counted {
//private:
// size_t count_;
//public:
// Counted();

// virtual ~Counted();

// Counted *retain();

// void release();

// /* return the current count for denugging purposes or similar */
// size_t count() const;
//};

///* counting reference to reference-counted objects */
//template<typename T> class Ref {
//private:
//public:
// T *object_;
// explicit Ref(T *o = 0) :
// object_(0) {
// reset(o);
// }
// Ref(const Ref &other) :
// object_(0) {
// reset(other.object_);
// }

// template<class Y>
// Ref(const QSharedPointer<Y> &other) :
// object_(0) {
// reset(other.object_);
// }

// ~Ref() {
// if (object_) {
// object_->release();
// }
// }

// void reset(T *o) {
// if (o) {
// o->retain();
// }
// if (object_ != 0) {
// object_->release();
// }
// object_ = o;
// }
// Ref& operator=(const Ref &other) {
// reset(other.object_);
// return *this;
// }
// template<class Y>
// Ref& operator=(const QSharedPointer<Y> &other) {
// reset(other.object_);
// return *this;
// }
// Ref& operator=(T* o) {
// reset(o);
// return *this;
// }
// template<class Y>
// Ref& operator=(Y* o) {
// reset(o);
// return *this;
// }

// T& operator*() {
// return *object_;
// }
// T* operator->() const {
// return object_;
// }
// operator T*() const {
// return object_;
// }

// bool operator==(const T* that) {
// return object_ == that;
// }
// bool operator==(const Ref &other) const {
// return object_ == other.object_ || *object_ == *(other.object_);
// }
// template<class Y>
// bool operator==(const QSharedPointer<Y> &other) const {
// return object_ == other.object_ || *object_ == *(other.object_);
// }

// bool operator!=(const T* that) {
// return !(*this == that);
// }

// bool empty() const {
// return object_ == 0;
// }
//};

//}
namespace zxing {

/* base class for reference-counted objects */
class Counted {
private:
size_t count_;
public:
Counted();

virtual ~Counted();

Counted *retain();

void release();

/* return the current count for denugging purposes or similar */
size_t count() const;
};

/* counting reference to reference-counted objects */
template<typename T> class Ref {
private:
public:
T *object_;
explicit Ref(T *o = 0) :
object_(0) {
reset(o);
}
Ref(const Ref &other) :
object_(0) {
reset(other.object_);
}

template<class Y>
Ref(const QSharedPointer<Y> &other) :
object_(0) {
reset(other.object_);
}

~Ref() {
if (object_) {
object_->release();
}
}

void reset(T *o) {
if (o) {
o->retain();
}
if (object_ != 0) {
object_->release();
}
object_ = o;
}
Ref& operator=(const Ref &other) {
reset(other.object_);
return *this;
}
template<class Y>
Ref& operator=(const QSharedPointer<Y> &other) {
reset(other.object_);
return *this;
}
Ref& operator=(T* o) {
reset(o);
return *this;
}
template<class Y>
Ref& operator=(Y* o) {
reset(o);
return *this;
}

T& operator*() {
return *object_;
}
T* operator->() const {
return object_;
}
operator T*() const {
return object_;
}

bool operator==(const T* that) {
return object_ == that;
}
bool operator==(const Ref &other) const {
return object_ == other.object_ || *object_ == *(other.object_);
}
template<class Y>
bool operator==(const QSharedPointer<Y> &other) const {
return object_ == other.object_ || *object_ == *(other.object_);
}

bool operator!=(const T* that) {
return !(*this == that);
}

bool empty() const {
return object_ == 0;
}
};

}

#endif // ZXING_COUNTED_H
2 changes: 1 addition & 1 deletion src/zxing/zxing/common/GlobalHistogramBinarizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS;
const QSharedPointer<std::vector<zxing::byte>> EMPTY (0);

GlobalHistogramBinarizer::GlobalHistogramBinarizer(QSharedPointer<LuminanceSource> source)
: Binarizer(source), luminances(EMPTY), buckets(new std::vector<int>(LUMINANCE_BUCKETS)) {}
: Binarizer(source), luminances(new std::vector<zxing::byte>()), buckets(new std::vector<int>(LUMINANCE_BUCKETS)) {}

GlobalHistogramBinarizer::~GlobalHistogramBinarizer() {}

Expand Down
2 changes: 1 addition & 1 deletion src/zxing/zxing/common/reedsolomon/GenericGF.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
namespace zxing {
class GenericGFPoly;

class GenericGF {
class GenericGF {

private:
std::vector<int> expTable;
Expand Down
6 changes: 3 additions & 3 deletions src/zxing/zxing/common/reedsolomon/GenericGFPoly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ QSharedPointer<GenericGFPoly> GenericGFPoly::addOrSubtract(QSharedPointer<zxing:
return other;
}
if (other->isZero()) {
return QSharedPointer<GenericGFPoly>(this);
return QSharedPointer<GenericGFPoly>(new GenericGFPoly(*this));
}

QSharedPointer<std::vector<int>> smallerCoefficients = coefficients_;
Expand Down Expand Up @@ -161,7 +161,7 @@ QSharedPointer<GenericGFPoly> GenericGFPoly::multiply(int scalar) {
return field_->getZero();
}
if (scalar == 1) {
return QSharedPointer<GenericGFPoly>(this);
return QSharedPointer<GenericGFPoly>(new GenericGFPoly(*this));
}
int size = coefficients_->size();
QSharedPointer<std::vector<int>> product(new std::vector<int>(size));
Expand Down Expand Up @@ -195,7 +195,7 @@ std::vector<QSharedPointer<GenericGFPoly>> GenericGFPoly::divide(QSharedPointer<
}

QSharedPointer<GenericGFPoly> quotient = field_->getZero();
QSharedPointer<GenericGFPoly> remainder = QSharedPointer<GenericGFPoly>(this);
QSharedPointer<GenericGFPoly> remainder = QSharedPointer<GenericGFPoly>(new GenericGFPoly(*this));

int denominatorLeadingTerm = other->getCoefficient(other->getDegree());
int inverseDenominatorLeadingTerm = field_->inverse(denominatorLeadingTerm);
Expand Down
8 changes: 4 additions & 4 deletions src/zxing/zxing/pdf417/decoder/ec/ModulusPoly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ QSharedPointer<ModulusPoly> ModulusPoly::add(QSharedPointer<ModulusPoly> other)
}
if (other->isZero())
{
return QSharedPointer<ModulusPoly>(this);
return QSharedPointer<ModulusPoly>(new ModulusPoly(*this));
}

QSharedPointer<std::vector<int>> smallerCoefficients = coefficients_;
Expand Down Expand Up @@ -181,7 +181,7 @@ QSharedPointer<ModulusPoly> ModulusPoly::subtract(QSharedPointer<ModulusPoly> ot
}
if (other->isZero())
{
return QSharedPointer<ModulusPoly>(this);
return QSharedPointer<ModulusPoly>(new ModulusPoly(*this));
}
return add(other->negative());
}
Expand Down Expand Up @@ -232,7 +232,7 @@ QSharedPointer<ModulusPoly> ModulusPoly::multiply(int scalar)
}
if (scalar == 1)
{
return QSharedPointer<ModulusPoly>(this);
return QSharedPointer<ModulusPoly>(new ModulusPoly(*this));
}
int size = coefficients_->size();
QSharedPointer<std::vector<int>> product(new std::vector<int>(size));
Expand Down Expand Up @@ -274,7 +274,7 @@ std::vector<QSharedPointer<ModulusPoly>> ModulusPoly::divide(QSharedPointer<Modu
}

QSharedPointer<ModulusPoly> quotient(field_.getZero());
QSharedPointer<ModulusPoly> remainder(this);
QSharedPointer<ModulusPoly> remainder(new ModulusPoly(*this));

int denominatorLeadingTerm = other->getCoefficient(other->getDegree());
int inverseDenominatorLeadingTerm = field_.inverse(denominatorLeadingTerm);
Expand Down
2 changes: 1 addition & 1 deletion src/zxing/zxing/qrcode/decoder/DecodedBitStreamParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DecodedBitStreamParser {
std::string& result,
int count,
common::CharacterSetECI const *currentCharacterSetECI,
QSharedPointer<std::vector<QSharedPointer<std::vector<zxing::byte>> >> &byteSegments,
QSharedPointer<std::vector<QSharedPointer<std::vector<zxing::byte>> >> byteSegments,
Hashtable const& hints);
static void decodeAlphanumericSegment(QSharedPointer<BitSource> bits, std::string &result, int count, bool fc1InEffect);
static void decodeNumericSegment(QSharedPointer<BitSource> bits, std::string &result, int count);
Expand Down
4 changes: 2 additions & 2 deletions src/zxing/zxing/qrcode/decoder/QRDecodedBitStreamParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ std::string DecodedBitStreamParser::decodeByteSegment(QSharedPointer<BitSource>
string& result,
int count,
CharacterSetECI const * currentCharacterSetECI,
QSharedPointer<std::vector< QSharedPointer<std::vector<zxing::byte>>>>& byteSegments,
QSharedPointer<std::vector< QSharedPointer<std::vector<zxing::byte>>>> byteSegments,
Hashtable const& hints) {
int nBytes = count;
BitSource& bits (*bits_);
Expand Down Expand Up @@ -359,7 +359,7 @@ DecodedBitStreamParser::decode(QSharedPointer<std::vector<zxing::byte>> bytes,
BitSource& bits (*bits_);
string result;
result.reserve(50);
QSharedPointer<std::vector< QSharedPointer<std::vector<zxing::byte>>>> byteSegments (0);
QSharedPointer<std::vector< QSharedPointer<std::vector<zxing::byte>>>> byteSegments (new std::vector< QSharedPointer<std::vector<zxing::byte>>>());
const CharacterSetECI* currentCharacterSetECI = 0;
string charSet = "";
try {
Expand Down
2 changes: 1 addition & 1 deletion src/zxing/zxing/qrcode/detector/QRFinderPatternFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ QSharedPointer<FinderPatternInfo> FinderPatternFinder::find(DecodeHints const &h

patternInfo.clear();
for (size_t i = 0; i < patternInfoResPoints.size(); i++)
patternInfo.push_back(QSharedPointer<FinderPattern>(static_cast<FinderPattern *>(&*patternInfoResPoints[i])));
patternInfo.push_back(qSharedPointerCast<FinderPattern>(patternInfoResPoints[i]));

QSharedPointer<FinderPatternInfo> result(new FinderPatternInfo(patternInfo));
return result;
Expand Down