diff --git a/src/containers/pideque.h b/src/containers/pideque.h index 3a780685..a9c7325f 100755 --- a/src/containers/pideque.h +++ b/src/containers/pideque.h @@ -538,8 +538,11 @@ __PIDEQUE_SIMPLE_TYPE__(float) __PIDEQUE_SIMPLE_TYPE__(double) __PIDEQUE_SIMPLE_TYPE__(ldouble) + +#ifdef PIP_STD_IOSTREAM template inline std::ostream & operator <<(std::ostream & s, const PIDeque & v) {s << "{"; for (size_t i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; return s;} +#endif template inline PICout operator <<(PICout s, const PIDeque & v) {s.space(); s.setControl(0, true); s << "{"; for (size_t i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; s.restoreControl(); return s;} diff --git a/src/containers/pimap.h b/src/containers/pimap.h index 44f55977..4f940563 100644 --- a/src/containers/pimap.h +++ b/src/containers/pimap.h @@ -428,6 +428,7 @@ public: #endif +#ifdef PIP_STD_IOSTREAM template inline std::ostream & operator <<(std::ostream & s, const PIMap & v) { s << "{"; @@ -441,6 +442,7 @@ inline std::ostream & operator <<(std::ostream & s, const PIMap & v) s << "}"; return s; } +#endif template inline PICout operator <<(PICout s, const PIMap & v) { diff --git a/src/containers/pipair.h b/src/containers/pipair.h index 9268e120..64ecc64e 100644 --- a/src/containers/pipair.h +++ b/src/containers/pipair.h @@ -18,8 +18,10 @@ template inline bool operator ==(const PIPair & value0, const PIPair & value1) {return (value0.first == value1.first) && (value0.second == value1.second);} template inline bool operator !=(const PIPair & value0, const PIPair & value1) {return (value0.first != value1.first) || (value0.second != value1.second);} + template inline std::ostream & operator <<(std::ostream & s, const PIPair & v) {s << "(" << v.first << ", " << v.second << ")"; return s;} + template inline PICout operator <<(PICout s, const PIPair & v) {s.space(); s.setControl(0, true); s << "(" << v.first << ", " << v.second << ")"; s.restoreControl(); return s;} diff --git a/src/containers/pivector.h b/src/containers/pivector.h index 0a93068f..2ee8c89d 100755 --- a/src/containers/pivector.h +++ b/src/containers/pivector.h @@ -538,8 +538,10 @@ __PIVECTOR_SIMPLE_TYPE__(double) __PIVECTOR_SIMPLE_TYPE__(ldouble) +#ifdef PIP_STD_IOSTREAM template inline std::ostream & operator <<(std::ostream & s, const PIVector & v) {s << "{"; for (size_t i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; return s;} +#endif template inline PICout operator <<(PICout s, const PIVector & v) {s.space(); s.setControl(0, true); s << "{"; for (size_t i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; s.restoreControl(); return s;} diff --git a/src/core/pibitarray.cpp b/src/core/pibitarray.cpp new file mode 100644 index 00000000..73f8c5c7 --- /dev/null +++ b/src/core/pibitarray.cpp @@ -0,0 +1,24 @@ +#include "pibitarray.h" +#include "picout.h" + + +PICout operator <<(PICout s, const PIBitArray & ba) { + s.space(); + s.setControl(0, true); + for (uint i = 0; i < ba.bitSize(); ++i) { + s << int(ba[i]); + if (i % 8 == 7) s << ' '; + } + s.restoreControl(); + return s; +} + + +std::ostream &operator <<(std::ostream & s, const PIBitArray & ba) { + for (uint i = 0; i < ba.bitSize(); ++i) { + s << ba[i]; + if (i % 8 == 7) s << ' '; + } + return s; +} + diff --git a/src/core/pibitarray.h b/src/core/pibitarray.h index 52564dcc..912f0984 100755 --- a/src/core/pibitarray.h +++ b/src/core/pibitarray.h @@ -100,7 +100,8 @@ private: }; -inline std::ostream & operator <<(std::ostream & s, const PIBitArray & ba) {for (uint i = 0; i < ba.bitSize(); ++i) {s << ba[i]; if (i % 8 == 7) s << ' ';} return s;} -inline PICout operator <<(PICout s, const PIBitArray & ba) {s.space(); s.setControl(0, true); for (uint i = 0; i < ba.bitSize(); ++i) {s << int(ba[i]); if (i % 8 == 7) s << ' ';} s.restoreControl(); return s;} +std::ostream & operator <<(std::ostream & s, const PIBitArray & ba); + +inline PICout operator <<(PICout s, const PIBitArray & ba); #endif // PIBITARRAY_H diff --git a/src/core/pibytearray.cpp b/src/core/pibytearray.cpp index b2b6a2f0..1b12fcc1 100755 --- a/src/core/pibytearray.cpp +++ b/src/core/pibytearray.cpp @@ -19,6 +19,7 @@ #include "pibytearray.h" #include "pistring.h" +#include /*! \class PIByteArray * \brief Byte array @@ -346,4 +347,26 @@ PIByteArray PIByteArray::fromHex(PIString str) { } -PICout operator <<(PICout s, const PIByteArray & ba) {s.space(); s.setControl(0, true); s << "{"; for (uint i = 0; i < ba.size(); ++i) {s << ba[i]; if (i < ba.size() - 1) s << ", ";} s << "}"; s.restoreControl(); return s;} +PICout operator <<(PICout s, const PIByteArray & ba) { + s.space(); + s.setControl(0, true); + s << "{"; + for (uint i = 0; i < ba.size(); ++i) { + s << ba[i]; + if (i < ba.size() - 1) s << ", "; + } + s << "}"; + s.restoreControl(); + return s; +} + + +std::ostream &operator <<(std::ostream & s, const PIByteArray & ba) { + s << "{"; + for (uint i = 0; i < ba.size(); ++i) { + s << ba[i]; + if (i < ba.size() - 1) s << ", "; + } + s << "}"; + return s; +} diff --git a/src/core/pibytearray.h b/src/core/pibytearray.h index 040ba0c0..857e8a3b 100755 --- a/src/core/pibytearray.h +++ b/src/core/pibytearray.h @@ -120,8 +120,9 @@ public: }; inline bool operator <(const PIByteArray & v0, const PIByteArray & v1) {if (v0.size() == v1.size()) {for (uint i = 0; i < v0.size(); ++i) if (v0[i] != v1[i]) return v0[i] < v1[i]; return false;} return v0.size() < v1.size();} + //! \relatesalso PIByteArray \brief Output to std::ostream operator -inline std::ostream & operator <<(std::ostream & s, const PIByteArray & ba) {s << "{"; for (uint i = 0; i < ba.size(); ++i) {s << ba[i]; if (i < ba.size() - 1) s << ", ";} s << "}"; return s;} +inline std::ostream & operator <<(std::ostream & s, const PIByteArray & ba); //! \relatesalso PIByteArray \brief Output to PICout operator PICout operator <<(PICout s, const PIByteArray & ba); diff --git a/src/core/pichar.cpp b/src/core/pichar.cpp index 508f396a..b0ed07e7 100644 --- a/src/core/pichar.cpp +++ b/src/core/pichar.cpp @@ -20,8 +20,8 @@ along with this program. If not, see . */ +#include #include "pibytearray.h" -#include "pichar.h" #ifdef PIP_ICU # include "unicode/ucnv.h" # include "unicode/ustring.h" diff --git a/src/core/picout.cpp b/src/core/picout.cpp index a678b4fc..a4a4d831 100644 --- a/src/core/picout.cpp +++ b/src/core/picout.cpp @@ -16,11 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "pibase.h" -#ifdef WINDOWS -# include -# include -#endif +#include "piincludes_p.h" #include "picout.h" #include "piconsole.h" #include "pibytearray.h" @@ -30,6 +26,7 @@ # include # define COMMON_LVB_UNDERSCORE 0x8000 #endif +#include /*! \class PICout * \brief Class for formatted output similar std::cout diff --git a/src/core/piincludes.h b/src/core/piincludes.h index 8748d0cd..c1280f98 100755 --- a/src/core/piincludes.h +++ b/src/core/piincludes.h @@ -24,7 +24,7 @@ #include "piflags.h" #include "pimonitor.h" -#include +//#include //#include #include #include @@ -47,6 +47,8 @@ class PIByteArray; class PIInit; class PIChar; class PICout; +#include + struct lconv; extern lconv * currentLocale; diff --git a/src/core/piincludes_p.h b/src/core/piincludes_p.h index d0a77268..b01cd259 100644 --- a/src/core/piincludes_p.h +++ b/src/core/piincludes_p.h @@ -26,4 +26,6 @@ #ifdef CC_GCC # include #endif +#include +#include #endif // PIINCLUDES_P_H diff --git a/src/core/pistring.cpp b/src/core/pistring.cpp index 2b2351ac..98620db0 100755 --- a/src/core/pistring.cpp +++ b/src/core/pistring.cpp @@ -18,6 +18,7 @@ */ #include "pistring.h" +#include #ifdef PIP_ICU # include "unicode/ucnv.h" #endif @@ -429,6 +430,12 @@ bool PIString::operator >(const PIString & str) const { } +PIString &PIString::operator +=(const std::string & str) { + appendFromChars(str.c_str(), str.length()); + return *this; +} + + PIString PIString::mid(const int start, const int len) const { //PIString str; int s = start, l = len; @@ -861,6 +868,16 @@ std::string PIString::convertToStd() const { } +#ifdef HAS_LOCALE +std::wstring PIString::convertToWString() const { + std::wstring s; + for (int i = 0; i < length(); ++i) + s.push_back(at(i).toWChar()); + return s; +} +#endif + + char PIString::toChar() const { PIString s(toNativeDecimalPoints()); char v; @@ -985,3 +1002,14 @@ PIStringList& PIStringList::removeDuplicates() { } return *this; } + + +std::ostream &operator <<(std::ostream & s, const PIStringList & v) { + s << "{"; + for (uint i = 0; i < v.size(); ++i) { + s << "\"" << v[i] << "\""; + if (i < v.size() - 1) s << ", "; + } + s << "}"; + return s; +} diff --git a/src/core/pistring.h b/src/core/pistring.h index f90b31f8..998a804a 100755 --- a/src/core/pistring.h +++ b/src/core/pistring.h @@ -26,12 +26,11 @@ #define PISTRING_H #include "pibytearray.h" -#ifndef QNX - using std::wstring; -#else +#define PIStringAscii PIString::fromAscii +#include +#ifdef QNX typedef std::basic_string wstring; #endif -#define PIStringAscii PIString::fromAscii class PIStringList; @@ -46,11 +45,11 @@ public: PIString & operator +=(const PIChar & c) {push_back(c); return *this;} PIString & operator +=(const char * str); PIString & operator +=(const wchar_t * str); - PIString & operator +=(const std::string & str) {appendFromChars(str.c_str(), str.length()); return *this;} + PIString & operator +=(const std::string & str); PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s()); return *this;} PIString & operator +=(const PIString & str); #ifdef HAS_LOCALE - PIString & operator +=(const wstring & str); + PIString & operator +=(const std::wstring & str); #endif //PIString(const char c) {*this += c;} @@ -86,7 +85,7 @@ public: /*! \brief Contructs string from "len" characters of buffer "str" * \details Example: \snippet pistring.cpp PIString(char * , int) */ - PIString(const char * str, const int len): PIDeque() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this += std::string(str, len);} + PIString(const char * str, const int len): PIDeque() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; appendFromChars(str, len);} /*! \brief Contructs string as sequence of characters "c" of buffer with length "len" * \details Example: \snippet pistring.cpp PIString(int, char) */ @@ -500,7 +499,7 @@ public: //! \brief Return \c std::string representation of this string std::string stdString() const {return convertToStd();} - + #ifdef HAS_LOCALE wstring stdWString() const {return convertToWString();} #endif @@ -841,7 +840,7 @@ private: void trimsubstr(int &st, int &fn) const; std::string convertToStd() const; #ifdef HAS_LOCALE - wstring convertToWString() const {wstring s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toWChar()); return s;} + std::wstring convertToWString() const; #endif mutable PIByteArray data_; @@ -970,7 +969,7 @@ inline PIByteArray & operator >>(PIByteArray & s, PIStringList & v) {int sz; s > //! \relatesalso PIStringList \brief Output operator to std::ostream (cout) -inline std::ostream & operator <<(std::ostream & s, const PIStringList & v) {s << "{"; for (uint i = 0; i < v.size(); ++i) {s << "\"" << v[i] << "\""; if (i < v.size() - 1) s << ", ";} s << "}"; return s;} +std::ostream & operator <<(std::ostream & s, const PIStringList & v); //! \relatesalso PIStringList \relatesalso PICout \brief Output operator to PICout inline PICout operator <<(PICout s, const PIStringList & v) {s.space(); s.setControl(0, true); s << "{"; for (uint i = 0; i < v.size(); ++i) {s << "\"" << v[i] << "\""; if (i < v.size() - 1) s << ", ";} s << "}"; s.restoreControl(); return s;} diff --git a/src/io/piconfig.cpp b/src/io/piconfig.cpp index 0fc9697c..12dd4c05 100755 --- a/src/io/piconfig.cpp +++ b/src/io/piconfig.cpp @@ -20,6 +20,7 @@ #include "piconfig.h" #include "pifile.h" #include "piiostring.h" +#include /*! \class PIConfig * \brief Configuration file @@ -222,7 +223,7 @@ PIConfig::Branch PIConfig::Entry::getValues(const PIString & vname) { if (i->_name.find(vname) >= 0) b << i; return b; -}; +} bool PIConfig::Entry::entryExists(const Entry * e, const PIString & name) const { @@ -235,6 +236,22 @@ bool PIConfig::Entry::entryExists(const Entry * e, const PIString & name) const } +void PIConfig::Entry::coutt(std::ostream & s, const PIString & p) const { + PIString nl = p + " "; + if (!_value.isEmpty()) s << p << _name << " = " << _value << std::endl; + else std::cout << p << _name << std::endl; + piForeachC (Entry * i, _children) i->coutt(s, nl); +} + + +void PIConfig::Entry::piCoutt(PICout s, const PIString & p) const { + PIString nl = p + " "; + if (!_value.isEmpty()) s << p << _name << " = " << _value << PICoutManipulators::NewLine; + else std::cout << p << _name << std::endl; + piForeachC (Entry * i, _children) i->piCoutt(s, nl); +} + + PIConfig::PIConfig(const PIString & path, PIIODevice::DeviceMode mode) { _init(); own_dev = true; diff --git a/src/io/piconfig.h b/src/io/piconfig.h index d8538986..c6f4b2a3 100755 --- a/src/io/piconfig.h +++ b/src/io/piconfig.h @@ -303,8 +303,8 @@ public: bool entryExists(const Entry * e, const PIString & name) const; void buildLine() {_all = _tab + _full_name + " = " + _value + " #" + _type + " " + _comment;} void clear() {_children.clear(); _name = _value = _type = _comment = _all = PIString(); _line = 0; _parent = 0;} - void coutt(std::ostream & s, const PIString & p) const {PIString nl = p + " "; if (!_value.isEmpty()) s << p << _name << " = " << _value << std::endl; else std::cout << p << _name << std::endl; piForeachC (Entry * i, _children) i->coutt(s, nl);} - void piCoutt(PICout s, const PIString & p) const {PIString nl = p + " "; if (!_value.isEmpty()) s << p << _name << " = " << _value << PICoutManipulators::NewLine; else std::cout << p << _name << std::endl; piForeachC (Entry * i, _children) i->piCoutt(s, nl);} + void coutt(std::ostream & s, const PIString & p) const; + void piCoutt(PICout s, const PIString & p) const; void deleteBranch() {piForeach (Entry * i, _children) {i->deleteBranch(); delete i;}} static Entry _empty; diff --git a/src/math/picrc.h b/src/math/picrc.h index 99f9baf1..2632e7fb 100755 --- a/src/math/picrc.h +++ b/src/math/picrc.h @@ -159,8 +159,8 @@ private: }; -template -inline std::ostream & operator <<(std::ostream & s, const uint_cl & v) {std::ios::fmtflags f = s.flags(); s << std::hex; for (uint i = 0; i < v.length(); ++i) {s << int(v.data()[i]); if (v.data()[i] < 0x10) s << '0'; s << ' ';} s.flags(f); return s;} +//template +//inline std::ostream & operator <<(std::ostream & s, const uint_cl & v) {std::ios::fmtflags f = s.flags(); s << std::hex; for (uint i = 0; i < v.length(); ++i) {s << int(v.data()[i]); if (v.data()[i] < 0x10) s << '0'; s << ' ';} s.flags(f); return s;} inline uchar reverseByte(uchar b) { uchar ret = 0;