mirror of https://github.com/status-im/qzxing.git
First working version of whole-project use of QSharedData
This commit is contained in:
parent
a36b859df3
commit
aee14aef71
|
@ -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_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//}
|
||||
}
|
||||
|
|
|
@ -21,109 +21,109 @@
|
|||
#include <iostream>
|
||||
#include <QSharedPointer>
|
||||
|
||||
//namespace zxing {
|
||||
namespace zxing {
|
||||
|
||||
///* base class for reference-counted objects */
|
||||
//class Counted {
|
||||
//private:
|
||||
// size_t count_;
|
||||
//public:
|
||||
// Counted();
|
||||
/* base class for reference-counted objects */
|
||||
class Counted {
|
||||
private:
|
||||
size_t count_;
|
||||
public:
|
||||
Counted();
|
||||
|
||||
// virtual ~Counted();
|
||||
virtual ~Counted();
|
||||
|
||||
// Counted *retain();
|
||||
Counted *retain();
|
||||
|
||||
// void release();
|
||||
void release();
|
||||
|
||||
// /* return the current count for denugging purposes or similar */
|
||||
// size_t count() const;
|
||||
//};
|
||||
/* 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_);
|
||||
// }
|
||||
/* 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_);
|
||||
// }
|
||||
template<class Y>
|
||||
Ref(const QSharedPointer<Y> &other) :
|
||||
object_(0) {
|
||||
reset(other.object_);
|
||||
}
|
||||
|
||||
// ~Ref() {
|
||||
// if (object_) {
|
||||
// object_->release();
|
||||
// }
|
||||
// }
|
||||
~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;
|
||||
// }
|
||||
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_;
|
||||
// }
|
||||
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 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 operator!=(const T* that) {
|
||||
return !(*this == that);
|
||||
}
|
||||
|
||||
// bool empty() const {
|
||||
// return object_ == 0;
|
||||
// }
|
||||
//};
|
||||
bool empty() const {
|
||||
return object_ == 0;
|
||||
}
|
||||
};
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
#endif // ZXING_COUNTED_H
|
||||
|
|
|
@ -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() {}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
namespace zxing {
|
||||
class GenericGFPoly;
|
||||
|
||||
class GenericGF {
|
||||
class GenericGF {
|
||||
|
||||
private:
|
||||
std::vector<int> expTable;
|
||||
|
|
|
@ -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_;
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
|
|
@ -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_;
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
|
|
@ -51,7 +51,7 @@ private:
|
|||
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);
|
||||
|
|
|
@ -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_);
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue