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);

View File

@@ -201,44 +201,44 @@ public:
//! Set parameters to "parameters_". You should to reopen %PIEthernet to apply them
void setParameters(PIFlags<PIEthernet::Parameters> parameters_) {setProperty(PIStringAscii("parameters"), (int)parameters_);}
void setParameters(PIFlags<PIEthernet::Parameters> parameters_) {setProperty("parameters", (int)parameters_);}
//! Set parameter "parameter" to state "on". You should to reopen %PIEthernet to apply this
void setParameter(PIEthernet::Parameters parameter, bool on = true);
//! Returns if parameter "parameter" is set
bool isParameterSet(PIEthernet::Parameters parameter) const {return ((PIFlags<PIEthernet::Parameters>)(property(PIStringAscii("parameters")).toInt()))[parameter];}
bool isParameterSet(PIEthernet::Parameters parameter) const {return ((PIFlags<PIEthernet::Parameters>)(property("parameters").toInt()))[parameter];}
//! Returns parameters
PIFlags<PIEthernet::Parameters> parameters() const {return (PIFlags<PIEthernet::Parameters>)(property(PIStringAscii("parameters")).toInt());}
PIFlags<PIEthernet::Parameters> parameters() const {return (PIFlags<PIEthernet::Parameters>)(property("parameters").toInt());}
//! Returns %PIEthernet type
Type type() const {return (Type)(property(PIStringAscii("type")).toInt());}
Type type() const {return (Type)(property("type").toInt());}
//! Returns read timeout
double readTimeout() const {return property(PIStringAscii("readTimeout")).toDouble();}
double readTimeout() const {return property("readTimeout").toDouble();}
//! Returns write timeout
double writeTimeout() const {return property(PIStringAscii("writeTimeout")).toDouble();}
double writeTimeout() const {return property("writeTimeout").toDouble();}
//! Set timeout for read
void setReadTimeout(double ms) {setProperty(PIStringAscii("readTimeout"), ms);}
void setReadTimeout(double ms) {setProperty("readTimeout", ms);}
//! Set timeout for write
void setWriteTimeout(double ms) {setProperty(PIStringAscii("writeTimeout"), ms);}
void setWriteTimeout(double ms) {setProperty("writeTimeout", ms);}
//! Returns TTL (Time To Live)
int TTL() const {return property(PIStringAscii("TTL")).toInt();}
int TTL() const {return property("TTL").toInt();}
//! Returns multicast TTL (Time To Live)
int multicastTTL() const {return property(PIStringAscii("MulticastTTL")).toInt();}
int multicastTTL() const {return property("MulticastTTL").toInt();}
//! Set TTL (Time To Live), default is 64
void setTTL(int ttl) {setProperty(PIStringAscii("TTL"), ttl);}
void setTTL(int ttl) {setProperty("TTL", ttl);}
//! Set multicast TTL (Time To Live), default is 1
void setMulticastTTL(int ttl) {setProperty(PIStringAscii("MulticastTTL"), ttl);}
void setMulticastTTL(int ttl) {setProperty("MulticastTTL", ttl);}
//! Join to multicast group with address "group". Use only for UDP
@@ -499,7 +499,7 @@ protected:
private:
EVENT_HANDLER1(void, clientDeleted, PIObject *, o);
static void server_func(void * eth);
void setType(Type t, bool reopen = true) {setProperty(PIStringAscii("type"), (int)t); if (reopen && isOpened()) {closeDevice(); init(); openDevice();}}
void setType(Type t, bool reopen = true) {setProperty("type", (int)t); if (reopen && isOpened()) {closeDevice(); init(); openDevice();}}
static int ethErrorCore();
static PIString ethErrorString();

View File

@@ -109,10 +109,10 @@ public:
DeviceInfoFlags infoFlags() const {return deviceInfoFlags();}
//! Current path of device
PIString path() const {return property(PIStringAscii("path")).toString();}
PIString path() const {return property("path").toString();}
//! Set path of device
void setPath(const PIString & path) {setProperty(PIStringAscii("path"), path);}
void setPath(const PIString & path) {setProperty("path", path);}
//! Return \b true if mode is ReadOnly or ReadWrite
bool isReadable() const {return (mode_ & ReadOnly);}
@@ -134,17 +134,17 @@ public:
//! Set execution of \a open enabled while threaded read on closed device
void setReopenEnabled(bool yes = true) {setProperty(PIStringAscii("reopenEnabled"), yes);}
void setReopenEnabled(bool yes = true) {setProperty("reopenEnabled", yes);}
//! Set timeout in milliseconds between \a open tryings if reopen is enabled
void setReopenTimeout(int msecs) {setProperty(PIStringAscii("reopenTimeout"), msecs);}
void setReopenTimeout(int msecs) {setProperty("reopenTimeout", msecs);}
//! Return reopen enable
bool isReopenEnabled() const {return property(PIStringAscii("reopenEnabled")).toBool();}
bool isReopenEnabled() const {return property("reopenEnabled").toBool();}
//! Return reopen timeout
int reopenTimeout() {return property(PIStringAscii("reopenTimeout")).toInt();}
int reopenTimeout() {return property("reopenTimeout").toInt();}
/** \brief Set "threaded read slot"