git-svn-id: svn://db.shs.com.ru/pip@474 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -27,5 +27,6 @@
|
||||
#include "piset.h"
|
||||
#include "pilist.h"
|
||||
#include "pistack.h"
|
||||
#include "pivector2d.h"
|
||||
|
||||
#endif // PICONTAINERSMODULE_H
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
#ifndef PIFRAME_H
|
||||
#define PIFRAME_H
|
||||
#include "pivector.h"
|
||||
|
||||
template <typename T>
|
||||
class PIFrame {
|
||||
public:
|
||||
inline PIFrame() {rows_ = cols_ = 0;}
|
||||
inline PIFrame(size_t rows, size_t cols, const T & f = T()) {
|
||||
rows_ = rows;
|
||||
cols_ = cols;
|
||||
mat.resize(rows*cols, f);
|
||||
}
|
||||
inline PIFrame(size_t rows, size_t cols, const PIVector<T> & v) {
|
||||
mat = v;
|
||||
rows_ = rows;
|
||||
cols_ = cols;
|
||||
mat.resize(rows*cols);
|
||||
}
|
||||
inline PIFrame(const PIVector<PIVector<T> > & v) {
|
||||
rows_ = v.size();
|
||||
if (rows_) {
|
||||
cols_ = v[0].size();
|
||||
for (size_t i = 0; i < rows_; i++) {
|
||||
mat.append(v[i]);
|
||||
}
|
||||
mat.resize(rows_*cols_);
|
||||
}
|
||||
if (mat.isEmpty()) rows_ = cols_ = 0;
|
||||
}
|
||||
|
||||
inline size_t rows() const {return rows_;}
|
||||
inline size_t cols() const {return cols_;}
|
||||
inline size_t size_all() const {return mat.size();}
|
||||
inline ssize_t size_s_all() const {return mat.size_s();}
|
||||
inline bool isEmpty() const {return mat.isEmpty();}
|
||||
|
||||
class PIFrameRow {
|
||||
friend class PIFrame<T>;
|
||||
private:
|
||||
inline PIFrameRow(PIFrame<T> * p, size_t row) : p_(p) {st_ = p_->cols_ * row;}
|
||||
PIFrame<T> * p_;
|
||||
size_t st_;
|
||||
public:
|
||||
inline size_t size() const {return p_->cols_;}
|
||||
inline T & operator [](size_t index) {return p_->mat[st_ + index];}
|
||||
inline const T & operator [](size_t index) const {return p_->mat[st_ + index];}
|
||||
};
|
||||
|
||||
class PIFrameRowConst {
|
||||
friend class PIFrame<T>;
|
||||
private:
|
||||
inline PIFrameRowConst(const PIFrame<T> * p, size_t row) : p_(p) {st_ = p_->cols_ * row;}
|
||||
const PIFrame<T> * p_;
|
||||
size_t st_;
|
||||
public:
|
||||
inline size_t size() const {return p_->cols_;}
|
||||
inline const T & operator [](size_t index) const {return p_->mat[st_ + index];}
|
||||
};
|
||||
|
||||
|
||||
inline PIFrameRow operator[](size_t index) {return PIFrameRow(this, index);}
|
||||
inline PIFrameRowConst operator[](size_t index) const {return PIFrameRowConst(this, index);}
|
||||
|
||||
PIVector<PIVector<T> > toVectors() const {
|
||||
PIVector<PIVector<T> > ret;
|
||||
for(size_t i = 0; i < rows_; ++i)
|
||||
ret << PIVector<T>(mat.data(i*cols_), cols_);
|
||||
return ret;
|
||||
}
|
||||
PIVector<T> toPlainVector() const {return mat;}
|
||||
|
||||
private:
|
||||
size_t rows_, cols_;
|
||||
PIVector<T> mat;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline PICout operator <<(PICout s, const PIFrame<T> & v) {
|
||||
s.setControl(0, true);
|
||||
s << "{";
|
||||
for (size_t i = 0; i < v.rows(); ++i) {
|
||||
s << "{ ";
|
||||
for (size_t j = 0; j < v.cols(); ++j) {
|
||||
s << v[i][j];
|
||||
if (j < v.cols() - 1) s << ", ";
|
||||
}
|
||||
s << " }";
|
||||
if (i < v.rows() - 1) s << PICoutManipulators::NewLine ;
|
||||
}
|
||||
if (v.isEmpty()) s << "{ }";
|
||||
s << "}";
|
||||
s.restoreControl();
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // PIFRAME_H
|
||||
125
src_main/containers/pivector2d.h
Normal file
125
src_main/containers/pivector2d.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/*! \file pivecto2Dr.h
|
||||
* \brief 2D wrapper around PIVector
|
||||
*
|
||||
* This file declares PIVector
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
2D wrapper around PIVector
|
||||
Copyright (C) 2017 Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIVECTOR2D_H
|
||||
#define PIVECTOR2D_H
|
||||
|
||||
#include "pivector.h"
|
||||
|
||||
|
||||
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) {
|
||||
mat = v;
|
||||
rows_ = rows;
|
||||
cols_ = cols;
|
||||
mat.resize(rows*cols);
|
||||
}
|
||||
inline PIVector2D(const PIVector<PIVector<T> > & v) {
|
||||
rows_ = v.size();
|
||||
if (rows_) {
|
||||
cols_ = v[0].size();
|
||||
for (size_t i = 0; i < rows_; i++) {
|
||||
mat.append(v[i]);
|
||||
}
|
||||
mat.resize(rows_*cols_);
|
||||
}
|
||||
if (mat.isEmpty()) rows_ = cols_ = 0;
|
||||
}
|
||||
|
||||
inline size_t rows() const {return rows_;}
|
||||
inline size_t cols() const {return cols_;}
|
||||
inline size_t size_all() const {return mat.size();}
|
||||
inline ssize_t size_s_all() const {return mat.size_s();}
|
||||
inline bool isEmpty() const {return mat.isEmpty();}
|
||||
|
||||
class Row {
|
||||
friend class PIVector2D<T>;
|
||||
private:
|
||||
inline Row(PIVector2D<T> * p, size_t row) : p_(p) {st_ = p_->cols_ * row;}
|
||||
PIVector2D<T> * p_;
|
||||
size_t st_;
|
||||
public:
|
||||
inline size_t size() const {return p_->cols_;}
|
||||
inline T & operator [](size_t index) {return p_->mat[st_ + index];}
|
||||
inline const T & operator [](size_t index) const {return p_->mat[st_ + index];}
|
||||
};
|
||||
|
||||
class RowConst {
|
||||
friend class PIVector2D<T>;
|
||||
private:
|
||||
inline RowConst(const PIVector2D<T> * p, size_t row) : p_(p) {st_ = p_->cols_ * row;}
|
||||
const PIVector2D<T> * p_;
|
||||
size_t st_;
|
||||
public:
|
||||
inline size_t size() const {return p_->cols_;}
|
||||
inline const T & operator [](size_t index) const {return p_->mat[st_ + index];}
|
||||
};
|
||||
|
||||
|
||||
inline Row operator[](size_t index) {return Row(this, index);}
|
||||
inline RowConst operator[](size_t index) const {return RowConst(this, index);}
|
||||
|
||||
PIVector<PIVector<T> > toVectors() const {
|
||||
PIVector<PIVector<T> > ret;
|
||||
for(size_t i = 0; i < rows_; ++i)
|
||||
ret << PIVector<T>(mat.data(i*cols_), cols_);
|
||||
return ret;
|
||||
}
|
||||
PIVector<T> toPlainVector() const {return mat;}
|
||||
|
||||
private:
|
||||
size_t rows_, cols_;
|
||||
PIVector<T> mat;
|
||||
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline PICout operator <<(PICout s, const PIVector2D<T> & v) {
|
||||
s.setControl(0, true);
|
||||
s << "{";
|
||||
for (size_t i = 0; i < v.rows(); ++i) {
|
||||
s << "{ ";
|
||||
for (size_t j = 0; j < v.cols(); ++j) {
|
||||
s << v[i][j];
|
||||
if (j < v.cols() - 1) s << ", ";
|
||||
}
|
||||
s << " }";
|
||||
if (i < v.rows() - 1) s << PICoutManipulators::NewLine ;
|
||||
}
|
||||
if (v.isEmpty()) s << "{ }";
|
||||
s << "}";
|
||||
s.restoreControl();
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // PIVECTOR2D_H
|
||||
@@ -180,8 +180,8 @@ void PISharedMemory::configureFromFullPathDevice(const PIString & full_path) {
|
||||
for (int i = 0; i < pl.size_s(); ++i) {
|
||||
PIString p(pl[i]);
|
||||
switch (i) {
|
||||
case 0: setPath(p); break;
|
||||
case 1: dsize = p.toInt(); break;
|
||||
case 0: setPath(p); break;
|
||||
case 1: dsize = p.toInt(); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ PRIVATE_DEFINITION_START(PIProcess)
|
||||
#else
|
||||
pid_t pid;
|
||||
#endif
|
||||
FILE * tf_in, * tf_out, * tf_err;
|
||||
FILE * tf_in, * tf_out, * tf_err;
|
||||
PRIVATE_DEFINITION_END(PIProcess)
|
||||
|
||||
|
||||
|
||||
@@ -91,12 +91,12 @@ private:
|
||||
void exec_();
|
||||
void startProc(bool detached);
|
||||
|
||||
PRIVATE_DECLARATION
|
||||
PIStringList args, env;
|
||||
PIString wd;
|
||||
PIByteArray out;
|
||||
PIFile f_in, f_out, f_err;
|
||||
bool g_in, g_out, g_err, t_in, t_out, t_err;
|
||||
PRIVATE_DECLARATION
|
||||
int exit_code, sz;
|
||||
bool is_exec;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user