This commit is contained in:
peri4
2022-03-21 22:03:47 +03:00
parent 20e0771331
commit 9a8b9c7141
7 changed files with 404 additions and 149 deletions

View File

@@ -78,11 +78,11 @@ public:
//! \~russian Устанавливает флаг "i" в "on" //! \~russian Устанавливает флаг "i" в "on"
PIFlags & setFlag(const int & i, bool on = true) {if (on) flags |= i; else flags &= ~i; return *this;} PIFlags & setFlag(const int & i, bool on = true) {if (on) flags |= i; else flags &= ~i; return *this;}
//! \~english Copy operator //! \~english Assign operator
//! \~russian Оператор присваивания //! \~russian Оператор присваивания
void operator =(const Enum & e) {flags = e;} void operator =(const Enum & e) {flags = e;}
//! \~english Copy operator //! \~english Assign operator
//! \~russian Оператор присваивания //! \~russian Оператор присваивания
void operator =(const int & i) {flags = i;} void operator =(const int & i) {flags = i;}

View File

@@ -20,6 +20,62 @@
#include "pipropertystorage.h" #include "pipropertystorage.h"
//! \addtogroup Core
//! \{
//! \~\class PIPropertyStorage pipropertystorage.h
//! \~\brief
//! \~english This class provides key-value properties storage
//! \~russian Этот класс предоставляет ключ-значение хранение свойств
//!
//! \~\details
//! \~english \section PIPropertyStorage_sec0 Synopsis
//! \~russian \section PIPropertyStorage_sec0 Краткий обзор
//!
//! \~english
//! Key-value storage, based on PIVector with PIPropertyStorage::Property elements. Each element in vector
//! contains unique name. You can access property by name with \a propertyValueByName() or \a propertyByName().
//! You can add or replace property by \a addProperty(const Property&) or \a addProperty(const PIString&, const PIVariant&, const PIString&, int).
//!
//! \~russian
//! Хранилище свойств ключ-значние, основанный на PIVector с элементами PIPropertyStorage::Property.
//! Каждый элемент имеет уникальное имя. Доступ к свойствам через \a propertyValueByName() или \a propertyByName().
//! Добавление и перезапись свойств через \a addProperty(const Property&) или \a addProperty(const PIString&, const PIVariant&, const PIString&, int).
//!
//! \~english Example:
//! \~russian Пример:
//! \~\code{.cpp}
//! \endcode
//! \}
//! \addtogroup Core
//! \{
//! \~\class PIPropertyStorage::Property pipropertystorage.h
//! \~\brief
//! \~english PIPropertyStorage element
//! \~russian Элемент PIPropertyStorage
//!
//! \~\details
//! \~english \section PIPropertyStorage_sec0 Synopsis
//! \~russian \section PIPropertyStorage_sec0 Краткий обзор
//!
//! \~english
//! Key-value storage, based on PIVector with PIPropertyStorage::Property elements. Each element in vector
//! contains unique name. You can access property by name with \a propertyValueByName() or \a propertyByName().
//! You can add or replace property by \a addProperty(const Property&) or \a addProperty(const PIString&, const PIVariant&, const PIString&, int).
//!
//! \~russian
//! Хранилище свойств ключ-значние, основанный на PIVector с элементами PIPropertyStorage::Property.
//! Каждый элемент имеет уникальное имя. Доступ к свойствам через \a propertyValueByName() или \a propertyByName().
//! Добавление и перезапись свойств через \a addProperty(const Property&) или \a addProperty(const PIString&, const PIVariant&, const PIString&, int).
//!
//! \~english Example:
//! \~russian Пример:
//! \~\code{.cpp}
//! \endcode
//! \}
bool PIPropertyStorage::isPropertyExists(const PIString & _name) const { bool PIPropertyStorage::isPropertyExists(const PIString & _name) const {
for (uint i = 0; i < props.size(); ++i) for (uint i = 0; i < props.size(); ++i)
if (props[i].name == _name) if (props[i].name == _name)
@@ -28,6 +84,9 @@ bool PIPropertyStorage::isPropertyExists(const PIString & _name) const {
} }
//! \details
//! \~english Returns "true" if new property added, else if update existing property return "false"
//! \~russian Возвращает истину если новое свойство добавлено, в случае обновления "ложь"
bool PIPropertyStorage::addProperty(const PIPropertyStorage::Property & p) { bool PIPropertyStorage::addProperty(const PIPropertyStorage::Property & p) {
for (uint i = 0; i < props.size(); ++i) for (uint i = 0; i < props.size(); ++i)
if (props[i].name == p.name) { if (props[i].name == p.name) {
@@ -50,6 +109,9 @@ bool PIPropertyStorage::addProperty(PIPropertyStorage::Property && p) {
} }
//! \details
//! \~english Returns "true" if new property added, else if update existing property return "false"
//! \~russian Возвращает истину если новое свойство добавлено, в случае обновления "ложь"
bool PIPropertyStorage::addProperty(const PIString & _name, const PIVariant & _def_value, const PIString & _comment, int _flags) { bool PIPropertyStorage::addProperty(const PIString & _name, const PIVariant & _def_value, const PIString & _comment, int _flags) {
return addProperty(Property(_name, _comment, _def_value, _flags)); return addProperty(Property(_name, _comment, _def_value, _flags));
} }
@@ -66,6 +128,9 @@ bool PIPropertyStorage::removeProperty(const PIString & _name) {
} }
//! \details
//! \~english "flag" checked as bitfield
//! \~russian "flag" проверяется как битовое поле
int PIPropertyStorage::removePropertiesByFlag(int flag) { int PIPropertyStorage::removePropertiesByFlag(int flag) {
int ret = 0; int ret = 0;
for (int i = 0; i < props.size_s(); ++i) { for (int i = 0; i < props.size_s(); ++i) {
@@ -79,6 +144,9 @@ int PIPropertyStorage::removePropertiesByFlag(int flag) {
} }
//! \details
//! \~english "flag_ignore" is bitfield to ignore property in merge process
//! \~russian "flag_ignore" - битовое поле для исключения свойств из процесса слияния
void PIPropertyStorage::updateProperties(const PIVector<PIPropertyStorage::Property> & properties_, int flag_ignore) { void PIPropertyStorage::updateProperties(const PIVector<PIPropertyStorage::Property> & properties_, int flag_ignore) {
PIMap<PIString, PIVariant> values; PIMap<PIString, PIVariant> values;
piForeachC(Property & p, props) piForeachC(Property & p, props)

View File

@@ -1,8 +1,8 @@
/*! \file pipropertystorage.h /*! \file pipropertystorage.h
* \brief Storage of properties for GUI usage * \~\brief
* * \~english Properties array
* This file declare PIPropertyStorage * \~russian Массив свойств
*/ */
/* /*
PIP - Platform Independent Primitives PIP - Platform Independent Primitives
Storage of properties for GUI usage Storage of properties for GUI usage
@@ -27,25 +27,28 @@
#include "pivariant.h" #include "pivariant.h"
/**
* \brief Key-value storage, based on PIVector with PIPropertyStorage::Property elements. Each element in vector
* contains unique name and you can identify property by name with propertyValueByName(), propertyByName().
* You can add property using addProperty(const Property&), addProperty(const PIString&, const PIVariant&, const PIString&, int).
*/
class PIP_EXPORT PIPropertyStorage { class PIP_EXPORT PIPropertyStorage {
public: public:
//! \~english Contructs an empty %PIPropertyStorage
//! \~russian Создает пустой %PIPropertyStorage
PIPropertyStorage() {} PIPropertyStorage() {}
/**
* \brief PIPropertyStorage element.
*/
struct PIP_EXPORT Property { struct PIP_EXPORT Property {
Property(const PIString & n = PIString(), const PIString & c = PIString(), const PIVariant & v = PIVariant(), int f = 0):
name(n), comment(c), value(v), flags(f) {} //! \~english Contructs %PIPropertyStorage::Property with name "n", comment "c", value "v" and flags "f"
Property(const Property & o): //! \~russian Создает %PIPropertyStorage::Property с именем "n", комментарием "c", значением "v" и флагами "f"
name(o.name), comment(o.comment), value(o.value), flags(o.flags) {} Property(const PIString & n = PIString(), const PIString & c = PIString(), const PIVariant & v = PIVariant(), int f = 0): name(n), comment(c), value(v), flags(f) {}
//! \~english Contructs copy of another %PIPropertyStorage::Property "o"
//! \~russian Создает копию %PIPropertyStorage::Property "o"
Property(const Property & o): name(o.name), comment(o.comment), value(o.value), flags(o.flags) {}
Property(Property && o) {swap(o);} Property(Property && o) {swap(o);}
//! \~english Assign operator
//! \~russian Оператор присваивания
Property & operator =(const Property & v) { Property & operator =(const Property & v) {
name = v.name; name = v.name;
comment = v.comment; comment = v.comment;
@@ -56,10 +59,24 @@ public:
Property & operator =(Property && v) {swap(v); return *this;} Property & operator =(Property && v) {swap(v); return *this;}
//! \~english Returns value as boolean
//! \~russian Возвращает значение как логическое
bool toBool() const {return value.toBool();} bool toBool() const {return value.toBool();}
//! \~english Returns value as integer
//! \~russian Возвращает значение как целое
int toInt() const {return value.toInt();} int toInt() const {return value.toInt();}
//! \~english Returns value as float
//! \~russian Возвращает значение как float
float toFloat() const {return value.toFloat();} float toFloat() const {return value.toFloat();}
//! \~english Returns value as double
//! \~russian Возвращает значение как double
double toDouble() const {return value.toDouble();} double toDouble() const {return value.toDouble();}
//! \~english Returns value as string
//! \~russian Возвращает значение как строку
PIString toString() const {return value.toString();} PIString toString() const {return value.toString();}
void swap(Property & o) { void swap(Property & o) {
@@ -69,22 +86,30 @@ public:
piSwap(flags, o.flags); piSwap(flags, o.flags);
} }
/*! Uniqueue id of property */ //! \~english Property name (uniqueue for %PIPropertyStorage)
//! \~russian Имя свойства (уникальное для %PIPropertyStorage)
PIString name; PIString name;
/*! Optional description of property */ //! \~english Optional description of property
//! \~russian Опциональный комментарий свойства
PIString comment; PIString comment;
/*! Custom value of property */ //! \~english Property value
//! \~russian Значение свойства
PIVariant value; PIVariant value;
/*! Abstract flags which may be used for user needs */ //! \~english Abstract flags which may be used for user needs
//! \~russian Абстрактные флаги, могут быть использованы для своих нужд
int flags; int flags;
}; };
//! \~english Contructs %PIPropertyStorage with "pl" properties
//! \~russian Создает %PIPropertyStorage со свойствами "pl"
PIPropertyStorage(const PIVector<Property> & pl) {props = pl;} PIPropertyStorage(const PIVector<Property> & pl) {props = pl;}
PIPropertyStorage(PIVector<Property> && pl): props(std::move(pl)) {} //! \~english Contructs %PIPropertyStorage from another "o"
//! \~russian Создает %PIPropertyStorage из другого "o"
PIPropertyStorage(PIVector<Property> && o): props(std::move(o)) {}
typedef PIVector<Property>::const_iterator const_iterator; typedef PIVector<Property>::const_iterator const_iterator;
typedef PIVector<Property>::iterator iterator; typedef PIVector<Property>::iterator iterator;
@@ -95,115 +120,140 @@ public:
iterator end() {return props.end();} iterator end() {return props.end();}
const_iterator end() const {return props.end();} const_iterator end() const {return props.end();}
//! \~english Returns properties count
//! \~russian Возвращает количество свойств
int length() const {return props.length();} int length() const {return props.length();}
//! \~english Returns properties count
//! \~russian Возвращает количество свойств
int size() const {return props.size();} int size() const {return props.size();}
//! \~english Returns if no properties
//! \~russian Возвращает нет ли свойств
bool isEmpty() const {return props.isEmpty();} bool isEmpty() const {return props.isEmpty();}
//! \~english Returns if properties
//! \~russian Возвращает есть ли свойства
bool isNotEmpty() const {return props.isNotEmpty();}
//! \~english Returns first property
//! \~russian Возвращает первое свойство
Property & front() {return props.front();} Property & front() {return props.front();}
//! \~english Returns first property as const
//! \~russian Возвращает первое свойство как константу
const Property & front() const {return props.front();} const Property & front() const {return props.front();}
//! \~english Returns last property
//! \~russian Возвращает последнее свойство
Property & back() {return props.back();} Property & back() {return props.back();}
//! \~english Returns last property as const
//! \~russian Возвращает последнее свойство как константу
const Property & back() const {return props.back();} const Property & back() const {return props.back();}
//! \~english Remove property at index "i"
//! \~russian Удаляет свойство по индексу "i"
void removeAt(int i) {props.remove(i);} void removeAt(int i) {props.remove(i);}
//! \~english Remove all properties
//! \~russian Удаляет все свойства
void clear() {props.clear();} void clear() {props.clear();}
//! \~english Returns copy of this %PIPropertyStorage
//! \~russian Возвращает копию этого %PIPropertyStorage
PIPropertyStorage copy() const {return PIPropertyStorage(*this);} PIPropertyStorage copy() const {return PIPropertyStorage(*this);}
//! \~english Returns properties count
//! \~russian Возвращает количество свойств
int propertiesCount() const {return props.size();} int propertiesCount() const {return props.size();}
//! \~english Returns properties as PIVector
//! \~russian Возвращает свойства как PIVector
PIVector<Property> & properties() {return props;} PIVector<Property> & properties() {return props;}
//! \~english Returns properties as const PIVector
//! \~russian Возвращает свойства как константный PIVector
const PIVector<Property> & properties() const {return props;} const PIVector<Property> & properties() const {return props;}
const PIPropertyStorage & propertyStorage() const {return *this;} const PIPropertyStorage & propertyStorage() const {return *this;}
/** //! \~english Returns if properties with name "name" exists
* \brief Check if property with \a name exists //! \~russian Возвращает присутствует ли свойство с именем "name"
* @return "true" if property exists bool isPropertyExists(const PIString & name) const;
*/
bool isPropertyExists(const PIString & _name) const;
/** //! \~english Remove all properties
* \brief Remove all properties //! \~russian Удаляет все свойства
*/
void clearProperties() {props.clear();} void clearProperties() {props.clear();}
/** //! \~english Add property if name isn't present in storage, otherwrise update existing property with same name
* \brief Add property if name isn't present in storage, otherwrise update existing property with same name. //! \~russian Добавляет новое свойство, если его имени не было в контейнере, иначе обновляет существующее свойство с этим именем
* @return "true" if new property added, else if update existing property return "false"
* @param p to copy in storage
*/
bool addProperty(const Property & p); bool addProperty(const Property & p);
bool addProperty(Property && p); bool addProperty(Property && p);
/** //! \~english Add property if name isn't present in storage, otherwrise update existing property with same name
* \brief First of all construct Property with method params. After then add property if name isn't present //! \~russian Добавляет новое свойство, если его имени не было в контейнере, иначе обновляет существующее свойство с этим именем
* in storage, otherwrise update existing property with same name.
* @return "true" if new property added, else if update existing property return "false"
*/
bool addProperty(const PIString & _name, const PIVariant & _def_value, const PIString & _comment = PIString(), int _flags = 0); bool addProperty(const PIString & _name, const PIVariant & _def_value, const PIString & _comment = PIString(), int _flags = 0);
/** //! \~english Remove property with name "name", returns if property removed
* \brief Remove property with \a name //! \~russian Удаляет свойство с именем "name", возвращает было ли оно удалено
* @return "true" if property exists and removed bool removeProperty(const PIString & name);
*/
bool removeProperty(const PIString & _name);
/** //! \~english Remove all properties with flag "flag" set, returns removed properties count
* \brief Remove properties wich has \a flag set //! \~russian Удаляет все свойства с флагом "flag", возвращает количество удаленных свойств
* @return removed properties count
*/
int removePropertiesByFlag(int flag); int removePropertiesByFlag(int flag);
/** //! \~english Merge other "properties" into this
* \brief Merge other \a properties_ into this //! \~russian Объединяет "properties" с текущим контейнером
* @param flag_ignore - properties wich has this flag set will be ignored in merge void updateProperties(const PIVector<Property> & properties, int flag_ignore = 0);
*/
void updateProperties(const PIVector<Property> & properties_, int flag_ignore = 0);
/** //! \~english Returns property with name "name" or default-constructed %PIPropertyStorage::Property
* \brief Search property by name and return it. //! \~russian Возвращает свойство с именем "name" или пустое %PIPropertyStorage::Property
*
* @param name of property
* @return property value or default constructed Property
*/
Property propertyByName(const PIString & name) const; Property propertyByName(const PIString & name) const;
/** //! \~english Returns property value with name "name" or invalid %PIVariant
* \brief Search property by name and return property value. //! \~russian Возвращает значение свойства с именем "name" или недействительный %PIVariant
*
* @param name of property
* @return property value or invalid PIVariant if name unknown
*/
PIVariant propertyValueByName(const PIString & name) const; PIVariant propertyValueByName(const PIString & name) const;
/** //! \~english Set value of property with name "name" to "value", returns if property exists
* \brief Set value of property with specific name if name is present in storage. //! \~russian Устанавливает значение "value" свойству с именем "name", возвращает существует ли такое свойство
*
* @param name of property to set value
* @param value to set
* @return "true" if property exists and updated
*/
bool setPropertyValue(const PIString & name, const PIVariant & value); bool setPropertyValue(const PIString & name, const PIVariant & value);
/** //! \~english Set comment of property with name "name" to "comment", returns if property exists
* \brief Set comment of property with specific name if name is present in storage. //! \~russian Устанавливает комментарий "comment" свойству с именем "name", возвращает существует ли такое свойство
*
* @param name of property to set comment
* @param comment to set
* @return "true" if property exists and updated
*/
bool setPropertyComment(const PIString & name, const PIString & comment); bool setPropertyComment(const PIString & name, const PIString & comment);
/** //! \~english Set flags of property with name "name" to "flags", returns if property exists
* \brief Set flags of property with specific name if name is present in storage. //! \~russian Устанавливает флаги "flags" свойству с именем "name", возвращает существует ли такое свойство
*
* @param name of property to set flags
* @param flags to set
* @return "true" if property exists and updated
*/
bool setPropertyFlags(const PIString & name, int flags); bool setPropertyFlags(const PIString & name, int flags);
//! \~english Add property "p"
//! \~russian Добавляет свойство "p"
PIPropertyStorage & operator <<(const PIPropertyStorage::Property & p) {props << p; return *this;} PIPropertyStorage & operator <<(const PIPropertyStorage::Property & p) {props << p; return *this;}
//! \~english Add properties "p"
//! \~russian Добавляет свойства "p"
PIPropertyStorage & operator <<(const PIVector<Property> & p) {props << p; return *this;} PIPropertyStorage & operator <<(const PIVector<Property> & p) {props << p; return *this;}
//! \~english Add properties "p"
//! \~russian Добавляет свойства "p"
PIPropertyStorage & operator <<(const PIPropertyStorage & p) {props << p.props; return *this;} PIPropertyStorage & operator <<(const PIPropertyStorage & p) {props << p.props; return *this;}
//! \~english Returns property with index "i"
//! \~russian Возвращает свойство по индексу "i"
Property & operator[](int i) {return props[i];} Property & operator[](int i) {return props[i];}
//! \~english Returns property with index "i" as const
//! \~russian Возвращает свойство по индексу "i" как константу
const Property & operator[](int i) const {return props[i];} const Property & operator[](int i) const {return props[i];}
//! \~english Returns property with name "name"
//! \~russian Возвращает свойство с именем "name"
Property & operator[](const PIString & name); Property & operator[](const PIString & name);
//! \~english Returns property with name "name" as const
//! \~russian Возвращает свойство с именем "name" как константу
const Property operator[](const PIString & name) const; const Property operator[](const PIString & name) const;
static Property parsePropertyLine(PIString l); static Property parsePropertyLine(PIString l);

View File

@@ -20,6 +20,52 @@
#include "pistringlist.h" #include "pistringlist.h"
//! \addtogroup Core
//! \{
//! \~\class PIStringList pistringlist.h
//! \~\brief
//! \~english Based on \a PIDeque<PIString> strings list
//! \~russian Основанный на \a PIDeque<PIString> массив строк
//!
//! \~\details
//!
//! \}
//! \details
//! \~english Example:
//! \~russian Пример:
//! \~\snippet pistring.cpp PIStringList::join
PIString PIStringList::join(const PIString & delim) const {
PIString s;
for (uint i = 0; i < size(); ++i) {
s += at(i);
if (i < size() - 1)
s += delim;
}
return s;
}
//! \details
//! \~english Example:
//! \~russian Пример:
//! \~\snippet pistring.cpp PIStringList::removeStrings
PIStringList & PIStringList::removeStrings(const PIString & value) {
for (uint i = 0; i < size(); ++i) {
if (at(i) == value) {
remove(i);
--i;
}
}
return *this;
}
//! \details
//! \~english Example:
//! \~russian Пример:
//! \~\snippet pistring.cpp PIStringList::removeDuplicates
PIStringList& PIStringList::removeDuplicates() { PIStringList& PIStringList::removeDuplicates() {
PIStringList l; PIStringList l;
PIString s; PIString s;
@@ -40,3 +86,14 @@ PIStringList& PIStringList::removeDuplicates() {
} }
return *this; return *this;
} }
//! \details
//! \~english Example:
//! \~russian Пример:
//! \~\snippet pistring.cpp PIStringList::trim
PIStringList & PIStringList::trim() {
for (uint i = 0; i < size(); ++i)
(*this)[i].trim();
return *this;
}

View File

@@ -1,6 +1,8 @@
/*! \brief Strings array class /*! \file pistringlist.h
* \details This class is based on \a PIDeque<PIString> and * \~\brief
* expand it functionality. */ * \~english Based on \a PIDeque<PIString> strings list
* \~russian Основанный на \a PIDeque<PIString> массив строк
*/
/* /*
PIP - Platform Independent Primitives PIP - Platform Independent Primitives
Strings array class Strings array class
@@ -30,80 +32,108 @@ class PIP_EXPORT PIStringList: public PIDeque<PIString>
{ {
public: public:
//! Contructs empty strings list //! \~english Contructs an empty strings list
//! \~russian Создает пустой список строк
PIStringList() {;} PIStringList() {;}
~PIStringList() {;} //! \~english Contructs strings list with one string "str"
//! \~russian Создает список строк с одной строкой "str"
//! Contructs strings list with one string "str"
PIStringList(const PIString & str) {push_back(str);} PIStringList(const PIString & str) {push_back(str);}
PIStringList(PIString && str) {push_back(std::move(str));} PIStringList(PIString && str) {push_back(std::move(str));}
//! Contructs empty strings list with strings "s0" and "s1" //! \~english Contructs strings list with strings "s0" and "s1"
//! \~russian Создает список строк со строками "s0" и "s1"
PIStringList(const PIString & s0, const PIString & s1) {push_back(s0); push_back(s1);} PIStringList(const PIString & s0, const PIString & s1) {push_back(s0); push_back(s1);}
PIStringList(PIString && s0, PIString && s1) {push_back(std::move(s0)); push_back(std::move(s1));} PIStringList(PIString && s0, PIString && s1) {push_back(std::move(s0)); push_back(std::move(s1));}
//! Contructs empty strings list with strings "s0", "s1" and "s2" //! \~english Contructs strings list with strings "s0", "s1" and "s2"
//! \~russian Создает список строк со строками "s0", "s1" и "s2"
PIStringList(const PIString & s0, const PIString & s1, const PIString & s2) {push_back(s0); push_back(s1); push_back(s2);} PIStringList(const PIString & s0, const PIString & s1, const PIString & s2) {push_back(s0); push_back(s1); push_back(s2);}
PIStringList(PIString && s0, PIString && s1, PIString && s2) {push_back(std::move(s0)); push_back(std::move(s1)); push_back(std::move(s2));} PIStringList(PIString && s0, PIString && s1, PIString && s2) {push_back(std::move(s0)); push_back(std::move(s1)); push_back(std::move(s2));}
//! Contructs empty strings list with strings "s0", "s1", "s2" and "s3" //! \~english Contructs strings list with strings "s0", "s1", "s2" and "s3"
//! \~russian Создает список строк со строками "s0", "s1", "s2" и "s3"
PIStringList(const PIString & s0, const PIString & s1, const PIString & s2, const PIString & s3) {push_back(s0); push_back(s1); push_back(s2); push_back(s3);} PIStringList(const PIString & s0, const PIString & s1, const PIString & s2, const PIString & s3) {push_back(s0); push_back(s1); push_back(s2); push_back(s3);}
PIStringList(PIString && s0, PIString && s1, PIString && s2, PIString && s3) {push_back(std::move(s0)); push_back(std::move(s1)); push_back(std::move(s2)); push_back(std::move(s3));} PIStringList(PIString && s0, PIString && s1, PIString && s2, PIString && s3) {push_back(std::move(s0)); push_back(std::move(s1)); push_back(std::move(s2)); push_back(std::move(s3));}
//! \~english Contructs strings list with strings "o"
//! \~russian Создает список строк со строками "o"
PIStringList(const PIStringList & o): PIDeque<PIString>(o) {} PIStringList(const PIStringList & o): PIDeque<PIString>(o) {}
PIStringList(PIStringList && o): PIDeque<PIString>(std::move(o)) {} PIStringList(PIStringList && o): PIDeque<PIString>(std::move(o)) {}
//! \~english Contructs strings list with strings "o"
//! \~russian Создает список строк со строками "o"
PIStringList(const PIVector<PIString> & o): PIDeque<PIString>() {resize(o.size()); for (uint i = 0; i < size(); ++i) (*this)[i] = o[i];} PIStringList(const PIVector<PIString> & o): PIDeque<PIString>() {resize(o.size()); for (uint i = 0; i < size(); ++i) (*this)[i] = o[i];}
//! \~english Contructs strings list with strings "o"
//! \~russian Создает список строк со строками "o"
PIStringList(const PIDeque<PIString> & o): PIDeque<PIString>() {resize(o.size()); for (uint i = 0; i < size(); ++i) (*this)[i] = o[i];} PIStringList(const PIDeque<PIString> & o): PIDeque<PIString>() {resize(o.size()); for (uint i = 0; i < size(); ++i) (*this)[i] = o[i];}
//! Contructs strings list with std::initializer_list //! \~english Contructs strings list with strings "init_list" in std::initializer_list format
//! \~russian Создает список строк со строками "init_list" в формате std::initializer_list
PIStringList(std::initializer_list<PIString> init_list): PIDeque<PIString>(init_list) {} PIStringList(std::initializer_list<PIString> init_list): PIDeque<PIString>(init_list) {}
//! \brief Join all strings in one with delimiter "delim" and return it //! \~english Join all strings in one with delimiter "delim" and returns it
//! \details Example: \snippet pistring.cpp PIStringList::join //! \~russian Соединяет все строки в одну через разделитель "delim" и возвращает её
PIString join(const PIString & delim) const {PIString s; for (uint i = 0; i < size(); ++i) {s += at(i); if (i < size() - 1) s += delim;} return s;} PIString join(const PIString & delim) const;
//! \brief Remove all strings equal "value" and return this //! \~english Remove all strings equal "value" and returns reference to this
//! \details Example: \snippet pistring.cpp PIStringList::removeStrings //! \~russian Удаляет все строки равные "value" и возвращает ссылку на этот список строк
PIStringList & removeStrings(const PIString & value) {for (uint i = 0; i < size(); ++i) {if (at(i) == value) {remove(i); --i;}} return *this;} PIStringList & removeStrings(const PIString & value);
PIStringList & remove(uint num) {PIDeque<PIString>::remove(num); return *this;} PIStringList & remove(uint num) {PIDeque<PIString>::remove(num); return *this;}
PIStringList & remove(uint num, uint count) {PIDeque<PIString>::remove(num, count); return *this;} PIStringList & remove(uint num, uint count) {PIDeque<PIString>::remove(num, count); return *this;}
//! \brief Remove duplicated strings and return this //! \~english Remove duplicated strings and returns reference to this
//! \details Example: \snippet pistring.cpp PIStringList::removeDuplicates //! \~russian Удаляет все дублированные строки и возвращает ссылку на этот список строк
PIStringList & removeDuplicates(); PIStringList & removeDuplicates();
//! \brief Trim all strings //! \~english Trim all strings and returns reference to this
//! \details Example: \snippet pistring.cpp PIString::trim //! \~russian Подчищает у всех строк пробельные символы в начале и в конце и возвращает ссылку на этот список строк
PIStringList & trim() {for (uint i = 0; i < size(); ++i) (*this)[i].trim(); return *this;} PIStringList & trim();
//! Return sum of lengths of all strings //! \~english Returns sum of lengths of all strings
//! \~russian Возвращает сумму длин всех строк
uint contentSize() {uint s = 0; for (uint i = 0; i < size(); ++i) s += at(i).size(); return s;} uint contentSize() {uint s = 0; for (uint i = 0; i < size(); ++i) s += at(i).size(); return s;}
//! Compare operator //! \~english Compare operator
//! \~russian Оператор сравнения
bool operator ==(const PIStringList & o) const {if (size() != o.size()) return false; for (size_t i = 0; i < size(); ++i) if (o[i] != (*this)[i]) return false; return true;} bool operator ==(const PIStringList & o) const {if (size() != o.size()) return false; for (size_t i = 0; i < size(); ++i) if (o[i] != (*this)[i]) return false; return true;}
//! Compare operator //! \~english Compare operator
//! \~russian Оператор сравнения
bool operator !=(const PIStringList & o) const {return !(o == (*this));} bool operator !=(const PIStringList & o) const {return !(o == (*this));}
//! \~english Assign operator
//! \~russian Оператор присваивания
PIStringList & operator =(const PIStringList & o) {PIDeque<PIString>::operator=(o); return *this;} PIStringList & operator =(const PIStringList & o) {PIDeque<PIString>::operator=(o); return *this;}
//! \~english Append string "str"
//! \~russian Добавляет строку "str"
PIStringList & operator <<(const PIString & str) {append(str); return *this;} PIStringList & operator <<(const PIString & str) {append(str); return *this;}
PIStringList & operator <<(PIString && str) {append(std::move(str)); return *this;} PIStringList & operator <<(PIString && str) {append(std::move(str)); return *this;}
//! \~english Append strings list "sl"
//! \~russian Добавляет список строк "sl"
PIStringList & operator <<(const PIStringList & sl) {append(sl); return *this;} PIStringList & operator <<(const PIStringList & sl) {append(sl); return *this;}
}; };
//! \relatesalso PIByteArray \brief Output operator to PIByteArray //! \relatesalso PIByteArray
//! \~english Store operator
//! \~russian Оператор сохранения
inline PIByteArray & operator <<(PIByteArray & s, const PIStringList & v) {s << int(v.size_s()); for (int i = 0; i < v.size_s(); ++i) s << v[i]; return s;} inline PIByteArray & operator <<(PIByteArray & s, const PIStringList & v) {s << int(v.size_s()); for (int i = 0; i < v.size_s(); ++i) s << v[i]; return s;}
//! relatesalso PIByteArray \brief Input operator from PIByteArray //! \relatesalso PIByteArray
//! \~english Restore operator
//! \~russian Оператор извлечения
inline PIByteArray & operator >>(PIByteArray & s, PIStringList & v) {int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;} inline PIByteArray & operator >>(PIByteArray & s, PIStringList & v) {int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;}
//! \relatesalso PICout \brief Output operator to PICout //! \relatesalso PICout
//! \~english Output operator to \a PICout
//! \~russian Оператор вывода в \a PICout
inline PICout operator <<(PICout s, const PIStringList & v) {s.space(); s.setControl(0, true); s << "{"; for (uint i = 0; i < v.size(); ++i) {s << "\"" << v[i] << "\""; if (i < v.size() - 1) s << ", ";} s << "}"; s.restoreControl(); return s;} inline PICout operator <<(PICout s, const PIStringList & v) {s.space(); s.setControl(0, true); s << "{"; for (uint i = 0; i < v.size(); ++i) {s << "\"" << v[i] << "\""; if (i < v.size() - 1) s << ", ";} s << "}"; s.restoreControl(); return s;}
#endif // PISTRINGLIST_H #endif // PISTRINGLIST_H

View File

@@ -39,31 +39,73 @@
# include <sys/time.h> # include <sys/time.h>
#endif #endif
/*! \class PISystemTime //! \addtogroup Core
* \brief System time //! \{
* //! \class PISystemTime pitime.h
* \section PISystemTime_sec0 Synopsis //! \brief
* This class provide arithmetic functions for POSIX system time. //! \~english System time with nanosecond precision
* This time represents as seconds and nanosecons in integer formats. //! \~russian Системное время с точностью до наносекунд
* You can take current system time with function \a PISystemTime::current(), //!
* compare times, sum or subtract two times, convert time to/from //! \~english \section PISystemTime_sec0 Synopsis
* seconds, milliseconds, microseconds or nanoseconds. //! \~russian \section PISystemTime_sec0 Краткий обзор
* \section PISystemTime_sec1 Example //! \~english
* \snippet pitimer.cpp system_time //! This class provide arithmetic functions for POSIX system time.
*/ //! This time represents as seconds and nanosecons in integer formats.
//! You can take current system time with function \a PISystemTime::current(),
//! compare times, sum or subtract two times, convert time to/from
//! seconds, milliseconds, microseconds or nanoseconds.
//!
//! \~russian
//! Этот класс предоставляет арифметику для системного времени в формате POSIX.
//! Это время представлено в виде целочисленных секунд и наносекунд.
//! Можно взять текущее время с помощью метода \a PISystemTime::current(),
//! сравнивать, суммировать и вычитать времена, преобразовывать в/из
//! секунд, миллисекунд, микросекунд и наносекунд.
//!
//! \~english \section PISystemTime_sec1 Example
//! \~russian \section PISystemTime_sec1 Пример
//! \~\snippet pitimer.cpp system_time
//!
//! \}
/*! \class PITimeMeasurer //! \addtogroup Core
* \brief Time measurements //! \{
* //! \class PITimeMeasurer pitime.h
* \section PITimeMeasurer_sec0 Synopsis //! \brief
* Function \a reset() set time mark to current //! \~english Time measurements
* system time, then functions double elapsed_*() returns time elapsed from this mark. //! \~russian Измерение времени
* These functions can returns nano-, micro-, milli- and seconds with suffixes "n", "u", "m" //!
* and "s" //! \~english \section PITimeMeasurer_sec0 Usage
*/ //! \~russian \section PITimeMeasurer_sec0 Использование
//! \~english
//! Function \a reset() set time mark to current
//! system time, then functions "double elapsed_*()" returns time elapsed from this mark.
//! These functions can returns nano-, micro-, milli- and seconds with suffixes "n", "u", "m"
//! and "s"
//!
//! \~russian
//! Метод \a reset() устанавливает текущую метку системного времени. Далее методы
//! "double elapsed_*()" возвращают время, прошедшее от установленной метки.
//! Эти методы возвращают нано, микро, милли и секунды с приставками
//! "n", "u", "m" и "s".
//!
//! \}
//! \details
//! \~english
//! This function consider \c "usleep" offset
//! on QNX/Linux/Mac, which is calculated with
//! \a pip_sys_test program. If this is correct
//! offset value in system config, this function
//! wait \b exactly "usecs" microseconds.
//! \~russian
//! Этот метод учитывает смещение \c "usleep"
//! на QNX/Linux/Mac, которое расчитывается с помощью
//! утилиты \a pip_sys_test. Если это значение в системном
//! конфиге действительно, то этот метод будет ожидать
//! \b точно "usecs" микросекунд.
void piUSleep(int usecs) { void piUSleep(int usecs) {
if (usecs <= 0) return; if (usecs <= 0) return;
#ifdef WINDOWS #ifdef WINDOWS

View File

@@ -1,5 +1,8 @@
/*! \file pitime.h /*! \file pitime.h
* \brief Time structs * \ingroup Core
* \~\brief
* \~english Time structs and methods
* \~russian Типы и методы времени
*/ */
/* /*
PIP - Platform Independent Primitives PIP - Platform Independent Primitives
@@ -30,23 +33,28 @@
# include <time.h> # include <time.h>
#endif #endif
/*! \brief Precise sleep for "usecs" microseconds //! \~english Precise sleep for "usecs" microseconds
* \details This function consider \c "usleep" offset //! \~russian Точно ожидает "usecs" микросекунд
* on QNX/Linux/Mac, which is calculated with
* \a pip_sys_test program. If there is correct
* offset value in system config, this function
* wait \b exactly "usecs" microseconds. */
PIP_EXPORT void piUSleep(int usecs); // on !Windows consider constant "usleep" offset PIP_EXPORT void piUSleep(int usecs); // on !Windows consider constant "usleep" offset
/*! \brief Precise sleep for "msecs" milliseconds //! ~\brief
* \details This function exec \a piUSleep (msecs * 1000). */ //! \~english Precise sleep for "msecs" milliseconds
//! \~russian Точно ожидает "msecs" миллисекунд
//! ~\details
//! \~english This function exec \a piUSleep (msecs * 1000)
//! \~russian Этот метод вызывает \a piUSleep (msecs * 1000)
inline void piMSleep(double msecs) {piUSleep(int(msecs * 1000.));} // on !Windows consider constant "usleep" offset inline void piMSleep(double msecs) {piUSleep(int(msecs * 1000.));} // on !Windows consider constant "usleep" offset
/*! \brief Precise sleep for "secs" seconds //! ~\brief
* \details This function exec \a piUSleep (msecs * 1000000). */ //! \~english Precise sleep for "secs" seconds
//! \~russian Точно ожидает "secs" секунд
//! ~\details
//! \~english This function exec \a piUSleep (msecs * 1000000)
//! \~russianЭтот метод вызывает \a piUSleep (msecs * 1000000)
inline void piSleep(double secs) {piUSleep(int(secs * 1000000.));} // on !Windows consider constant "usleep" offset inline void piSleep(double secs) {piUSleep(int(secs * 1000000.));} // on !Windows consider constant "usleep" offset
//! Shortest available on current system sleep //! \~english Shortest available on current system sleep
//! \~russian Наименее возможное для данной системы по длительности ожидание
inline void piMinSleep() {piMSleep(PIP_MIN_MSLEEP);} inline void piMinSleep() {piMSleep(PIP_MIN_MSLEEP);}