PIVector doc, forEach refactory

This commit is contained in:
Andrey
2022-04-14 15:58:40 +03:00
parent 77e0423375
commit fa93c8a486
5 changed files with 150 additions and 109 deletions

View File

@@ -1,14 +1,13 @@
#include "pip.h"
class ROString {
class ConstChars {
public:
inline ROString() : len(0), str(nullptr) {}
inline ROString(const char * string) {
inline ConstChars() : len(0), str(nullptr) {}
inline ConstChars(const char * string) {
str = string;
len = strlen(string);
}
inline ROString(const char * data, size_t size) {
inline ConstChars(const char * data, size_t size) {
str = data;
len = size;
}
@@ -29,7 +28,7 @@ public:
//! \~\brief
//! \~english Assign operator.
//! \~russian Оператор присваивания.
inline ROString & operator =(const ROString & s) {
inline ConstChars & operator =(const ConstChars & s) {
if (this == &s) return *this;
len = s.len;
str = s.str;
@@ -39,12 +38,12 @@ public:
//! \~\brief
//! \~english Assign move operator.
//! \~russian Оператор перемещающего присваивания.
inline ROString & operator =(ROString && s) {
inline ConstChars & operator =(ConstChars && s) {
swap(s);
return *this;
}
inline void swap(ROString& v) {
inline void swap(ConstChars& v) {
piSwap<const char *>(str, v.str);
piSwap<size_t>(len, v.len);
}
@@ -54,7 +53,7 @@ private:
const char * str;
};
PICout operator <<(PICout s, const ROString & v) {
PICout operator <<(PICout s, const ConstChars & v) {
s.space();
s.quote();
s.write(v.data(), v.size());
@@ -63,30 +62,33 @@ PICout operator <<(PICout s, const ROString & v) {
}
int main(int argc, char * argv[]) {
const char * dd = "12345";
char text[]{ "hello" };
ROString s("test");
piCout << s;
ROString s2;
piCout << s2;
s2 = s;
piCout << s2;
s2 = text;
s = s2;
piCout << s << s2;
// const char * dd = "12345";
// char text[]{ "hello" };
// ConstChars s("test");
// piCout << s;
// ConstChars s2;
// piCout << s2;
// s2 = s;
text[1] = '0';
piCout << text;
piCout << s << s2 << ROString(text, 3);
// piCout << s2;
// s2 = text;
// s = s2;
// piCout << s << s2;
// PIString ss(s.data(), s.length());
// piCout << ss;
PICout(PICoutManipulators::DefaultControls | PICoutManipulators::AddQuotes) << PIString(dd);
//// s2 = s;
// text[1] = '0';
// piCout << text;
// piCout << s << s2 << ConstChars(text, 3);
//// piCout << s << s2;
//// PIString ss(s.data(), s.length());
//// piCout << ss;
// PICout(PICoutManipulators::DefaultControls | PICoutManipulators::AddQuotes) << PIString(dd);
piCout << PIString::fromUTF8("test");
piCout << PIString::fromUTF8("бюд\n");
piCout.writePIString(PIString::fromUTF8("test\n"));
piCout.writePIString(PIString::fromUTF8("бюд\n"));
piCout << "бюд\n";
// piCout << PIString::fromUTF8("test");
// piCout << PIString::fromUTF8("бюд\n");
// piCout.writePIString(PIString::fromUTF8("test\n"));
// piCout.writePIString(PIString::fromUTF8("бюд\n"));
// piCout << "бюд\n";
PIVector<double> v{1.1, 2.5, 3.8};
PIVector<int> v2 = v.toType<int>();
piCout << v2;
return 0;
}