PIObject Property const char *

This commit is contained in:
Andrey
2022-04-29 18:17:03 +03:00
parent 97dd19f0c7
commit 8c8553a6af
7 changed files with 44 additions and 46 deletions

View File

@@ -208,8 +208,9 @@ PIObject::~PIObject() {
PIMap<PIString, PIVariant> PIObject::properties() const {
PIMap<PIString, PIVariant> ret;
piForeachC (PropertyHash p, properties_)
ret[p.second.first] = p.second.second;
for (const PropertyHash & p : properties_) {
ret[PIStringAscii(p.second.first)] = p.second.second;
}
return ret;
}
@@ -693,9 +694,12 @@ void PIObject::dump(const PIString & line_prefix) const {
PICout(PICoutManipulators::AddNewLine) << line_prefix << " properties {";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << properties_.size_s();
//printf("dump %d properties\n", properties_.size());
piForeachC (PropertyHash p, properties_)
if (p.first != PIString("name").hash())
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << p.second.first << ": " << p.second.second;
const char * o_name = "name";
auto it = properties_.makeIterator();
while (it.next()) {
if (it.key() != piHashData((const uchar *)o_name, strlen(o_name)))
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << it.value().first << ": " << it.value().second;
}
//printf("dump %d properties ok\n", properties_.size());
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methods {";
@@ -710,7 +714,7 @@ void PIObject::dump(const PIString & line_prefix) const {
PICout(PICoutManipulators::AddNewLine) << line_prefix << " connections {";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << connections.size_s();
//printf("dump %d connections\n",connections.size());
piForeachC (Connection & c, connections) {
for (const Connection & c : connections) {
PIObject * dst = c.dest_o;
__MetaFunc ef = methodEH(c.signal);
PIString src(c.event);

View File

@@ -113,7 +113,7 @@ public:
//! \~english Returns object name
//! \~russian Возвращает имя объекта
PIString name() const {return property(PIStringAscii("name")).toString();}
PIString name() const {return property("name").toString();}
//! \~english Returns object class name
//! \~russian Возвращает имя класса объекта
@@ -131,17 +131,16 @@ public:
//! \~english Return if \a piCoutObj of this object is active
//! \~russian Возвращает включен ли вывод \a piCoutObj для этого объекта
bool debug() const {return property(PIStringAscii("debug")).toBool();}
bool debug() const {return property("debug").toBool();}
//! \~english Set object name
//! \~russian Устанавливает имя объекта
void setName(const PIString & name) {setProperty(PIStringAscii("name"), name);}
void setName(const char * name) {setName(PIStringAscii(name));}
void setName(const PIString & name) {setProperty("name", name);}
//! \~english Set object \a piCoutObj active
//! \~russian Включает или отключает вывод \a piCoutObj для этого объекта
void setDebug(bool debug) {setProperty(PIStringAscii("debug"), debug);}
void setDebug(bool debug) {setProperty("debug", debug);}
//! \~english Returns properties of the object
//! \~russian Возвращает словарь свойств объекта
@@ -153,18 +152,15 @@ public:
//! \~english Returns property with name "name"
//! \~russian Возвращает свойство объекта по имени "name"
PIVariant property(const PIString & name) const {return properties_.value(name.hash(), Property(PIString(), PIVariant())).second;}
PIVariant property(const char * name) const {return property(PIStringAscii(name));}
PIVariant property(const char * name) const {return properties_.value(piHashData((const uchar *)name, strlen(name)), Property(nullptr, PIVariant())).second;}
//! \~english Set property with name "name" to "value". If there is no such property in object it will be added
//! \~russian Устанавливает у объекта свойство по имени "name" в "value". Если такого свойства нет, оно добавляется
void setProperty(const PIString & name, const PIVariant & value) {properties_[name.hash()] = Property(name, value); propertyChanged(name);}
void setProperty(const char * name, const PIVariant & value) {setProperty(PIStringAscii(name), value);}
void setProperty(const char * name, const PIVariant & value) {properties_[piHashData((const uchar *)name, strlen(name))] = Property(name, value); propertyChanged(name);}
//! \~english Returns if property with name "name" exists
//! \~russian Возвращает присутствует ли свойство по имени "name"
bool isPropertyExists(const PIString & name) const {return properties_.contains(name.hash());}
bool isPropertyExists(const char * name) const {return isPropertyExists(PIStringAscii(name));}
bool isPropertyExists(const char * name) const {return properties_.contains(piHashData((const uchar *)name, strlen(name)));}
void setThreadSafe(bool yes) {thread_safe_ = yes;}
bool isThreadSafe() const {return thread_safe_;}
@@ -520,7 +516,7 @@ protected:
//! \~english Virtual function executes after property with name "name" has been changed
//! \~russian Виртуальная функция, вызывается после изменения любого свойства.
virtual void propertyChanged(const PIString & name) {}
virtual void propertyChanged(const char * name) {}
EVENT1(deleted, PIObject *, o)
@@ -569,8 +565,8 @@ private:
PRIVATE_DECLARATION(PIP_EXPORT)
};
typedef PIPair<PIString, PIVariant> Property;
typedef PIPair<uint, PIPair<PIString, PIVariant> > PropertyHash;
typedef PIPair<const char *, PIVariant> Property;
typedef PIPair<uint, Property > PropertyHash;
bool findSuitableMethodV(const PIString & method, int args, int & ret_args, __MetaFunc & ret);
PIVector<__MetaFunc> findEH(const PIString & name) const;
@@ -591,7 +587,7 @@ private:
PIVector<Connection> connections;
PIMap<uint, PIPair<PIString, PIVariant> > properties_;
PIMap<uint, Property> properties_;
PISet<PIObject * > connectors;
PIVector<__QueuedEvent> events_queue;
PIMutex mutex_, mutex_connect, mutex_queue;

View File

@@ -257,8 +257,6 @@ public:
//! \~russian Возвращает свойство с именем "name" как константу
const Property operator[](const PIString & name) const;
static Property parsePropertyLine(PIString l);
protected:
PIVector<Property> props;

View File

@@ -63,7 +63,7 @@ const char PIString::toBaseN[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^'};
const int PIString::fromBaseN[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
const char PIString::fromBaseN[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
@@ -168,7 +168,7 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
PIVector<int> digits;
llong ret = 0, m = 1;
bool neg = false;
int cs;
char cs;
for (int i = 0; i < v.size_s(); ++i) {
if (v[i] == PIChar('-')) {
neg = !neg;

View File

@@ -1531,7 +1531,7 @@ public:
private:
static const char toBaseN[];
static const int fromBaseN[];
static const char fromBaseN[];
static PIString itos(const int num);
static PIString ltos(const long num);