From 724a2dffcf7ab1579b47e85e7c7aa353080f90e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Mon, 8 Aug 2022 16:44:37 +0300 Subject: [PATCH] picout and clean --- CMakeLists.txt | 2 +- libs/main/containers/pideque.h | 2 +- libs/main/containers/pimap.h | 144 +++++++++++++------------- libs/main/containers/piqueue.h | 1 - libs/main/containers/piset.h | 2 - libs/main/containers/pistack.h | 3 +- libs/main/containers/pivector.h | 2 +- libs/main/containers/pivector2d.h | 32 ++++-- libs/main/core/pichar.h | 6 +- libs/main/core/picout.cpp | 108 ++++++++++++------- libs/main/core/picout.h | 54 +++++----- libs/main/core/pistring.cpp | 14 ++- libs/main/core/pistring.h | 16 +-- libs/main/io_utils/pifiletransfer.cpp | 3 +- libs/main/math/pimathvector.h | 20 +++- main.cpp | 20 +--- 16 files changed, 242 insertions(+), 187 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a860867b..d0dab138 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(pip) set(pip_MAJOR 2) -set(pip_MINOR 99) +set(pip_MINOR 100) set(pip_REVISION 0) set(pip_SUFFIX ) set(pip_COMPANY SHS) diff --git a/libs/main/containers/pideque.h b/libs/main/containers/pideque.h index 3dcc51c3..4311802a 100644 --- a/libs/main/containers/pideque.h +++ b/libs/main/containers/pideque.h @@ -196,7 +196,7 @@ public: other._reset(); } - inline virtual ~PIDeque() { + inline ~PIDeque() { PIINTROSPECTION_CONTAINER_DELETE(T) PIINTROSPECTION_CONTAINER_FREE(T, (pid_rsize)) deleteT(pid_data + pid_start, pid_size); diff --git a/libs/main/containers/pimap.h b/libs/main/containers/pimap.h index 60f5c216..3a8dd17d 100644 --- a/libs/main/containers/pimap.h +++ b/libs/main/containers/pimap.h @@ -91,15 +91,15 @@ public: //! \~english Constructs an empty map. //! \~russian Создает пустой словарь. - PIMap() {} + inline PIMap() {} //! \~english Copy constructor. //! \~russian Копирующий конструктор. - PIMap(const PIMap & other) {*this = other;} + inline PIMap(const PIMap & other) {*this = other;} //! \~english Move constructor. //! \~russian Перемещающий конструктор. - PIMap(PIMap && other) : pim_content(std::move(other.pim_content)), pim_index(std::move(other.pim_index)) {} + inline PIMap(PIMap && other) : pim_content(std::move(other.pim_content)), pim_index(std::move(other.pim_index)) {} //! \~english Contructs map from //! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list). @@ -110,7 +110,7 @@ public: //! PIMap m{{1, "a"}, {2, "b"}}; //! piCout << m; // {1, 2, 3} //! \endcode - PIMap(std::initializer_list> init_list) { + inline PIMap(std::initializer_list> init_list) { for (auto i: init_list) { insert(std::get<0>(i), std::get<1>(i)); } @@ -118,7 +118,7 @@ public: //! \~english Assign operator. //! \~russian Оператор присваивания. - PIMap & operator =(const PIMap & other) { + inline PIMap & operator =(const PIMap & other) { if (this == &other) return *this; clear(); pim_content = other.pim_content; @@ -128,7 +128,7 @@ public: //! \~english Assign move operator. //! \~russian Оператор перемещающего присваивания. - PIMap & operator =(PIMap && other) { + inline PIMap & operator =(PIMap && other) { swap(other); return *this; } @@ -212,53 +212,53 @@ public: }; - iterator begin() {return iterator(this, 0);} + inline iterator begin() {return iterator(this, 0);} - iterator end() {return iterator(this, size());} + inline iterator end() {return iterator(this, size());} - const_iterator begin() const {return const_iterator(this, 0);} + inline const_iterator begin() const {return const_iterator(this, 0);} - const_iterator end() const {return const_iterator(this, size());} + inline const_iterator end() const {return const_iterator(this, size());} - const_iterator constBegin() const {return const_iterator(this, 0);} + inline const_iterator constBegin() const {return const_iterator(this, 0);} - const_iterator constEnd() const {return const_iterator(this, size());} + inline const_iterator constEnd() const {return const_iterator(this, size());} - reverse_iterator rbegin() {return reverse_iterator(this, size() - 1);} + inline reverse_iterator rbegin() {return reverse_iterator(this, size() - 1);} - reverse_iterator rend() {return reverse_iterator(this, -1);} + inline reverse_iterator rend() {return reverse_iterator(this, -1);} - const_reverse_iterator rbegin() const {return const_reverse_iterator(this, size() - 1);} + inline const_reverse_iterator rbegin() const {return const_reverse_iterator(this, size() - 1);} - const_reverse_iterator rend() const {return const_reverse_iterator(this, -1);} + inline const_reverse_iterator rend() const {return const_reverse_iterator(this, -1);} - const_reverse_iterator constRbegin() const {return const_reverse_iterator(this, size() - 1);} + inline const_reverse_iterator constRbegin() const {return const_reverse_iterator(this, size() - 1);} - const_reverse_iterator constRend() const {return const_reverse_iterator(this, -1);} + inline const_reverse_iterator constRend() const {return const_reverse_iterator(this, -1);} //! \relatesalso PIMapIteratorConst - PIMapIteratorConst makeIterator() const {return PIMapIteratorConst(*this);} + inline PIMapIteratorConst makeIterator() const {return PIMapIteratorConst(*this);} //! \relatesalso PIMapIterator - PIMapIterator makeIterator() {return PIMapIterator(*this);} + inline PIMapIterator makeIterator() {return PIMapIterator(*this);} //! \relatesalso PIMapIteratorConstReverse - PIMapIteratorConstReverse makeReverseIterator() const {return PIMapIteratorConstReverse(*this);} + inline PIMapIteratorConstReverse makeReverseIterator() const {return PIMapIteratorConstReverse(*this);} //! \relatesalso PIMapIteratorReverse - PIMapIteratorReverse makeReverseIterator() {return PIMapIteratorReverse(*this);} + inline PIMapIteratorReverse makeReverseIterator() {return PIMapIteratorReverse(*this);} - size_t size() const {return pim_content.size();} + inline size_t size() const {return pim_content.size();} - int size_s() const {return pim_content.size_s();} + inline int size_s() const {return pim_content.size_s();} - size_t length() const {return pim_content.size();} + inline size_t length() const {return pim_content.size();} - bool isEmpty() const {return (pim_content.size() == 0);} + inline bool isEmpty() const {return (pim_content.size() == 0);} - bool isNotEmpty() const {return (pim_content.size() > 0);} + inline bool isNotEmpty() const {return (pim_content.size() > 0);} - T & operator [](const Key & key) { + inline T & operator [](const Key & key) { bool f(false); ssize_t i = _find(key, f); if (f) return pim_content[pim_index[i].index]; @@ -266,9 +266,10 @@ public: pim_index.insert(i, MapIndex(key, pim_content.size() - 1)); return pim_content.back(); } - T at(const Key & key) const {return value(key);} - T take(const Key & key) const { + inline T at(const Key & key) const {return value(key);} + + inline T take(const Key & key) const { bool f(false); ssize_t i = _find(key, f); if (!f) return T(); @@ -277,7 +278,7 @@ public: return ret; } - PIMap & operator <<(const PIMap & other) { + inline PIMap & operator <<(const PIMap & other) { #ifndef NDEBUG if (&other == this) { printf("error with PIMap<%s, %s>::<<\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T)); @@ -300,28 +301,28 @@ public: return *this; } - bool operator ==(const PIMap & t) const { + inline bool operator ==(const PIMap & t) const { return (pim_content == t.pim_content && pim_index == t.pim_index); } - bool operator !=(const PIMap & t) const { + inline bool operator !=(const PIMap & t) const { return (pim_content != t.pim_content || pim_index != t.pim_index); } - bool contains(const Key & key) const { + inline bool contains(const Key & key) const { bool f(false); _find(key, f); return f; } - bool containsValue(const T & value) const { + inline bool containsValue(const T & value) const { return pim_content.contains(value); } - PIMap & reserve(size_t new_size) { + inline PIMap & reserve(size_t new_size) { pim_content.reserve(new_size); pim_index.reserve(new_size); return *this; } - PIMap & remove(const Key & key) { + inline PIMap & remove(const Key & key) { bool f(false); ssize_t i = _find(key, f); if (f) _remove(i); @@ -329,7 +330,7 @@ public: } - PIMap & removeWhere(std::function test) { + inline PIMap & removeWhere(std::function test) { for (int i = 0; i < pim_index.size_s(); ++i) { if (pim_index[i].key, pim_content[pim_index[i].index]) { _remove(i); @@ -338,20 +339,20 @@ public: } } - PIMap & erase(const Key & key) {return remove(key);} + inline PIMap & erase(const Key & key) {return remove(key);} - PIMap & clear() { + inline PIMap & clear() { pim_content.clear(); pim_index.clear(); return *this; } - void swap(PIMap & other) { + inline void swap(PIMap & other) { pim_content.swap(other.pim_content); pim_index.swap(other.pim_index); } - PIMap & insert(const Key & key, const T & value) { + inline PIMap & insert(const Key & key, const T & value) { bool f(false); ssize_t i = _find(key, f); if (f) { @@ -362,7 +363,8 @@ public: } return *this; } - PIMap & insert(const Key & key, T && value) { + + inline PIMap & insert(const Key & key, T && value) { bool f(false); ssize_t i = _find(key, f); if (f) { @@ -373,7 +375,8 @@ public: } return *this; } - PIMap & insert(const PIPair & pair) { + + inline PIMap & insert(const PIPair & pair) { bool f(false); ssize_t i = _find(pair.first, f); if (f) { @@ -384,7 +387,8 @@ public: } return *this; } - PIMap & insert(PIPair && pair) { + + inline PIMap & insert(PIPair && pair) { bool f(false); Key k(std::move(pair.first)); ssize_t i = _find(k, f); @@ -397,16 +401,16 @@ public: return *this; } - T value(const Key & key, const T & default_ = T()) const { + inline T value(const Key & key, const T & default_ = T()) const { bool f(false); ssize_t i = _find(key, f); if (!f) return default_; return pim_content[pim_index[i].index]; } - PIVector values() const {return pim_content;} + inline PIVector values() const {return pim_content;} - Key key(const T & value_, const Key & default_ = Key()) const { + inline Key key(const T & value_, const Key & default_ = Key()) const { for (int i = 0; i < pim_index.size_s(); ++i) { if (pim_content[pim_index[i].index] == value_) { return pim_index[i].key; @@ -415,7 +419,7 @@ public: return default_; } - PIVector keys() const { + inline PIVector keys() const { PIVector ret; ret.reserve(pim_index.size()); for (int i = 0; i < pim_index.size_s(); ++i) { @@ -424,7 +428,7 @@ public: return ret; } - void forEach(std::function f) const { + inline void forEach(std::function f) const { for (int i = 0; i < pim_index.size_s(); ++i) { f(pim_index[i].key, pim_content[pim_index[i].index]); } @@ -465,7 +469,7 @@ private: template friend PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIDeque::MapIndex> & v); - ssize_t _binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const { + inline ssize_t _binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const { ssize_t mid; while (first <= last) { mid = (first + last) / 2; @@ -477,7 +481,7 @@ private: return first; } - ssize_t _find(const Key & k, bool & found) const { + inline ssize_t _find(const Key & k, bool & found) const { if (pim_index.isEmpty()) { found = false; return 0; @@ -485,7 +489,7 @@ private: return _binarySearch(0, pim_index.size_s() - 1, k, found); } - void _remove(ssize_t index) { + inline void _remove(ssize_t index) { size_t ci = pim_index[index].index, bi = pim_index.size() - 1; pim_index.remove(index); for (size_t i = 0; i < pim_index.size(); ++i) { @@ -498,18 +502,18 @@ private: pim_content.resize(pim_index.size()); } - const value_type _pair(ssize_t index) const { + inline const value_type _pair(ssize_t index) const { if (index < 0 || index >= pim_index.size_s()) return value_type(); return value_type(pim_index[index].key, pim_content[pim_index[index].index]); } - Key & _key(ssize_t index) {return pim_index[index].key;} + inline Key & _key(ssize_t index) {return pim_index[index].key;} - const Key & _key(ssize_t index) const {return pim_index[index].key;} + inline const Key & _key(ssize_t index) const {return pim_index[index].key;} - T & _value(ssize_t index) {return pim_content[pim_index[index].index];} + inline T & _value(ssize_t index) {return pim_content[pim_index[index].index];} - const T & _value(ssize_t index) const {return pim_content[pim_index[index].index];} + inline const T & _value(ssize_t index) const {return pim_content[pim_index[index].index];} PIVector pim_content; @@ -549,19 +553,19 @@ template class PIMapIteratorConst { typedef PIMap MapType; public: - PIMapIteratorConst(const PIMap & map): m(map), pos(-1) {} + inline PIMapIteratorConst(const PIMap & map): m(map), pos(-1) {} //! \~english Returns current key. //! \~russian Возвращает ключ текущего элемента. //! \~\sa \a value() - const Key & key() const { + inline const Key & key() const { return m._key(pos); } //! \~english Returns current value. //! \~russian Возвращает значение текущего элемента. //! \~\sa \a key() - const T & value() const { + inline const T & value() const { return m._value(pos); } @@ -625,19 +629,19 @@ template class PIMapIteratorConstReverse { typedef PIMap MapType; public: - PIMapIteratorConstReverse(const PIMap & map): m(map), pos(m.size_s()) {} + inline PIMapIteratorConstReverse(const PIMap & map): m(map), pos(m.size_s()) {} //! \~english Returns current key. //! \~russian Возвращает ключ текущего элемента. //! \~\sa \a value() - const Key & key() const { + inline const Key & key() const { return m._key(pos); } //! \~english Returns current value. //! \~russian Возвращает значение текущего элемента. //! \~\sa \a key() - const T & value() const { + inline const T & value() const { return m._value(pos); } @@ -701,19 +705,19 @@ template class PIMapIterator { typedef PIMap MapType; public: - PIMapIterator(PIMap & map): m(map), pos(-1) {} + inline PIMapIterator(PIMap & map): m(map), pos(-1) {} //! \~english Returns current key. //! \~russian Возвращает ключ текущего элемента. //! \~\sa \a value() - const Key & key() const { + inline const Key & key() const { return m._key(pos); } //! \~english Returns current value. //! \~russian Возвращает значение текущего элемента. //! \~\sa \a key() - T & value() { + inline T & value() { return m._value(pos); } @@ -777,19 +781,19 @@ template class PIMapIteratorReverse { typedef PIMap MapType; public: - PIMapIteratorReverse(PIMap & map): m(map), pos(m.size_s()) {} + inline PIMapIteratorReverse(PIMap & map): m(map), pos(m.size_s()) {} //! \~english Returns current key. //! \~russian Возвращает ключ текущего элемента. //! \~\sa \a value() - const Key & key() const { + inline const Key & key() const { return m._key(pos); } //! \~english Returns current value. //! \~russian Возвращает значение текущего элемента. //! \~\sa \a key() - T & value() { + inline T & value() { return m._value(pos); } diff --git a/libs/main/containers/piqueue.h b/libs/main/containers/piqueue.h index bd972f9d..8c58e360 100644 --- a/libs/main/containers/piqueue.h +++ b/libs/main/containers/piqueue.h @@ -33,7 +33,6 @@ template class PIQueue: public PIDeque { public: PIQueue() {} - virtual ~PIQueue() {} PIDeque & enqueue(const T & v) {PIDeque::push_front(v); return *this;} PIDeque & enqueue(T && v) {PIDeque::push_front(std::move(v)); return *this;} T dequeue() {return PIDeque::take_back();} diff --git a/libs/main/containers/piset.h b/libs/main/containers/piset.h index e0b28e63..3a0b7afe 100644 --- a/libs/main/containers/piset.h +++ b/libs/main/containers/piset.h @@ -42,8 +42,6 @@ public: //! Contructs an empty set PISet() {} - virtual ~PISet() {;} - //! Contructs set with one element "value" PISet(const T & value) {_CSet::insert(value, 0);} diff --git a/libs/main/containers/pistack.h b/libs/main/containers/pistack.h index 4e29502e..fdc0f903 100644 --- a/libs/main/containers/pistack.h +++ b/libs/main/containers/pistack.h @@ -30,8 +30,7 @@ template class PIStack: public PIVector { public: - PIStack() {;} - virtual ~PIStack() {;} + PIStack() {} PIVector & push(const T & v) {PIVector::push_back(v); return *this;} PIVector & push(T && v) {PIVector::push_back(std::move(v)); return *this;} T pop() {return PIVector::take_back();} diff --git a/libs/main/containers/pivector.h b/libs/main/containers/pivector.h index e731f419..14624ed2 100644 --- a/libs/main/containers/pivector.h +++ b/libs/main/containers/pivector.h @@ -196,7 +196,7 @@ public: v._reset(); } - inline virtual ~PIVector() { + inline ~PIVector() { PIINTROSPECTION_CONTAINER_DELETE(T) PIINTROSPECTION_CONTAINER_FREE(T, (piv_rsize)) deleteT(piv_data, piv_size); diff --git a/libs/main/containers/pivector2d.h b/libs/main/containers/pivector2d.h index f78e2908..aef42f28 100644 --- a/libs/main/containers/pivector2d.h +++ b/libs/main/containers/pivector2d.h @@ -39,17 +39,21 @@ template 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 & v) : rows_(rows), cols_(cols), mat(v) { mat.resize(rows*cols); } + inline PIVector2D(size_t rows, size_t cols, PIVector && v) : rows_(rows), cols_(cols), mat(std::move(v)) { mat.resize(rows*cols); } + inline PIVector2D(const PIVector> & 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; private: @@ -243,16 +255,19 @@ public: } inline bool operator !=(const PIVector2D & t) const {return !(*this == t);} - PIVector > toVectors() const { + inline PIVector > toVectors() const { PIVector > ret; ret.reserve(rows_); for(size_t i = 0; i < rows_; ++i) ret << PIVector(mat.data(i*cols_), cols_); return ret; } - PIVector toPlainVector() const {return mat;} - PIVector & plainVector() {return mat;} - const PIVector & plainVector() const {return mat;} + + inline PIVector toPlainVector() const {return mat;} + + inline PIVector & plainVector() {return mat;} + + inline const PIVector & plainVector() const {return mat;} inline void swap(PIVector2D & other) { mat.swap(other.mat); @@ -275,11 +290,16 @@ public: mat.clear(); } - void forEach(std::function f) const { + template + inline PIVector2D map(std::function f) const { + return PIVector2D(rows_, cols_, mat.map(f)); + } + + inline void forEach(std::function f) const { mat.forEach(f); } - PIVector2D & forEach(std::function f) { + inline PIVector2D & forEach(std::function f) { mat.forEach(f); return *this; } diff --git a/libs/main/core/pichar.h b/libs/main/core/pichar.h index cf312353..2accf07f 100644 --- a/libs/main/core/pichar.h +++ b/libs/main/core/pichar.h @@ -39,11 +39,11 @@ extern PIP_EXPORT char * __utf8name__; class PIP_EXPORT PIChar { friend class PIString; - friend PICout PIP_EXPORT operator <<(PICout s, const PIChar & v); + friend PICout operator <<(PICout s, const PIChar & v); public: //! \~english Contructs Ascii symbol //! \~russian Создает символ Ascii - PIChar(char c) {ch = c; ch &= 0xFF;} + PIChar(char c) {ch = c;} //! \~english Contructs ascii symbol //! \~russian Создает символ Ascii @@ -183,7 +183,7 @@ private: //! \relatesalso PIChar //! \~english Output operator to \a PICout //! \~russian Оператор вывода в \a PICout -PICout PIP_EXPORT operator <<(PICout s, const PIChar & v); +PIP_EXPORT PICout operator <<(PICout s, const PIChar & v); //! \relatesalso PIChar //! \~english Compare operator diff --git a/libs/main/core/picout.cpp b/libs/main/core/picout.cpp index ecada7b2..2edc0823 100644 --- a/libs/main/core/picout.cpp +++ b/libs/main/core/picout.cpp @@ -154,21 +154,13 @@ DWORD PICout::__Private__::smode = 0; #endif PICout::PICout(int controls): fo_(true), cc_(false), fc_(false), act_(true), cnb_(10), co_(controls) { + buffer_ = nullptr; init(); } PICout::PICout(bool active): fo_(true), cc_(false), fc_(false), act_(active), cnb_(10), co_(PICoutManipulators::DefaultControls) { buffer_ = nullptr; - if (act_) - init(); -} - - -PICout::PICout(PIString * buffer, int id, PIFlags controls): fo_(true), cc_(false), - fc_(false), act_(true), cnb_(10), co_(controls) { - init(); - buffer_ = buffer; - id_ = id; + if (act_) init(); } @@ -182,14 +174,16 @@ PICout::~PICout() { if (fc_) applyFormat(PICoutManipulators::Default); if (cc_) return; newLine(); - if ((co_ & NoLock) != NoLock) + if ((co_ & NoLock) != NoLock) { PICout::__mutex__().unlock(); - if (buffer_) + } + if (buffer_) { ((NotifierObject*)Notifier::object())->finished(id_, buffer_); + } } -PICout PICout::operator <<(const PICoutAction v) { +PICout & PICout::operator <<(PICoutAction v) { if (!act_) return *this; #ifdef WINDOWS CONSOLE_SCREEN_BUFFER_INFO sbi; @@ -198,8 +192,9 @@ PICout PICout::operator <<(const PICoutAction v) { #endif switch (v) { case PICoutManipulators::Flush: - if (!buffer_ && isOutputDeviceActive(StdOut)) + if (!buffer_ && isOutputDeviceActive(StdOut)) { std::cout << std::flush; + } break; case PICoutManipulators::Backspace: if (isOutputDeviceActive(StdOut)) { @@ -275,7 +270,7 @@ PICout PICout::operator <<(const PICoutAction v) { } -PICout PICout::operator <<(const PICoutManipulators::PICoutFormat v) { +PICout & PICout::operator <<(PICoutManipulators::PICoutFormat v) { switch (v) { case PICoutManipulators::Bin: cnb_ = 2; break; case PICoutManipulators::Oct: cnb_ = 8; break; @@ -287,7 +282,7 @@ PICout PICout::operator <<(const PICoutManipulators::PICoutFormat v) { } -PICout PICout::operator <<(const PIFlags & v) { +PICout & PICout::operator <<(PIFlags v) { if (v[PICoutManipulators::Bin]) cnb_ = 2; if (v[PICoutManipulators::Oct]) cnb_ = 8; if (v[PICoutManipulators::Dec]) cnb_ = 10; @@ -338,40 +333,73 @@ PICout PICout::operator <<(const PIFlags & v) if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v);\ if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() += PIString::fromNumber(v, 'g');\ }\ - } + }\ + return *this; -PICout PICout::operator <<(const char * v) {if (!act_ || !v) return *this; if (v[0] == '\0') return *this; space(); quote(); write(v); quote(); return *this;} +PICout & PICout::operator <<(const PIString & v) { + space(); + quote(); + write(v); + quote(); + return *this; +} -PICout PICout::operator <<(const bool v) {if (!act_) return *this; space(); if (v) write("true"); else write("false"); return *this;} +PICout & PICout::operator <<(const char * v) { + if (!act_ || !v) return *this; + if (v[0] == '\0') return *this; + space(); + quote(); + write(v); + quote(); + return *this; +} -PICout PICout::operator <<(const char v) {if (!act_) return *this; space(); write(v); return *this;} +PICout & PICout::operator <<(bool v) { + if (!act_) return *this; + space(); + if (v) write("true"); + else write("false"); + return *this; +} -PICout PICout::operator <<(const uchar v) {PIINTCOUT(ushort(v))} +PICout & PICout::operator <<(char v) { + if (!act_) return *this; + space(); + write(v); + return *this; +} -PICout PICout::operator <<(const short int v) {PIINTCOUT(v)} +PICout & PICout::operator <<(uchar v) {PIINTCOUT(ushort(v))} -PICout PICout::operator <<(const ushort v) {PIINTCOUT(v)} +PICout & PICout::operator <<(short int v) {PIINTCOUT(v)} -PICout PICout::operator <<(const int v) {PIINTCOUT(v)} +PICout & PICout::operator <<(ushort v) {PIINTCOUT(v)} -PICout PICout::operator <<(const uint v) {PIINTCOUT(v)} +PICout & PICout::operator <<(int v) {PIINTCOUT(v)} -PICout PICout::operator <<(const long v) {PIINTCOUT(v)} +PICout & PICout::operator <<(uint v) {PIINTCOUT(v)} -PICout PICout::operator <<(const ulong v) {PIINTCOUT(v)} +PICout & PICout::operator <<(long v) {PIINTCOUT(v)} -PICout PICout::operator <<(const llong v) {PIINTCOUT(v)} +PICout & PICout::operator <<(ulong v) {PIINTCOUT(v)} -PICout PICout::operator <<(const ullong v) {PIINTCOUT(v)} +PICout & PICout::operator <<(llong v) {PIINTCOUT(v)} -PICout PICout::operator <<(const float v) {if (!act_) return *this; space(); PIFLOATCOUT(v) return *this;} +PICout & PICout::operator <<(ullong v) {PIINTCOUT(v)} -PICout PICout::operator <<(const double v) {if (!act_) return *this; space(); PIFLOATCOUT(v) return *this;} +PICout & PICout::operator <<(float v) {if (!act_) return *this; space(); PIFLOATCOUT(v)} -PICout PICout::operator <<(const void * v) {if (!act_) return *this; space(); write("0x" + PIString::fromNumber(ullong(v), 16)); return *this;} +PICout & PICout::operator <<(double v) {if (!act_) return *this; space(); PIFLOATCOUT(v)} -PICout PICout::operator <<(const PIObject * v) { +PICout & PICout::operator <<(void * v) { + if (!act_) return *this; + space(); + write("0x" + PIString::fromNumber(ullong(v), 16)); + return *this; +} + +PICout & PICout::operator <<(const PIObject * v) { if (!act_) return *this; space(); if (v == 0) write("PIObject*(0x0)"); @@ -382,7 +410,7 @@ PICout PICout::operator <<(const PIObject * v) { return *this; } -PICout PICout::operator <<(const PICoutSpecialChar v) { +PICout & PICout::operator <<(PICoutSpecialChar v) { if (!act_) return *this; switch (v) { case Null: @@ -581,10 +609,10 @@ void PICout::init() { } attr_ = __Private__::dattr; #endif - buffer_ = nullptr; id_ = 0; - if ((co_ & NoLock) != NoLock) + if ((co_ & NoLock) != NoLock) { PICout::__mutex__().lock(); + } } @@ -686,3 +714,11 @@ void PICout::setOutputDevices(PICout::OutputDevices d) { bool PICout::isOutputDeviceActive(PICout::OutputDevice d) { return devs[d]; } + + +PICout PICout::withExternalBuffer(PIString * buffer, int id, PIFlags controls) { + PICout c(controls); + c.buffer_ = buffer; + c.id_ = id; + return c; +} diff --git a/libs/main/core/picout.h b/libs/main/core/picout.h index 06ed67ab..37f21256 100644 --- a/libs/main/core/picout.h +++ b/libs/main/core/picout.h @@ -140,10 +140,6 @@ public: //! \~russian Конструктор по умолчанию (AddSpaces и AddNewLine), но если не \"active\" то будет неактивным PICout(bool active); - //! \~english Construct with external buffer and ID "id". See \a Notifier for details - //! \~russian Конструктор с внешним буфером и ID "id". Подробнее \a Notifier - PICout(PIString * buffer, int id = 0, PIFlags controls = PICoutManipulators::AddSpaces | PICoutManipulators::AddNewLine); - PICout(const PICout & other); ~PICout(); @@ -176,86 +172,87 @@ public: //! \~english Output operator for strings with "const char * " type //! \~russian Оператор вывода для строк "const char * " - PICout operator <<(const char * v); + PICout & operator <<(const char * v); - // ! Output operator for strings with "std::string" type - //PICout operator <<(const std::string & v); + //! \~english Output operator for \a PIString + //! \~russian Оператор вывода для \a PIString + PICout & operator <<(const PIString & v); //! \~english Output operator for boolean values //! \~russian Оператор вывода для логических значений - PICout operator <<(const bool v); + PICout & operator <<(bool v); //! \~english Output operator for "char" values //! \~russian Оператор вывода для "char" значений - PICout operator <<(const char v); + PICout & operator <<(char v); //! \~english Output operator for "unsigned char" values //! \~russian Оператор вывода для "unsigned char" значений - PICout operator <<(const uchar v); + PICout & operator <<(uchar v); //! \~english Output operator for "short" values //! \~russian Оператор вывода для "short" значений - PICout operator <<(const short v); + PICout & operator <<(short v); //! \~english Output operator for "unsigned short" values //! \~russian Оператор вывода для "unsigned short" значений - PICout operator <<(const ushort v); + PICout & operator <<(ushort v); //! \~english Output operator for "int" values //! \~russian Оператор вывода для "int" значений - PICout operator <<(const int v); + PICout & operator <<(int v); //! \~english Output operator for "unsigned int" values //! \~russian Оператор вывода для "unsigned int" значений - PICout operator <<(const uint v); + PICout & operator <<(uint v); //! \~english Output operator for "long" values //! \~russian Оператор вывода для "long" значений - PICout operator <<(const long v); + PICout & operator <<(long v); //! \~english Output operator for "unsigned long" values //! \~russian Оператор вывода для "unsigned long" значений - PICout operator <<(const ulong v); + PICout & operator <<(ulong v); //! \~english Output operator for "long long" values //! \~russian Оператор вывода для "long long" значений - PICout operator <<(const llong v); + PICout & operator <<(llong v); //! \~english Output operator for "unsigned long long" values //! \~russian Оператор вывода для "unsigned long long" значений - PICout operator <<(const ullong v); + PICout & operator <<(ullong v); //! \~english Output operator for "float" values //! \~russian Оператор вывода для "float" значений - PICout operator <<(const float v); + PICout & operator <<(float v); //! \~english Output operator for "double" values //! \~russian Оператор вывода для "double" значений - PICout operator <<(const double v); + PICout & operator <<(double v); //! \~english Output operator for pointers //! \~russian Оператор вывода для указателей - PICout operator <<(const void * v); + PICout & operator <<(void * v); //! \~english Output operator for PIObject and ancestors //! \~russian Оператор вывода для PIObject и наследников - PICout operator <<(const PIObject * v); + PICout & operator <<(const PIObject * v); //! \~english Output operator for \a PICoutSpecialChar values //! \~russian Оператор вывода для \a PICoutSpecialChar - PICout operator <<(const PICoutManipulators::PICoutSpecialChar v); + PICout & operator <<(PICoutManipulators::PICoutSpecialChar v); //! \~english Output operator for \a PIFlags values //! \~russian Оператор вывода для \a PIFlags - PICout operator <<(const PIFlags & v); + PICout & operator <<(PIFlags v); //! \~english Output operator for \a PICoutFormat values //! \~russian Оператор вывода для \a PICoutFormat - PICout operator <<(const PICoutManipulators::PICoutFormat v); + PICout & operator <<(PICoutManipulators::PICoutFormat v); //! \~english Do some action //! \~russian Делает действие - PICout operator <<(const PICoutManipulators::PICoutAction v); + PICout & operator <<(PICoutManipulators::PICoutAction v); //! \~english Set control flag "c" is "on" state //! \~russian Установить флаг "c" в "on" состояние @@ -348,6 +345,11 @@ public: //! \~russian Возвращает активно ли устройство вывода "d" static bool isOutputDeviceActive(OutputDevice d); + + //! \~english Construct with external buffer and ID "id". See \a Notifier for details + //! \~russian Конструктор с внешним буфером и ID "id". Подробнее \a Notifier + static PICout withExternalBuffer(PIString * buffer, int id = 0, PIFlags controls = PICoutManipulators::AddSpaces | PICoutManipulators::AddNewLine); + static PIMutex & __mutex__(); static PIString & __string__(); diff --git a/libs/main/core/pistring.cpp b/libs/main/core/pistring.cpp index 5c6d293c..4ec1ee60 100644 --- a/libs/main/core/pistring.cpp +++ b/libs/main/core/pistring.cpp @@ -411,6 +411,12 @@ PIString & PIString::operator +=(const char * str) { } +PIString & PIString::operator +=(const PIByteArray & ba) { + appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); + return *this; +} + + PIString::~PIString() { deleteData(); } @@ -1685,11 +1691,3 @@ PIString versionNormalize(const PIString & v) { return ret; } - -PICout operator <<(PICout s, const PIString & v) { - s.space(); - s.quote(); - s.write(v); - s.quote(); - return s; -} diff --git a/libs/main/core/pistring.h b/libs/main/core/pistring.h index 47625b9f..1128157c 100644 --- a/libs/main/core/pistring.h +++ b/libs/main/core/pistring.h @@ -73,7 +73,7 @@ public: PIString & operator +=(const char c) {d.push_back(PIChar(c)); return *this;} PIString & operator +=(const char * str); PIString & operator +=(const wchar_t * str); - PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); return *this;} + PIString & operator +=(const PIByteArray & ba); PIString & operator +=(const PIString & str); PIString & operator +=(const PIConstChars & str); @@ -107,11 +107,11 @@ public: //! \~english Contructs string with single character "c". //! \~russian Создает строку из одного символа "c". - PIString(const PIChar c) {*this += c;} + PIString(const PIChar c) {d.push_back(c);} //! \~english Contructs string with single character "c". //! \~russian Создает строку из одного символа "c". - PIString(const char c) {*this += PIChar(c);} + PIString(const char c) {d.push_back(PIChar(c));} //! \~english Contructs string from C-string "str" (system codepage). //! \~russian Создает строку из C-строки "str" (кодировка системы). @@ -1517,12 +1517,6 @@ private: mutable char * data_ = nullptr; }; - -//! \relatesalso PICout -//! \~english Output operator to \a PICout. -//! \~russian Оператор вывода в \a PICout. -PIP_EXPORT PICout operator <<(PICout s, const PIString & v); - //! \relatesalso PIBinaryStream //! \~english Store operator. //! \~russian Оператор сохранения. @@ -1548,11 +1542,11 @@ inline PIString operator +(const char * str, const PIString & f) {return PIStrin //! \~english Returns concatenated string. //! \~russian Возвращает соединение строк. -inline PIString operator +(const char c, const PIString & f) {return PIChar(c) + f;} +inline PIString operator +(const char c, const PIString & f) {return PIString(c) + f;} //! \~english Returns concatenated string. //! \~russian Возвращает соединение строк. -inline PIString operator +(const PIString & f, const char c) {return f + PIChar(c);} +inline PIString operator +(const PIString & f, const char c) {PIString s(f); s.push_back(c); return s;} //! \relatesalso PIString diff --git a/libs/main/io_utils/pifiletransfer.cpp b/libs/main/io_utils/pifiletransfer.cpp index 475aa814..291adf0b 100644 --- a/libs/main/io_utils/pifiletransfer.cpp +++ b/libs/main/io_utils/pifiletransfer.cpp @@ -22,8 +22,7 @@ const char PIFileTransfer::sign[] = {'P', 'F', 'T'}; PIFileTransfer::PIFileTransfer() { - for (uint i = 0; i < sizeof(sign); i++) - pftheader.sig[i] = sign[i]; + for (uint i = 0; i < sizeof(sign); i++) pftheader.sig[i] = sign[i]; pftheader.version = __PIFILETRANSFER_VERSION; pftheader.session_id = 0; pftheader.step = pft_None; diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index f6d9281c..190ae477 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -238,7 +238,15 @@ inline PIMathVectorT operator *(const Type & x, const PIMathVectorT< } template -inline PICout operator <<(PICout s, const PIMathVectorT & v) {s << "{"; PIMV_FOR {s << v[i]; if (i < Size - 1) s << ", ";} s << "}"; return s;} +inline PICout operator <<(PICout s, const PIMathVectorT & v) { + s << "Vector{"; + PIMV_FOR { + s << v[i]; + if (i < Size - 1) s << ", "; + } + s << "}"; + return s; +} typedef PIMathVectorT<2u, int> PIMathVectorT2i; @@ -510,7 +518,15 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathVector & v #endif template -inline PICout operator <<(PICout s, const PIMathVector & v) {s << "Vector{"; for (uint i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; return s;} +inline PICout operator <<(PICout s, const PIMathVector & v) { + s << "Vector{"; + for (uint i = 0; i < v.size(); ++i) { + s << v[i]; + if (i < v.size() - 1) s << ", "; + } + s << "}"; + return s; +} template inline PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIMathVector & v) {s << v.c; return s;} diff --git a/main.cpp b/main.cpp index 7125d414..c116ae08 100644 --- a/main.cpp +++ b/main.cpp @@ -5,19 +5,9 @@ using namespace PICoutManipulators; int main(int argc, char * argv[]) { - float a_read[10], a_write[10]; - for (int i = 0; i < 10; ++i) { - a_read [i] = 0.f; - a_write[i] = i / 10.f; - } - - PIByteArray data; - data << PIMemoryBlock(a_write, 10 * sizeof(float)); - - piCout << data.toHex(); - - data >> PIMemoryBlock(a_read, 10 * sizeof(float)); - for (int i = 0; i < 10; ++i) - piCout << a_read[i]; - + //PIMap v{{1, "xdsa"},{2, "blya"},{3, "\n"}}; + PIVector x{1,2}; + piCout << 1 << 2; + piCout << 1 << 2; + return 0; }