PIIODevice fullPathPrefix returns PIConstChars

This commit is contained in:
2022-05-04 16:33:05 +03:00
parent 28ce6e8f3f
commit 6995c25613
4 changed files with 36 additions and 16 deletions

View File

@@ -23,10 +23,7 @@
//! \addtogroup Core //! \addtogroup Core
//! \{ //! \{
//! \~\class PIConstChars piconstchars.h //! \~\class PIConstChars piconstchars.h
//! \~\brief //! \~\details
//! \~english C-String class
//! \~russian Класс C-строки
//!
//! \~english \section PICout_sec0 Synopsis //! \~english \section PICout_sec0 Synopsis
//! \~russian \section PICout_sec0 Краткий обзор //! \~russian \section PICout_sec0 Краткий обзор
//! \~english //! \~english
@@ -54,12 +51,24 @@ bool PIConstChars::startsWith(const PIConstChars & str) const {
} }
bool PIConstChars::startsWith(const char c) const {
if (size() < 1) return false;
return str[0] == c;
}
bool PIConstChars::endsWith(const PIConstChars & str) const { bool PIConstChars::endsWith(const PIConstChars & str) const {
if (size() < str.size()) return false; if (size() < str.size()) return false;
return str == right(str.size()); return str == right(str.size());
} }
bool PIConstChars::endsWith(const char c) const {
if (size() < 1) return false;
return str[len - 1] == c;
}
PIConstChars PIConstChars::mid(const int start, const int len) const { PIConstChars PIConstChars::mid(const int start, const int len) const {
int s = start, l = len; int s = start, l = len;
if (l == 0 || s >= (int)size() || isEmpty()) return PIConstChars(""); if (l == 0 || s >= (int)size() || isEmpty()) return PIConstChars("");

View File

@@ -29,6 +29,10 @@
#include "picout.h" #include "picout.h"
//! \ingroup Core
//! \~\brief
//! \~english C-String class
//! \~russian Класс C-строки
class PIP_EXPORT PIConstChars { class PIP_EXPORT PIConstChars {
public: public:
@@ -98,10 +102,18 @@ public:
//! \~russian Возвращает начинается ли строка со "str". //! \~russian Возвращает начинается ли строка со "str".
bool startsWith(const PIConstChars & str) const; bool startsWith(const PIConstChars & str) const;
//! \~english Returns if string starts with "c".
//! \~russian Возвращает начинается ли строка с "c".
bool startsWith(const char c) const;
//! \~english Returns if string ends with "str". //! \~english Returns if string ends with "str".
//! \~russian Возвращает оканчивается ли строка на "str". //! \~russian Возвращает оканчивается ли строка на "str".
bool endsWith(const PIConstChars & str) const; bool endsWith(const PIConstChars & str) const;
//! \~english Returns if string ends with "c".
//! \~russian Возвращает оканчивается ли строка "c".
bool endsWith(const char c) const;
//! \~english Returns part of string from character at index "start" and maximum length "len". //! \~english Returns part of string from character at index "start" and maximum length "len".
//! \~russian Возвращает подстроку от символа "start" и максимальной длиной "len". //! \~russian Возвращает подстроку от символа "start" и максимальной длиной "len".
//! \~\sa \a left(), \a right() //! \~\sa \a left(), \a right()

View File

@@ -87,7 +87,7 @@
//! \n \a constructFullPath() should returns full unambiguous string, contains prefix and all device parameters //! \n \a constructFullPath() should returns full unambiguous string, contains prefix and all device parameters
//! \n \a configureFromFullPath() provide configuring device from full unambiguous string without prefix and "://" //! \n \a configureFromFullPath() provide configuring device from full unambiguous string without prefix and "://"
//! \n Macro PIIODEVICE should be used instead of PIOBJECT //! \n Macro PIIODEVICE should be used instead of PIOBJECT
//! \n Macro REGISTER_DEVICE should be used after definition of class, i.e. at the last line of *.cpp file //! \n Macro REGISTER_DEVICE should be used after declaration of class, i.e. at the last line of *.h file
//! \n \n If custom I/O device corresponds there rules, it can be returned by function \a createFromFullPath(). //! \n \n If custom I/O device corresponds there rules, it can be returned by function \a createFromFullPath().
//! \n Each PIP I/O device has custom unambiguous string description: //! \n Each PIP I/O device has custom unambiguous string description:
//! * PIFile: "file://<path>" //! * PIFile: "file://<path>"
@@ -423,7 +423,7 @@ bool PIIODevice::configure(const PIString & config_file, const PIString & sectio
PIString PIIODevice::constructFullPath() const { PIString PIIODevice::constructFullPath() const {
return PIStringAscii(fullPathPrefix()) + PIStringAscii("://") + constructFullPathDevice() + fullPathOptions(); return fullPathPrefix().toString() + PIStringAscii("://") + constructFullPathDevice() + fullPathOptions();
} }
@@ -499,16 +499,15 @@ PIStringList PIIODevice::availableClasses() {
} }
void PIIODevice::registerDevice(const char * prefix, const char * classname, PIIODevice * (*fabric)()) { void PIIODevice::registerDevice(PIConstChars prefix, PIConstChars classname, PIIODevice * (*fabric)()) {
PIConstChars p(prefix); if (prefix.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(prefix)) {
FabricInfo fi; FabricInfo fi;
fi.prefix = prefix; fi.prefix = prefix;
fi.classname = classname; fi.classname = classname;
fi.fabricator = fabric; fi.fabricator = fabric;
fabrics()[p] = fi; fabrics()[prefix] = fi;
} }
} }

View File

@@ -54,8 +54,8 @@ typedef bool (*ReadRetFunc)(void * , uchar * , int );
PIOBJECT_SUBCLASS(name, PIIODevice) \ PIOBJECT_SUBCLASS(name, PIIODevice) \
PIIODevice * copy() const {return new name();} \ PIIODevice * copy() const {return new name();} \
public: \ public: \
virtual const char * fullPathPrefix() const {return prefix;} \ virtual PIConstChars fullPathPrefix() const {return prefix;} \
static const char * fullPathPrefixS() {return prefix;} \ static PIConstChars fullPathPrefixS() {return prefix;} \
private: private:
@@ -244,9 +244,9 @@ public:
//! Returns full unambiguous string prefix. \ref PIIODevice_sec7 //! Returns full unambiguous string prefix. \ref PIIODevice_sec7
virtual const char * fullPathPrefix() const {return "";} virtual PIConstChars fullPathPrefix() const {return "";}
static const char * fullPathPrefixS() {return "";} static PIConstChars fullPathPrefixS() {return "";}
//! Returns full unambiguous string, describes this device, \a fullPathPrefix() + "://" //! Returns full unambiguous string, describes this device, \a fullPathPrefix() + "://"
PIString constructFullPath() const; PIString constructFullPath() const;
@@ -280,7 +280,7 @@ public:
//! Returns class names of all registered devices //! Returns class names of all registered devices
static PIStringList availableClasses(); static PIStringList availableClasses();
static void registerDevice(const char * prefix, const char * classname, PIIODevice*(*fabric)()); static void registerDevice(PIConstChars prefix, PIConstChars classname, PIIODevice*(*fabric)());
EVENT_HANDLER(bool, open); EVENT_HANDLER(bool, open);