version 2.39.0
PIString works with PIConstChars picodeinfo optimizations PIIODevice::availableClasses
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
|
|||||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||||
project(pip)
|
project(pip)
|
||||||
set(pip_MAJOR 2)
|
set(pip_MAJOR 2)
|
||||||
set(pip_MINOR 38)
|
set(pip_MINOR 39)
|
||||||
set(pip_REVISION 0)
|
set(pip_REVISION 0)
|
||||||
set(pip_SUFFIX )
|
set(pip_SUFFIX )
|
||||||
set(pip_COMPANY SHS)
|
set(pip_COMPANY SHS)
|
||||||
|
|||||||
@@ -24,39 +24,39 @@
|
|||||||
PIString PICodeInfo::EnumInfo::memberName(int value_) const {
|
PIString PICodeInfo::EnumInfo::memberName(int value_) const {
|
||||||
piForeachC (PICodeInfo::EnumeratorInfo & e, members)
|
piForeachC (PICodeInfo::EnumeratorInfo & e, members)
|
||||||
if (e.value == value_)
|
if (e.value == value_)
|
||||||
return e.name;
|
return e.name.toString();
|
||||||
return PIString();
|
return PIString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int PICodeInfo::EnumInfo::memberValue(const PIString & name_) const {
|
int PICodeInfo::EnumInfo::memberValue(const PIString & name_) const {
|
||||||
piForeachC (PICodeInfo::EnumeratorInfo & e, members)
|
piForeachC (PICodeInfo::EnumeratorInfo & e, members)
|
||||||
if (e.name == name_)
|
if (e.name.toString() == name_)
|
||||||
return e.value;
|
return e.value;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIVariantTypes::Enum PICodeInfo::EnumInfo::toPIVariantEnum() {
|
PIVariantTypes::Enum PICodeInfo::EnumInfo::toPIVariantEnum() {
|
||||||
PIVariantTypes::Enum en(name);
|
PIVariantTypes::Enum en(name.toString());
|
||||||
for (auto m: members) en << m.toPIVariantEnumerator();
|
for (auto m: members) en << m.toPIVariantEnumerator();
|
||||||
if (!en.isEmpty()) en.selectValue(members.front().value);
|
if (!en.isEmpty()) en.selectValue(members.front().value);
|
||||||
return en;
|
return en;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIMap<PIString, PICodeInfo::ClassInfo * > * PICodeInfo::classesInfo;
|
PIMap<PIConstChars, PICodeInfo::ClassInfo * > * PICodeInfo::classesInfo;
|
||||||
PIMap<PIString, PICodeInfo::EnumInfo * > * PICodeInfo::enumsInfo;
|
PIMap<PIConstChars, PICodeInfo::EnumInfo * > * PICodeInfo::enumsInfo;
|
||||||
PIMap<PIString, PICodeInfo::AccessValueFunction> * PICodeInfo::accessValueFunctions;
|
PIMap<PIConstChars, PICodeInfo::AccessValueFunction> * PICodeInfo::accessValueFunctions;
|
||||||
PIMap<PIString, PICodeInfo::AccessTypeFunction> * PICodeInfo::accessTypeFunctions;
|
PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> * PICodeInfo::accessTypeFunctions;
|
||||||
|
|
||||||
bool __PICodeInfoInitializer__::_inited_ = false;
|
bool __PICodeInfoInitializer__::_inited_ = false;
|
||||||
|
|
||||||
|
|
||||||
PIVariant PICodeInfo::getMemberAsVariant(const void * p, const char * class_name, const char * member_name) {
|
PIVariant PICodeInfo::getMemberAsVariant(const void * p, const char * class_name, const char * member_name) {
|
||||||
if (!p || !class_name || !member_name || !accessTypeFunctions || !accessValueFunctions) return PIVariant();
|
if (!p || !class_name || !member_name || !accessTypeFunctions || !accessValueFunctions) return PIVariant();
|
||||||
AccessTypeFunction atf = accessTypeFunctions->value(PIStringAscii(class_name), (AccessTypeFunction)0);
|
AccessTypeFunction atf = accessTypeFunctions->value(class_name, (AccessTypeFunction)0);
|
||||||
AccessValueFunction avf = accessValueFunctions->value(PIStringAscii(class_name), (AccessValueFunction)0);
|
AccessValueFunction avf = accessValueFunctions->value(class_name, (AccessValueFunction)0);
|
||||||
if (!atf || !avf) return PIVariant();
|
if (!atf || !avf) return PIVariant();
|
||||||
return PIVariant::fromValue(avf(p, member_name), PIStringAscii(atf(member_name)));
|
return PIVariant::fromValue(avf(p, member_name), PIStringAscii(atf(member_name)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#ifndef PICODEINFO_H
|
#ifndef PICODEINFO_H
|
||||||
#define PICODEINFO_H
|
#define PICODEINFO_H
|
||||||
|
|
||||||
|
#include "piconstchars.h"
|
||||||
#include "pistringlist.h"
|
#include "pistringlist.h"
|
||||||
#include "pivarianttypes.h"
|
#include "pivarianttypes.h"
|
||||||
|
|
||||||
@@ -52,18 +53,18 @@ typedef PIByteArray(*AccessValueFunction)(const void *, const char *);
|
|||||||
typedef const char*(*AccessTypeFunction)(const char *);
|
typedef const char*(*AccessTypeFunction)(const char *);
|
||||||
|
|
||||||
struct PIP_EXPORT TypeInfo {
|
struct PIP_EXPORT TypeInfo {
|
||||||
TypeInfo(const PIString & n = PIString(), const PIString & t = PIString(), PICodeInfo::TypeFlags f = 0, int b = -1) {name = n; type = t; flags = f; bits = b;}
|
TypeInfo(const PIConstChars & n = PIConstChars(), const PIConstChars & t = PIConstChars(), PICodeInfo::TypeFlags f = 0, int b = -1) {name = n; type = t; flags = f; bits = b;}
|
||||||
bool isBitfield() const {return bits > 0;}
|
bool isBitfield() const {return bits > 0;}
|
||||||
MetaMap meta;
|
MetaMap meta;
|
||||||
PIString name;
|
PIConstChars name;
|
||||||
PIString type;
|
PIConstChars type;
|
||||||
PICodeInfo::TypeFlags flags;
|
PICodeInfo::TypeFlags flags;
|
||||||
int bits;
|
int bits;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PIP_EXPORT FunctionInfo {
|
struct PIP_EXPORT FunctionInfo {
|
||||||
MetaMap meta;
|
MetaMap meta;
|
||||||
PIString name;
|
PIConstChars name;
|
||||||
TypeInfo return_type;
|
TypeInfo return_type;
|
||||||
PIVector<PICodeInfo::TypeInfo> arguments;
|
PIVector<PICodeInfo::TypeInfo> arguments;
|
||||||
};
|
};
|
||||||
@@ -72,19 +73,19 @@ struct PIP_EXPORT ClassInfo {
|
|||||||
ClassInfo() {has_name = true;}
|
ClassInfo() {has_name = true;}
|
||||||
MetaMap meta;
|
MetaMap meta;
|
||||||
bool has_name;
|
bool has_name;
|
||||||
PIString type;
|
PIConstChars type;
|
||||||
PIString name;
|
PIConstChars name;
|
||||||
PIStringList parents;
|
PIVector<PIConstChars> parents;
|
||||||
PIVector<PICodeInfo::TypeInfo> variables;
|
PIVector<PICodeInfo::TypeInfo> variables;
|
||||||
PIVector<PICodeInfo::FunctionInfo> functions;
|
PIVector<PICodeInfo::FunctionInfo> functions;
|
||||||
PIVector<PICodeInfo::ClassInfo * > children_info;
|
PIVector<PICodeInfo::ClassInfo * > children_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PIP_EXPORT EnumeratorInfo {
|
struct PIP_EXPORT EnumeratorInfo {
|
||||||
EnumeratorInfo(const PIString & n = PIString(), int v = 0) {name = n; value = v;}
|
EnumeratorInfo(const PIConstChars & n = PIConstChars(), int v = 0) {name = n; value = v;}
|
||||||
PIVariantTypes::Enumerator toPIVariantEnumerator() {return PIVariantTypes::Enumerator(value, name);}
|
PIVariantTypes::Enumerator toPIVariantEnumerator() {return PIVariantTypes::Enumerator(value, name.toString());}
|
||||||
MetaMap meta;
|
MetaMap meta;
|
||||||
PIString name;
|
PIConstChars name;
|
||||||
int value;
|
int value;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,7 +94,7 @@ struct PIP_EXPORT EnumInfo {
|
|||||||
int memberValue(const PIString & name) const;
|
int memberValue(const PIString & name) const;
|
||||||
PIVariantTypes::Enum toPIVariantEnum();
|
PIVariantTypes::Enum toPIVariantEnum();
|
||||||
MetaMap meta;
|
MetaMap meta;
|
||||||
PIString name;
|
PIConstChars name;
|
||||||
PIVector<PICodeInfo::EnumeratorInfo> members;
|
PIVector<PICodeInfo::EnumeratorInfo> members;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -119,17 +120,17 @@ inline PICout operator <<(PICout s, const PICodeInfo::ClassInfo & v) {
|
|||||||
if (!v.parents.isEmpty()) {
|
if (!v.parents.isEmpty()) {
|
||||||
s << ": ";
|
s << ": ";
|
||||||
bool first = true;
|
bool first = true;
|
||||||
piForeachC (PIString & i, v.parents) {
|
for (const auto & i: v.parents) {
|
||||||
if (first) first = false;
|
if (first) first = false;
|
||||||
else s << ", ";
|
else s << ", ";
|
||||||
s << i;
|
s << i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s << " Meta" << v.meta << " {\n";
|
s << " Meta" << v.meta << " {\n";
|
||||||
piForeachC (FunctionInfo & i, v.functions) {
|
for (const auto & i: v.functions) {
|
||||||
s << PICoutManipulators::Tab << i.return_type << " " << i.name << "(";
|
s << PICoutManipulators::Tab << i.return_type << " " << i.name << "(";
|
||||||
bool fa = true;
|
bool fa = true;
|
||||||
piForeachC (TypeInfo & a, i.arguments) {
|
for (const auto & a: i.arguments) {
|
||||||
if (fa) fa = false;
|
if (fa) fa = false;
|
||||||
else s << ", ";
|
else s << ", ";
|
||||||
s << a;
|
s << a;
|
||||||
@@ -138,7 +139,7 @@ inline PICout operator <<(PICout s, const PICodeInfo::ClassInfo & v) {
|
|||||||
}
|
}
|
||||||
if (!v.functions.isEmpty() && !v.variables.isEmpty())
|
if (!v.functions.isEmpty() && !v.variables.isEmpty())
|
||||||
s << "\n";
|
s << "\n";
|
||||||
piForeachC (TypeInfo & i, v.variables) {
|
for (const auto & i: v.variables) {
|
||||||
s << PICoutManipulators::Tab << i << " Meta" << i.meta << ";\n";
|
s << PICoutManipulators::Tab << i << " Meta" << i.meta << ";\n";
|
||||||
}
|
}
|
||||||
s << "}\n";
|
s << "}\n";
|
||||||
@@ -149,7 +150,7 @@ inline PICout operator <<(PICout s, const PICodeInfo::ClassInfo & v) {
|
|||||||
inline PICout operator <<(PICout s, const PICodeInfo::EnumInfo & v) {
|
inline PICout operator <<(PICout s, const PICodeInfo::EnumInfo & v) {
|
||||||
s.setControl(0, true);
|
s.setControl(0, true);
|
||||||
s << "enum " << v.name << " Meta" << v.meta << " {\n";
|
s << "enum " << v.name << " Meta" << v.meta << " {\n";
|
||||||
piForeachC (EnumeratorInfo & i, v.members) {
|
for (const auto & i: v.members) {
|
||||||
bool f = true;
|
bool f = true;
|
||||||
if (f) f = false;
|
if (f) f = false;
|
||||||
else s << ", ";
|
else s << ", ";
|
||||||
@@ -160,21 +161,21 @@ inline PICout operator <<(PICout s, const PICodeInfo::EnumInfo & v) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::ClassInfo * > * classesInfo;
|
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::ClassInfo * > * classesInfo;
|
||||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::EnumInfo * > * enumsInfo;
|
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::EnumInfo * > * enumsInfo;
|
||||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::AccessValueFunction> * accessValueFunctions;
|
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::AccessValueFunction> * accessValueFunctions;
|
||||||
extern PIP_EXPORT PIMap<PIString, PICodeInfo::AccessTypeFunction> * accessTypeFunctions;
|
extern PIP_EXPORT PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> * accessTypeFunctions;
|
||||||
|
|
||||||
inline PIByteArray getMemberValue(const void * p, const char * class_name, const char * member_name) {
|
inline PIByteArray getMemberValue(const void * p, const char * class_name, const char * member_name) {
|
||||||
if (!p || !class_name || !member_name || !accessValueFunctions) return PIByteArray();
|
if (!p || !class_name || !member_name || !accessValueFunctions) return PIByteArray();
|
||||||
AccessValueFunction af = accessValueFunctions->value(PIStringAscii(class_name), (AccessValueFunction)0);
|
AccessValueFunction af = accessValueFunctions->value(class_name, (AccessValueFunction)0);
|
||||||
if (!af) return PIByteArray();
|
if (!af) return PIByteArray();
|
||||||
return af(p, member_name);
|
return af(p, member_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char * getMemberType(const char * class_name, const char * member_name) {
|
inline const char * getMemberType(const char * class_name, const char * member_name) {
|
||||||
if (!class_name || !member_name || !accessTypeFunctions) return "";
|
if (!class_name || !member_name || !accessTypeFunctions) return "";
|
||||||
AccessTypeFunction af = accessTypeFunctions->value(PIStringAscii(class_name), (AccessTypeFunction)0);
|
AccessTypeFunction af = accessTypeFunctions->value(class_name, (AccessTypeFunction)0);
|
||||||
if (!af) return "";
|
if (!af) return "";
|
||||||
return af(member_name);
|
return af(member_name);
|
||||||
}
|
}
|
||||||
@@ -195,10 +196,10 @@ public:
|
|||||||
__PICodeInfoInitializer__() {
|
__PICodeInfoInitializer__() {
|
||||||
if (_inited_) return;
|
if (_inited_) return;
|
||||||
_inited_ = true;
|
_inited_ = true;
|
||||||
PICodeInfo::classesInfo = new PIMap<PIString, PICodeInfo::ClassInfo * >;
|
PICodeInfo::classesInfo = new PIMap<PIConstChars, PICodeInfo::ClassInfo * >;
|
||||||
PICodeInfo::enumsInfo = new PIMap<PIString, PICodeInfo::EnumInfo * >;
|
PICodeInfo::enumsInfo = new PIMap<PIConstChars, PICodeInfo::EnumInfo * >;
|
||||||
PICodeInfo::accessValueFunctions = new PIMap<PIString, PICodeInfo::AccessValueFunction>;
|
PICodeInfo::accessValueFunctions = new PIMap<PIConstChars, PICodeInfo::AccessValueFunction>;
|
||||||
PICodeInfo::accessTypeFunctions = new PIMap<PIString, PICodeInfo::AccessTypeFunction>;
|
PICodeInfo::accessTypeFunctions = new PIMap<PIConstChars, PICodeInfo::AccessTypeFunction>;
|
||||||
}
|
}
|
||||||
static bool _inited_;
|
static bool _inited_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ PIString PIString::fromAscii(const char * s, int len) {
|
|||||||
PIString ret;
|
PIString ret;
|
||||||
ret.resize(len);
|
ret.resize(len);
|
||||||
for (int l = 0; l < len; ++l) {
|
for (int l = 0; l < len; ++l) {
|
||||||
ret[l] = s[l];
|
ret[l] = s[l];
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -369,14 +369,14 @@ uint PIString::hash() const {
|
|||||||
|
|
||||||
|
|
||||||
PIByteArray PIString::toUTF8() const {
|
PIByteArray PIString::toUTF8() const {
|
||||||
if (isEmpty()) return PIByteArray(1,'\0');
|
if (isEmpty()) return PIByteArray();
|
||||||
buildData(__utf8name__);
|
buildData(__utf8name__);
|
||||||
return PIByteArray(data_, strlen(data_));
|
return PIByteArray(data_, strlen(data_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIByteArray PIString::toCharset(const char * c) const {
|
PIByteArray PIString::toCharset(const char * c) const {
|
||||||
if (isEmpty()) return PIByteArray(1,'\0');
|
if (isEmpty()) return PIByteArray();
|
||||||
buildData(
|
buildData(
|
||||||
#ifdef PIP_ICU
|
#ifdef PIP_ICU
|
||||||
c
|
c
|
||||||
@@ -418,6 +418,18 @@ PIString & PIString::operator +=(const PIString & str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIString & PIString::operator +=(const PIConstChars & str) {
|
||||||
|
if (!str.isEmpty()) {
|
||||||
|
size_t os = d.size();
|
||||||
|
d.enlarge(str.size());
|
||||||
|
for (size_t l = 0; l < d.size(); ++l) {
|
||||||
|
d[os + l] = str[l];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIString::operator ==(const PIString & str) const {
|
bool PIString::operator ==(const PIString & str) const {
|
||||||
return d == str.d;
|
return d == str.d;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#define PISTRING_H
|
#define PISTRING_H
|
||||||
|
|
||||||
#include "pibytearray.h"
|
#include "pibytearray.h"
|
||||||
|
#include "piconstchars.h"
|
||||||
|
|
||||||
#define PIStringAscii PIString::fromAscii
|
#define PIStringAscii PIString::fromAscii
|
||||||
|
|
||||||
@@ -71,6 +72,7 @@ public:
|
|||||||
PIString & operator +=(const wchar_t * 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) {appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); return *this;}
|
||||||
PIString & operator +=(const PIString & str);
|
PIString & operator +=(const PIString & str);
|
||||||
|
PIString & operator +=(const PIConstChars & str);
|
||||||
|
|
||||||
//! \~english Contructs a copy of string.
|
//! \~english Contructs a copy of string.
|
||||||
//! \~russian Создает копию строки.
|
//! \~russian Создает копию строки.
|
||||||
@@ -143,6 +145,8 @@ public:
|
|||||||
//! PIString s(5, "№"); // s = "№№№№№"
|
//! PIString s(5, "№"); // s = "№№№№№"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString(const int len, const PIChar c) {for (int i = 0; i < len; ++i) d.push_back(c);}
|
PIString(const int len, const PIChar c) {for (int i = 0; i < len; ++i) d.push_back(c);}
|
||||||
|
|
||||||
|
PIString(const PIConstChars & c) {*this += c;}
|
||||||
|
|
||||||
~PIString();
|
~PIString();
|
||||||
|
|
||||||
@@ -154,6 +158,14 @@ public:
|
|||||||
//! \~russian Оператор перемещающего присваивания.
|
//! \~russian Оператор перемещающего присваивания.
|
||||||
PIString & operator =(PIString && o) {d.swap(o.d); piSwap(data_, o.data_); return *this;}
|
PIString & operator =(PIString && o) {d.swap(o.d); piSwap(data_, o.data_); return *this;}
|
||||||
|
|
||||||
|
//! \~english Assign operator.
|
||||||
|
//! \~russian Оператор присваивания.
|
||||||
|
PIString & operator =(const PIConstChars & o) {d.clear(); *this += o; return *this;}
|
||||||
|
|
||||||
|
//! \~english Assign operator.
|
||||||
|
//! \~russian Оператор присваивания.
|
||||||
|
PIString & operator =(const char * o) {d.clear(); *this += o; return *this;}
|
||||||
|
|
||||||
//! \~english Compare operator.
|
//! \~english Compare operator.
|
||||||
//! \~russian Оператор сравнения.
|
//! \~russian Оператор сравнения.
|
||||||
bool operator ==(const PIString & str) const;
|
bool operator ==(const PIString & str) const;
|
||||||
@@ -271,6 +283,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & operator <<(const wchar_t * str) {*this += str; return *this;}
|
PIString & operator <<(const wchar_t * str) {*this += str; return *this;}
|
||||||
|
|
||||||
|
PIString & operator <<(const PIConstChars & str) {*this += str; return *this;}
|
||||||
|
|
||||||
//! \~english Append string representation of "num" at the end of string.
|
//! \~english Append string representation of "num" at the end of string.
|
||||||
//! \~russian Добавляет в конец строковое представление "num".
|
//! \~russian Добавляет в конец строковое представление "num".
|
||||||
//! \~\details
|
//! \~\details
|
||||||
@@ -453,6 +467,8 @@ public:
|
|||||||
//! \~russian Вставляет "str" в конец строки.
|
//! \~russian Вставляет "str" в конец строки.
|
||||||
PIString & append(const PIString & str) {d.append(str.d); return *this;}
|
PIString & append(const PIString & str) {d.append(str.d); return *this;}
|
||||||
|
|
||||||
|
PIString & append(const PIConstChars & str) {*this += str; return *this;}
|
||||||
|
|
||||||
//! \~english Insert character `c` at the end of string.
|
//! \~english Insert character `c` at the end of string.
|
||||||
//! \~russian Вставляет символ `c` в конец строки.
|
//! \~russian Вставляет символ `c` в конец строки.
|
||||||
PIString & append(const PIChar c) {d.append(c); return *this;}
|
PIString & append(const PIChar c) {d.append(c); return *this;}
|
||||||
@@ -469,6 +485,8 @@ public:
|
|||||||
//! \~russian Вставляет "str" в конец строки.
|
//! \~russian Вставляет "str" в конец строки.
|
||||||
PIString & push_back(const PIString & str) {d.push_back(str.d); return *this;}
|
PIString & push_back(const PIString & str) {d.push_back(str.d); return *this;}
|
||||||
|
|
||||||
|
PIString & push_back(const PIConstChars & str) {*this += str; return *this;}
|
||||||
|
|
||||||
//! \~english Insert character `c` at the end of string.
|
//! \~english Insert character `c` at the end of string.
|
||||||
//! \~russian Вставляет символ `c` в конец строки.
|
//! \~russian Вставляет символ `c` в конец строки.
|
||||||
PIString & push_back(const PIChar c) {d.push_back(c); return *this;}
|
PIString & push_back(const PIChar c) {d.push_back(c); return *this;}
|
||||||
|
|||||||
@@ -614,7 +614,7 @@ int PIFile::writeDevice(const void * data, int max_size) {
|
|||||||
|
|
||||||
|
|
||||||
PIFile &PIFile::operator <<(const PIString & v) {
|
PIFile &PIFile::operator <<(const PIString & v) {
|
||||||
if (canWrite() && PRIVATE->fd != 0)
|
if (canWrite() && v.isNotEmpty() && PRIVATE->fd != 0)
|
||||||
*this << v.toCharset(defaultCharset());
|
*this << v.toCharset(defaultCharset());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,11 +266,9 @@ void PIIODevice::write_func() {
|
|||||||
|
|
||||||
PIIODevice * PIIODevice::newDeviceByPrefix(const char * prefix) {
|
PIIODevice * PIIODevice::newDeviceByPrefix(const char * prefix) {
|
||||||
if (!prefix) return nullptr;
|
if (!prefix) return nullptr;
|
||||||
PIConstChars p(prefix);
|
auto fi = fabrics().value(prefix);
|
||||||
for (const auto & i: fabrics()) {
|
if (fi.fabricator)
|
||||||
if (i.first == p)
|
return fi.fabricator();
|
||||||
return i.second();
|
|
||||||
}
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,17 +486,30 @@ void PIIODevice::splitFullPath(PIString fpwm, PIString * full_path, DeviceMode *
|
|||||||
PIStringList PIIODevice::availablePrefixes() {
|
PIStringList PIIODevice::availablePrefixes() {
|
||||||
PIStringList ret;
|
PIStringList ret;
|
||||||
for (const auto & i: fabrics())
|
for (const auto & i: fabrics())
|
||||||
ret << i.first.toString();
|
ret << i.second.prefix.toString();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIIODevice::registerDevice(const char * prefix, PIIODevice * (*fabric)()) {
|
PIStringList PIIODevice::availableClasses() {
|
||||||
|
PIStringList ret;
|
||||||
|
for (const auto & i: fabrics())
|
||||||
|
ret << i.second.classname.toString();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIIODevice::registerDevice(const char * prefix, const char * classname, PIIODevice * (*fabric)()) {
|
||||||
PIConstChars p(prefix);
|
PIConstChars p(prefix);
|
||||||
if (p.isEmpty()) return;
|
if (p.isEmpty()) return;
|
||||||
//printf("registerDevice %s %d %d\n", prefix, p.isEmpty(), fabrics().size());
|
//printf("registerDevice %s %d %d\n", prefix, p.isEmpty(), fabrics().size());
|
||||||
if (!fabrics().contains(p))
|
if (!fabrics().contains(p)) {
|
||||||
fabrics()[p] = fabric;
|
FabricInfo fi;
|
||||||
|
fi.prefix = prefix;
|
||||||
|
fi.classname = classname;
|
||||||
|
fi.fabricator = fabric;
|
||||||
|
fabrics()[p] = fi;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -555,8 +566,8 @@ void PIIODevice::cacheFullPath(const PIString & full_path, const PIIODevice * d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIMap<PIConstChars, PIIODevice * (*)()> & PIIODevice::fabrics() {
|
PIMap<PIConstChars, PIIODevice::FabricInfo> & PIIODevice::fabrics() {
|
||||||
static PIMap<PIConstChars, PIIODevice * (*)()> ret;
|
static PIMap<PIConstChars, FabricInfo> ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ typedef bool (*ReadRetFunc)(void * , uchar * , int );
|
|||||||
|
|
||||||
# define REGISTER_DEVICE(name) \
|
# define REGISTER_DEVICE(name) \
|
||||||
STATIC_INITIALIZER_BEGIN \
|
STATIC_INITIALIZER_BEGIN \
|
||||||
PIIODevice::registerDevice(name::fullPathPrefixS(), []()->PIIODevice*{return new name();});\
|
PIIODevice::registerDevice(name::fullPathPrefixS(), #name, []()->PIIODevice*{return new name();});\
|
||||||
STATIC_INITIALIZER_END
|
STATIC_INITIALIZER_END
|
||||||
|
|
||||||
# define PIIODEVICE(name, prefix) \
|
# define PIIODEVICE(name, prefix) \
|
||||||
@@ -90,6 +90,12 @@ public:
|
|||||||
Reliable /*! Channel without data errors / corruptions */ = 0x02
|
Reliable /*! Channel without data errors / corruptions */ = 0x02
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct FabricInfo {
|
||||||
|
PIConstChars prefix;
|
||||||
|
PIConstChars classname;
|
||||||
|
PIIODevice*(*fabricator)() = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
typedef PIFlags<DeviceOption> DeviceOptions;
|
typedef PIFlags<DeviceOption> DeviceOptions;
|
||||||
typedef PIFlags<DeviceInfoFlag> DeviceInfoFlags;
|
typedef PIFlags<DeviceInfoFlag> DeviceInfoFlags;
|
||||||
|
|
||||||
@@ -271,7 +277,10 @@ public:
|
|||||||
//! Returns fullPath prefixes of all registered devices
|
//! Returns fullPath prefixes of all registered devices
|
||||||
static PIStringList availablePrefixes();
|
static PIStringList availablePrefixes();
|
||||||
|
|
||||||
static void registerDevice(const char * prefix, PIIODevice*(*fabric)());
|
//! Returns class names of all registered devices
|
||||||
|
static PIStringList availableClasses();
|
||||||
|
|
||||||
|
static void registerDevice(const char * prefix, const char * classname, PIIODevice*(*fabric)());
|
||||||
|
|
||||||
|
|
||||||
EVENT_HANDLER(bool, open);
|
EVENT_HANDLER(bool, open);
|
||||||
@@ -421,7 +430,7 @@ private:
|
|||||||
void run();
|
void run();
|
||||||
void end() {terminate();}
|
void end() {terminate();}
|
||||||
static void cacheFullPath(const PIString & full_path, const PIIODevice * d);
|
static void cacheFullPath(const PIString & full_path, const PIIODevice * d);
|
||||||
static PIMap<PIConstChars, PIIODevice*(*)()> & fabrics();
|
static PIMap<PIConstChars, FabricInfo> & fabrics();
|
||||||
|
|
||||||
PITimer timer;
|
PITimer timer;
|
||||||
PITimeMeasurer tm;
|
PITimeMeasurer tm;
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
|||||||
PIString inc_string;
|
PIString inc_string;
|
||||||
PIVector<PIString> incf = inc_files.toVector();
|
PIVector<PIString> incf = inc_files.toVector();
|
||||||
piForeachC (PIString & i, incf) {
|
piForeachC (PIString & i, incf) {
|
||||||
if (i != parser.mainFile())
|
if ((i != parser.mainFile()) && (streams || texts || getters))
|
||||||
inc_string << "\n#include \"" << i << "\"";
|
inc_string << "\n#include \"" << i << "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user