make line endings consistent

git-svn-id: https://zxing.googlecode.com/svn/trunk@1981 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2011-10-19 14:25:51 +00:00
parent a71d01c4a3
commit b910002170

View file

@ -1,207 +1,207 @@
#ifndef __ARRAY_H__ #ifndef __ARRAY_H__
#define __ARRAY_H__ #define __ARRAY_H__
/* /*
* Array.h * Array.h
* zxing * zxing
* *
* Copyright 2010 ZXing authors All rights reserved. * Copyright 2010 ZXing authors All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <vector> #include <vector>
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
#include <iostream> #include <iostream>
#include <typeinfo> #include <typeinfo>
#endif #endif
#include <zxing/common/Counted.h> #include <zxing/common/Counted.h>
namespace zxing { namespace zxing {
template<typename T> class Array : public Counted { template<typename T> class Array : public Counted {
protected: protected:
public: public:
std::vector<T> values_; std::vector<T> values_;
Array(size_t n) : Array(size_t n) :
Counted(), values_(n, T()) { Counted(), values_(n, T()) {
} }
Array(T *ts, size_t n) : Array(T *ts, size_t n) :
Counted(), values_(ts, ts+n) { Counted(), values_(ts, ts+n) {
} }
Array(T v, size_t n) : Array(T v, size_t n) :
Counted(), values_(n, v) { Counted(), values_(n, v) {
} }
Array(std::vector<T> &v) : Array(std::vector<T> &v) :
Counted(), values_(v) { Counted(), values_(v) {
} }
Array(Array<T> &other) : Array(Array<T> &other) :
Counted(), values_(other.values_) { Counted(), values_(other.values_) {
} }
Array(Array<T> *other) : Array(Array<T> *other) :
Counted(), values_(other->values_) { Counted(), values_(other->values_) {
} }
virtual ~Array() { virtual ~Array() {
} }
Array<T>& operator=(const Array<T> &other) { Array<T>& operator=(const Array<T> &other) {
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "assigning values from Array " << &other << " to this Array " << this << ", "; cout << "assigning values from Array " << &other << " to this Array " << this << ", ";
#endif #endif
values_ = other.values_; values_ = other.values_;
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "new size = " << values_.size() << "\n"; cout << "new size = " << values_.size() << "\n";
#endif #endif
return *this; return *this;
} }
Array<T>& operator=(const std::vector<T> &array) { Array<T>& operator=(const std::vector<T> &array) {
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "assigning values from Array " << &array << " to this Array " << this << ", "; cout << "assigning values from Array " << &array << " to this Array " << this << ", ";
#endif #endif
values_ = array; values_ = array;
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "new size = " << values_.size() << "\n"; cout << "new size = " << values_.size() << "\n";
#endif #endif
return *this; return *this;
} }
T operator[](size_t i) const { T operator[](size_t i) const {
return values_[i]; return values_[i];
} }
T& operator[](size_t i) { T& operator[](size_t i) {
return values_[i]; return values_[i];
} }
size_t size() const { size_t size() const {
return values_.size(); return values_.size();
} }
std::vector<T> values() const { std::vector<T> values() const {
return values_; return values_;
} }
std::vector<T>& values() { std::vector<T>& values() {
return values_; return values_;
} }
}; };
template<typename T> class ArrayRef : public Counted { template<typename T> class ArrayRef : public Counted {
private: private:
public: public:
Array<T> *array_; Array<T> *array_;
ArrayRef() : ArrayRef() :
array_(0) { array_(0) {
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "instantiating empty ArrayRef " << this << "\n"; cout << "instantiating empty ArrayRef " << this << "\n";
#endif #endif
} }
ArrayRef(size_t n) : ArrayRef(size_t n) :
array_(0) { array_(0) {
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "instantiating ArrayRef " << this << "with size " << n << "\n"; cout << "instantiating ArrayRef " << this << "with size " << n << "\n";
#endif #endif
reset(new Array<T> (n)); reset(new Array<T> (n));
} }
ArrayRef(T *ts, size_t n) : ArrayRef(T *ts, size_t n) :
array_(0) { array_(0) {
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "instantiating ArrayRef " << this << "with " << n << " elements at " << (void *)ts << "\n"; cout << "instantiating ArrayRef " << this << "with " << n << " elements at " << (void *)ts << "\n";
#endif #endif
reset(new Array<T> (ts, n)); reset(new Array<T> (ts, n));
} }
ArrayRef(Array<T> *a) : ArrayRef(Array<T> *a) :
array_(0) { array_(0) {
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "instantiating ArrayRef " << this << " from pointer:\n"; cout << "instantiating ArrayRef " << this << " from pointer:\n";
#endif #endif
reset(a); reset(a);
} }
ArrayRef(const Array<T> &a) : ArrayRef(const Array<T> &a) :
array_(0) { array_(0) {
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "instantiating ArrayRef " << this << " from reference to Array " << (void *)&a << ":\n"; cout << "instantiating ArrayRef " << this << " from reference to Array " << (void *)&a << ":\n";
#endif #endif
reset(const_cast<Array<T> *>(&a)); reset(const_cast<Array<T> *>(&a));
} }
ArrayRef(const ArrayRef &other) : ArrayRef(const ArrayRef &other) :
array_(0) { array_(0) {
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "instantiating ArrayRef " << this << " from ArrayRef " << &other << ":\n"; cout << "instantiating ArrayRef " << this << " from ArrayRef " << &other << ":\n";
#endif #endif
reset(other.array_); reset(other.array_);
} }
template<class Y> template<class Y>
ArrayRef(const ArrayRef<Y> &other) : ArrayRef(const ArrayRef<Y> &other) :
array_(0) { array_(0) {
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "instantiating ArrayRef " << this << " from ArrayRef " << &other << ":\n"; cout << "instantiating ArrayRef " << this << " from ArrayRef " << &other << ":\n";
#endif #endif
reset(static_cast<const Array<T> *>(other.array_)); reset(static_cast<const Array<T> *>(other.array_));
} }
~ArrayRef() { ~ArrayRef() {
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "destroying ArrayRef " << this << " with " << (array_ ? typeid(*array_).name() : "NULL") << " " cout << "destroying ArrayRef " << this << " with " << (array_ ? typeid(*array_).name() : "NULL") << " "
<< array_ << "\n"; << array_ << "\n";
#endif #endif
if (array_) { if (array_) {
array_->release(); array_->release();
} }
array_ = 0; array_ = 0;
} }
T operator[](size_t i) const { T operator[](size_t i) const {
return (*array_)[i]; return (*array_)[i];
} }
T& operator[](size_t i) { T& operator[](size_t i) {
return (*array_)[i]; return (*array_)[i];
} }
size_t size() const { size_t size() const {
return array_->size(); return array_->size();
} }
void reset(Array<T> *a) { void reset(Array<T> *a) {
#ifdef DEBUG_COUNTING #ifdef DEBUG_COUNTING
cout << "resetting ArrayRef " << this << " from " << (array_ ? typeid(*array_).name() : "NULL") << " " cout << "resetting ArrayRef " << this << " from " << (array_ ? typeid(*array_).name() : "NULL") << " "
<< array_ << " to " << (a ? typeid(*a).name() : "NULL") << " " << a << "\n"; << array_ << " to " << (a ? typeid(*a).name() : "NULL") << " " << a << "\n";
#endif #endif
if (a) { if (a) {
a->retain(); a->retain();
} }
if (array_) { if (array_) {
array_->release(); array_->release();
} }
array_ = a; array_ = a;
} }
void reset(const ArrayRef<T> &other) { void reset(const ArrayRef<T> &other) {
reset(other.array_); reset(other.array_);
} }
ArrayRef<T>& operator=(const ArrayRef<T> &other) { ArrayRef<T>& operator=(const ArrayRef<T> &other) {
reset(other); reset(other);
return *this; return *this;
} }
ArrayRef<T>& operator=(Array<T> *a) { ArrayRef<T>& operator=(Array<T> *a) {
reset(a); reset(a);
return *this; return *this;
} }
Array<T>& operator*() { Array<T>& operator*() {
return *array_; return *array_;
} }
Array<T>* operator->() { Array<T>* operator->() {
return array_; return array_;
} }
}; };
} // namespace zxing } // namespace zxing
#endif // __ARRAY_H__ #endif // __ARRAY_H__