picout and clean

This commit is contained in:
Бычков Андрей
2022-08-08 16:44:37 +03:00
parent 8551499a5e
commit 724a2dffcf
16 changed files with 242 additions and 187 deletions

View File

@@ -39,17 +39,21 @@ template <typename T>
class PIVector2D {
public:
inline PIVector2D() {rows_ = cols_ = 0;}
inline PIVector2D(size_t rows, size_t cols, const T & f = T()) {
rows_ = rows;
cols_ = cols;
mat.resize(rows*cols, f);
}
inline PIVector2D(size_t rows, size_t cols, const PIVector<T> & v) : rows_(rows), cols_(cols), mat(v) {
mat.resize(rows*cols);
}
inline PIVector2D(size_t rows, size_t cols, PIVector<T> && v) : rows_(rows), cols_(cols), mat(std::move(v)) {
mat.resize(rows*cols);
}
inline PIVector2D(const PIVector<PIVector<T>> & v) {
rows_ = v.size();
if (rows_) {
@@ -64,13 +68,21 @@ public:
}
inline size_t rows() const {return rows_;}
inline size_t cols() const {return cols_;}
inline size_t size() const {return mat.size();}
inline ssize_t size_s() const {return mat.size_s();}
inline size_t length() const {return mat.length();}
inline size_t capacity() const {return mat.capacity();}
inline bool isEmpty() const {return mat.isEmpty();}
inline bool isNotEmpty() const {return mat.isNotEmpty();}
class Row {
friend class PIVector2D<T>;
private:
@@ -243,16 +255,19 @@ public:
}
inline bool operator !=(const PIVector2D<T> & t) const {return !(*this == t);}
PIVector<PIVector<T> > toVectors() const {
inline PIVector<PIVector<T> > toVectors() const {
PIVector<PIVector<T> > ret;
ret.reserve(rows_);
for(size_t i = 0; i < rows_; ++i)
ret << PIVector<T>(mat.data(i*cols_), cols_);
return ret;
}
PIVector<T> toPlainVector() const {return mat;}
PIVector<T> & plainVector() {return mat;}
const PIVector<T> & plainVector() const {return mat;}
inline PIVector<T> toPlainVector() const {return mat;}
inline PIVector<T> & plainVector() {return mat;}
inline const PIVector<T> & plainVector() const {return mat;}
inline void swap(PIVector2D<T> & other) {
mat.swap(other.mat);
@@ -275,11 +290,16 @@ public:
mat.clear();
}
void forEach(std::function<void(const T &)> f) const {
template <typename ST>
inline PIVector2D<ST> map(std::function<ST(const T & e)> f) const {
return PIVector2D<ST>(rows_, cols_, mat.map(f));
}
inline void forEach(std::function<void(const T &)> f) const {
mat.forEach(f);
}
PIVector2D<T> & forEach(std::function<void(T &)> f) {
inline PIVector2D<T> & forEach(std::function<void(T &)> f) {
mat.forEach(f);
return *this;
}