summaryrefslogtreecommitdiff
path: root/xfa/fxbarcode/common
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-08-09 13:45:03 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-09 13:45:03 -0700
commite76203dbefd1df075a063ee019c3908513f6bee5 (patch)
tree2a763852e1d1de3eee6a67285ea96be2874bfb00 /xfa/fxbarcode/common
parentad5ac7584844b03c5ceed082e5f5158a632405cc (diff)
downloadpdfium-e76203dbefd1df075a063ee019c3908513f6bee5.tar.xz
Use smart pointers for class owned pointers in xfa/fxbarcode
For classes under xfa/fxbarcode, use smart pointers instead of raw pointer to make memory management easier. Also fix some styling issues along the changes. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2221023003
Diffstat (limited to 'xfa/fxbarcode/common')
-rw-r--r--xfa/fxbarcode/common/BC_CommonByteArray.cpp6
-rw-r--r--xfa/fxbarcode/common/BC_CommonByteArray.h8
-rw-r--r--xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp38
-rw-r--r--xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h22
4 files changed, 45 insertions, 29 deletions
diff --git a/xfa/fxbarcode/common/BC_CommonByteArray.cpp b/xfa/fxbarcode/common/BC_CommonByteArray.cpp
index be48d51b5b..afa8ac6836 100644
--- a/xfa/fxbarcode/common/BC_CommonByteArray.cpp
+++ b/xfa/fxbarcode/common/BC_CommonByteArray.cpp
@@ -44,16 +44,16 @@ CBC_CommonByteArray::CBC_CommonByteArray(uint8_t* byteArray, int32_t size) {
CBC_CommonByteArray::~CBC_CommonByteArray() {
FX_Free(m_bytes);
}
-int32_t CBC_CommonByteArray::At(int32_t index) {
+int32_t CBC_CommonByteArray::At(int32_t index) const {
return m_bytes[index] & 0xff;
}
void CBC_CommonByteArray::Set(int32_t index, int32_t value) {
m_bytes[index] = (uint8_t)value;
}
-int32_t CBC_CommonByteArray::Size() {
+int32_t CBC_CommonByteArray::Size() const {
return m_size;
}
-FX_BOOL CBC_CommonByteArray::IsEmpty() {
+FX_BOOL CBC_CommonByteArray::IsEmpty() const {
return m_size == 0;
}
void CBC_CommonByteArray::AppendByte(int32_t value) {
diff --git a/xfa/fxbarcode/common/BC_CommonByteArray.h b/xfa/fxbarcode/common/BC_CommonByteArray.h
index 2570f81c0f..cdda41b4fd 100644
--- a/xfa/fxbarcode/common/BC_CommonByteArray.h
+++ b/xfa/fxbarcode/common/BC_CommonByteArray.h
@@ -9,6 +9,8 @@
#include "core/fxcrt/include/fx_basic.h"
+// TODO(weili): The usage of this class should be replaced by
+// std::vector<uint8_t>.
class CBC_CommonByteArray {
public:
CBC_CommonByteArray();
@@ -16,10 +18,10 @@ class CBC_CommonByteArray {
CBC_CommonByteArray(uint8_t* byteArray, int32_t size);
virtual ~CBC_CommonByteArray();
- int32_t At(int32_t index);
+ int32_t At(int32_t index) const;
+ int32_t Size() const;
+ FX_BOOL IsEmpty() const;
void Set(int32_t index, int32_t value);
- int32_t Size();
- FX_BOOL IsEmpty();
void AppendByte(int32_t value);
void Reserve(int32_t capacity);
void Set(uint8_t* source, int32_t offset, int32_t count);
diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp
index da0ad3ff05..c9425dfa19 100644
--- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp
+++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp
@@ -23,18 +23,19 @@
#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h"
#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h"
-CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::QRCodeFild = nullptr;
+CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::QRCodeField = nullptr;
CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::DataMatrixField = nullptr;
+
void CBC_ReedSolomonGF256::Initialize() {
- QRCodeFild = new CBC_ReedSolomonGF256(0x011D);
- QRCodeFild->Init();
+ QRCodeField = new CBC_ReedSolomonGF256(0x011D);
+ QRCodeField->Init();
DataMatrixField = new CBC_ReedSolomonGF256(0x012D);
DataMatrixField->Init();
}
void CBC_ReedSolomonGF256::Finalize() {
- delete QRCodeFild;
- QRCodeFild = nullptr;
+ delete QRCodeField;
+ QRCodeField = nullptr;
delete DataMatrixField;
DataMatrixField = nullptr;
}
@@ -53,20 +54,22 @@ CBC_ReedSolomonGF256::CBC_ReedSolomonGF256(int32_t primitive) {
}
m_logTable[0] = 0;
}
+
void CBC_ReedSolomonGF256::Init() {
- m_zero = new CBC_ReedSolomonGF256Poly(this, 0);
- m_one = new CBC_ReedSolomonGF256Poly(this, 1);
-}
-CBC_ReedSolomonGF256::~CBC_ReedSolomonGF256() {
- delete m_zero;
- delete m_one;
+ m_zero.reset(new CBC_ReedSolomonGF256Poly(this, 0));
+ m_one.reset(new CBC_ReedSolomonGF256Poly(this, 1));
}
-CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetZero() {
- return m_zero;
+
+CBC_ReedSolomonGF256::~CBC_ReedSolomonGF256() {}
+
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetZero() const {
+ return m_zero.get();
}
-CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetOne() {
- return m_one;
+
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetOne() const {
+ return m_one.get();
}
+
CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::BuildMonomial(
int32_t degree,
int32_t coefficient,
@@ -88,12 +91,15 @@ CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::BuildMonomial(
BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
return temp;
}
+
int32_t CBC_ReedSolomonGF256::AddOrSubtract(int32_t a, int32_t b) {
return a ^ b;
}
+
int32_t CBC_ReedSolomonGF256::Exp(int32_t a) {
return m_expTable[a];
}
+
int32_t CBC_ReedSolomonGF256::Log(int32_t a, int32_t& e) {
if (a == 0) {
e = BCExceptionAIsZero;
@@ -101,6 +107,7 @@ int32_t CBC_ReedSolomonGF256::Log(int32_t a, int32_t& e) {
}
return m_logTable[a];
}
+
int32_t CBC_ReedSolomonGF256::Inverse(int32_t a, int32_t& e) {
if (a == 0) {
e = BCExceptionAIsZero;
@@ -108,6 +115,7 @@ int32_t CBC_ReedSolomonGF256::Inverse(int32_t a, int32_t& e) {
}
return m_expTable[255 - m_logTable[a]];
}
+
int32_t CBC_ReedSolomonGF256::Multiply(int32_t a, int32_t b) {
if (a == 0 || b == 0) {
return 0;
diff --git a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h
index cd788111ed..ec0f1ff549 100644
--- a/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h
+++ b/xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h
@@ -7,20 +7,23 @@
#ifndef XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256_H_
#define XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256_H_
+#include <memory>
+
#include "core/fxcrt/include/fx_basic.h"
#include "xfa/fxbarcode/utils.h"
class CBC_ReedSolomonGF256Poly;
+
class CBC_ReedSolomonGF256 {
public:
+ explicit CBC_ReedSolomonGF256(int32_t primitive);
+ virtual ~CBC_ReedSolomonGF256();
+
static void Initialize();
static void Finalize();
- static CBC_ReedSolomonGF256* QRCodeFild;
- static CBC_ReedSolomonGF256* DataMatrixField;
- CBC_ReedSolomonGF256(int32_t primitive);
- virtual ~CBC_ReedSolomonGF256();
- CBC_ReedSolomonGF256Poly* GetZero();
- CBC_ReedSolomonGF256Poly* GetOne();
+
+ CBC_ReedSolomonGF256Poly* GetZero() const;
+ CBC_ReedSolomonGF256Poly* GetOne() const;
CBC_ReedSolomonGF256Poly* BuildMonomial(int32_t degree,
int32_t coefficient,
int32_t& e);
@@ -31,11 +34,14 @@ class CBC_ReedSolomonGF256 {
int32_t Multiply(int32_t a, int32_t b);
virtual void Init();
+ static CBC_ReedSolomonGF256* QRCodeField;
+ static CBC_ReedSolomonGF256* DataMatrixField;
+
private:
int32_t m_expTable[256];
int32_t m_logTable[256];
- CBC_ReedSolomonGF256Poly* m_zero;
- CBC_ReedSolomonGF256Poly* m_one;
+ std::unique_ptr<CBC_ReedSolomonGF256Poly> m_zero;
+ std::unique_ptr<CBC_ReedSolomonGF256Poly> m_one;
};
#endif // XFA_FXBARCODE_COMMON_REEDSOLOMON_BC_REEDSOLOMONGF256_H_