Merge pull request 'добавил const для части контейнеров и explicit для конструкторов' (#176) from const_explicit into master
Reviewed-on: https://git.shs.tools/SHS/pip/pulls/176
This commit was merged in pull request #176.
This commit is contained in:
@@ -238,7 +238,7 @@ PIAuth::State PIAuth::receive(PIByteArray & ba) {
|
||||
rinfo = crypt.decrypt(rinfo, secret_key, &ok);
|
||||
if (!ok) return disconnect(ba, "Error while exchange keys");
|
||||
state = Connected;
|
||||
connected(rinfo);
|
||||
connected(PIString::fromUTF8(rinfo));
|
||||
ba << (int)state << crypt.generateRandomBuff(randomi() % PIAUTH_NOISE_MAX_SIZE);
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ const size_t minAlloc = 64;
|
||||
|
||||
|
||||
size_t _PIContainerConstantsBase::calcMinCountPoT(size_t szof) {
|
||||
size_t ret = 0, elc = 1;
|
||||
size_t ret = 0;
|
||||
size_t elc = 1;
|
||||
while (elc * szof < minAlloc) {
|
||||
elc *= 2;
|
||||
++ret;
|
||||
|
||||
@@ -73,7 +73,7 @@ template<typename T>
|
||||
class _PIContainerConstants {
|
||||
public:
|
||||
static size_t minCountPoT() {
|
||||
static size_t ret = _PIContainerConstantsBase::calcMinCountPoT(sizeof(T));
|
||||
static const size_t ret = _PIContainerConstantsBase::calcMinCountPoT(sizeof(T));
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -75,9 +75,9 @@
|
||||
//! if the number of elements is known beforehand.
|
||||
//!
|
||||
//! The complexity (efficiency) of common operations on PIDeque is as follows:
|
||||
//! - Random access - constant 𝓞(1)
|
||||
//! - Insertion or removal of elements at the end or begin - amortized constant 𝓞(1)
|
||||
//! - Insertion or removal of elements - linear in the distance to the end of the array 𝓞(n)
|
||||
//! - Random access - constant O(1)
|
||||
//! - Insertion or removal of elements at the end or begin - amortized constant O(1)
|
||||
//! - Insertion or removal of elements - linear in the distance to the end of the array O(n)
|
||||
//!
|
||||
//! \~russian
|
||||
//! Элементы хранятся непрерывно, а значит доступны не только через итераторы,
|
||||
@@ -109,9 +109,9 @@
|
||||
//! если количество элементов известно заранее.
|
||||
//!
|
||||
//! Сложность (эффективность) обычных операций над PIDeque следующая:
|
||||
//! - Произвольный доступ — постоянная 𝓞(1)
|
||||
//! - Вставка и удаление элементов в конце или начале — амортизированная постоянная 𝓞(1)
|
||||
//! - Вставка и удаление элементов — линейная по расстоянию до конца массива 𝓞(n)
|
||||
//! - Произвольный доступ — постоянная O(1)
|
||||
//! - Вставка и удаление элементов в конце или начале — амортизированная постоянная O(1)
|
||||
//! - Вставка и удаление элементов — линейная по расстоянию до конца массива O(n)
|
||||
//!
|
||||
//! \~\sa \a PIVector, \a PIMap
|
||||
template<typename T>
|
||||
@@ -164,7 +164,7 @@ public:
|
||||
|
||||
//! \~english Contructs array with size `size` filled elements `e`.
|
||||
//! \~russian Создает массив из `size` элементов заполненных `e`.
|
||||
inline PIDeque(size_t pid_size, const T & e = T()) {
|
||||
inline explicit PIDeque(size_t pid_size, const T & e = T()) {
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
expand(pid_size, e);
|
||||
}
|
||||
@@ -249,7 +249,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline iterator operator++(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -258,7 +258,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline iterator operator--(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -328,7 +328,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline const_iterator operator++(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -337,7 +337,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline const_iterator operator--(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -409,7 +409,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline reverse_iterator operator++(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -418,7 +418,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline reverse_iterator operator--(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -487,7 +487,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline const_reverse_iterator operator++(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -496,7 +496,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline const_reverse_iterator operator--(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -729,7 +729,7 @@ public:
|
||||
//! заданному в передаваемой функции `test`, или `def` если такого элемента нет.
|
||||
//! \~\sa \a indexWhere()
|
||||
inline const T & atWhere(std::function<bool(const T & e)> test, ssize_t start = 0, const T & def = T()) const {
|
||||
ssize_t i = indexWhere(test, start);
|
||||
const ssize_t i = indexWhere(test, start);
|
||||
if (i < 0)
|
||||
return def;
|
||||
else
|
||||
@@ -743,7 +743,7 @@ public:
|
||||
//! заданному в передаваемой функции `test`, или `def` если такого элемента нет.
|
||||
//! \~\sa \a lastIndexWhere()
|
||||
inline const T & lastAtWhere(std::function<bool(const T & e)> test, ssize_t start = -1, const T & def = T()) const {
|
||||
ssize_t i = lastIndexWhere(test, start);
|
||||
const ssize_t i = lastIndexWhere(test, start);
|
||||
if (i < 0)
|
||||
return def;
|
||||
else
|
||||
@@ -1302,7 +1302,7 @@ public:
|
||||
//! \~\sa \a size(), \a capacity(), \a resize()
|
||||
inline PIDeque<T> & reserve(size_t new_size) {
|
||||
if (new_size <= pid_rsize) return *this;
|
||||
size_t os = pid_size;
|
||||
const size_t os = pid_size;
|
||||
alloc_forward(new_size);
|
||||
pid_size = os;
|
||||
return *this;
|
||||
@@ -1322,17 +1322,21 @@ public:
|
||||
inline PIDeque<T> & insert(size_t index, const T & e = T()) {
|
||||
if (index == pid_size) return push_back(e);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
||||
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
||||
const bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
||||
if (dir) {
|
||||
alloc_forward(pid_size + 1);
|
||||
if (index < pid_size - 1) {
|
||||
size_t os = pid_size - index - 1;
|
||||
memmove((void *)(pid_data + pid_start + index + 1), (const void *)(pid_data + pid_start + index), os * sizeof(T));
|
||||
const size_t os = pid_size - index - 1;
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index + 1),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + 1, -1);
|
||||
if (index > 0) {
|
||||
memmove((void *)(pid_data + pid_start), (const void *)(pid_data + pid_start + 1), index * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + 1),
|
||||
index * sizeof(T));
|
||||
}
|
||||
}
|
||||
elementNew(pid_data + pid_start + index, e);
|
||||
@@ -1348,17 +1352,21 @@ public:
|
||||
inline PIDeque<T> & insert(size_t index, T && e) {
|
||||
if (index == pid_size) return push_back(e);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
||||
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
||||
const bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
||||
if (dir) {
|
||||
alloc_forward(pid_size + 1);
|
||||
if (index < pid_size - 1) {
|
||||
size_t os = pid_size - index - 1;
|
||||
memmove((void *)(pid_data + pid_start + index + 1), (const void *)(pid_data + pid_start + index), os * sizeof(T));
|
||||
const size_t os = pid_size - index - 1;
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index + 1),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + 1, -1);
|
||||
if (index > 0) {
|
||||
memmove((void *)(pid_data + pid_start), (const void *)(pid_data + pid_start + 1), index * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + 1),
|
||||
index * sizeof(T));
|
||||
}
|
||||
}
|
||||
elementNew(pid_data + pid_start + index, std::move(e));
|
||||
@@ -1379,17 +1387,21 @@ public:
|
||||
}
|
||||
#endif
|
||||
assert(&v != this);
|
||||
bool dir = v.size() > pid_size ? true : (index >= pid_rsize / 2 ? true : false);
|
||||
const bool dir = v.size() > pid_size ? true : (index >= pid_rsize / 2 ? true : false);
|
||||
if (dir) {
|
||||
ssize_t os = pid_size - index;
|
||||
const ssize_t os = pid_size - index;
|
||||
alloc_forward(pid_size + v.pid_size);
|
||||
if (os > 0) {
|
||||
memmove((void *)(pid_data + pid_start + index + v.pid_size), (const void *)(pid_data + pid_start + index), os * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index + v.pid_size),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + v.pid_size, -v.pid_size);
|
||||
if (index > 0) {
|
||||
memmove((void *)(pid_data + pid_start), (const void *)(pid_data + pid_start + v.pid_size), index * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + v.pid_size),
|
||||
index * sizeof(T));
|
||||
}
|
||||
}
|
||||
newT(pid_data + pid_start + index, v.pid_data + v.pid_start, v.pid_size);
|
||||
@@ -1408,19 +1420,21 @@ public:
|
||||
//! \~\sa \a append(), \a prepend(), \a remove()
|
||||
inline PIDeque<T> & insert(size_t index, std::initializer_list<T> init_list) {
|
||||
if (init_list.size() == 0) return *this;
|
||||
bool dir = init_list.size() > pid_size ? true : (index >= pid_rsize / 2 ? true : false);
|
||||
const bool dir = init_list.size() > pid_size ? true : (index >= pid_rsize / 2 ? true : false);
|
||||
if (dir) {
|
||||
ssize_t os = ssize_t(pid_size) - index;
|
||||
const ssize_t os = ssize_t(pid_size) - index;
|
||||
alloc_forward(pid_size + init_list.size());
|
||||
if (os > 0) {
|
||||
memmove((void *)(pid_data + pid_start + index + init_list.size()),
|
||||
(const void *)(pid_data + pid_start + index),
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index + init_list.size()),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + init_list.size(), -init_list.size());
|
||||
if (index > 0) {
|
||||
memmove((void *)(pid_data + pid_start), (const void *)(pid_data + pid_start + init_list.size()), index * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + init_list.size()),
|
||||
index * sizeof(T));
|
||||
}
|
||||
}
|
||||
newT(pid_data + pid_start + index, init_list.begin(), init_list.size());
|
||||
@@ -1444,13 +1458,17 @@ public:
|
||||
pid_size = index;
|
||||
}
|
||||
} else {
|
||||
size_t os = pid_size - index - count;
|
||||
const size_t os = pid_size - index - count;
|
||||
deleteT(pid_data + pid_start + index, count);
|
||||
if (os <= index) {
|
||||
memmove((void *)(pid_data + pid_start + index), (const void *)(pid_data + pid_start + index + count), os * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index + count),
|
||||
os * sizeof(T));
|
||||
} else {
|
||||
if (index > 0) {
|
||||
memmove((void *)(pid_data + pid_start + count), (const void *)(pid_data + pid_start), index * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + count),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
index * sizeof(T));
|
||||
}
|
||||
pid_start += count;
|
||||
}
|
||||
@@ -1544,7 +1562,7 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a reversed()
|
||||
inline PIDeque<T> & reverse() {
|
||||
size_t s2 = pid_size / 2;
|
||||
const size_t s2 = pid_size / 2;
|
||||
for (size_t i = 0; i < s2; ++i) {
|
||||
piSwap<T>(pid_data[pid_start + i], pid_data[pid_start + pid_size - i - 1]);
|
||||
}
|
||||
@@ -1575,7 +1593,7 @@ public:
|
||||
//! Если `add_size < 0` и в массиве меньше элементов чем указано, то массив становится пустым.
|
||||
//! \~\sa \a resize()
|
||||
inline PIDeque<T> & enlarge(ssize_t add_size, const T & e = T()) {
|
||||
ssize_t ns = size_s() + add_size;
|
||||
const ssize_t ns = size_s() + add_size;
|
||||
if (ns <= 0)
|
||||
clear();
|
||||
else
|
||||
@@ -1698,7 +1716,7 @@ public:
|
||||
//! \~\sa \a push_back()
|
||||
inline PIDeque<T> & push_back(std::initializer_list<T> init_list) {
|
||||
if (init_list.size() == 0) return *this;
|
||||
size_t ps = pid_size;
|
||||
const size_t ps = pid_size;
|
||||
alloc_forward(pid_size + init_list.size());
|
||||
newT(pid_data + pid_start + ps, init_list.begin(), init_list.size());
|
||||
return *this;
|
||||
@@ -1718,7 +1736,7 @@ public:
|
||||
}
|
||||
#endif
|
||||
assert(&v != this);
|
||||
size_t ps = pid_size;
|
||||
const size_t ps = pid_size;
|
||||
alloc_forward(pid_size + v.pid_size);
|
||||
newT(pid_data + ps + pid_start, v.pid_data + v.pid_start, v.pid_size);
|
||||
return *this;
|
||||
@@ -1997,7 +2015,7 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a take_front(), \a pop_back(), \a pop_front()
|
||||
inline T take_back() {
|
||||
T e(back());
|
||||
const T e(back());
|
||||
pop_back();
|
||||
return e;
|
||||
}
|
||||
@@ -2012,7 +2030,7 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a take_front(), \a pop_back(), \a pop_front()
|
||||
inline T take_front() {
|
||||
T e(front());
|
||||
const T e(front());
|
||||
pop_front();
|
||||
return e;
|
||||
}
|
||||
@@ -2415,8 +2433,8 @@ public:
|
||||
inline PIDeque<C> flatten(ReshapeOrder order = ReshapeByRow) const {
|
||||
PIDeque<C> ret;
|
||||
if (isEmpty()) return ret;
|
||||
size_t rows = size();
|
||||
size_t cols = at(0).size();
|
||||
const size_t rows = size();
|
||||
const size_t cols = at(0).size();
|
||||
ret.reserve(rows * cols);
|
||||
if (order == ReshapeByRow) {
|
||||
for (size_t r = 0; r < rows; r++) {
|
||||
@@ -2487,11 +2505,11 @@ public:
|
||||
inline PIDeque<PIDeque<T>> splitBySize(size_t sz) const {
|
||||
PIDeque<PIDeque<T>> ret;
|
||||
if (isEmpty() || sz == 0) return ret;
|
||||
size_t ch = pid_size / sz;
|
||||
const size_t ch = pid_size / sz;
|
||||
for (size_t i = 0; i < ch; ++i) {
|
||||
ret << PIDeque<T>(pid_data + pid_start + sz * i, sz);
|
||||
}
|
||||
size_t t = ch * sz;
|
||||
const size_t t = ch * sz;
|
||||
if (t < pid_size) {
|
||||
ret << PIDeque<T>(pid_data + pid_start + t, pid_size - t);
|
||||
}
|
||||
@@ -2520,16 +2538,22 @@ public:
|
||||
if (index >= pid_size || count == 0) return ret;
|
||||
if (index + count > pid_size) count = pid_size - index;
|
||||
ret.alloc_forward(count);
|
||||
memcpy((void *)(ret.pid_data + ret.pid_start), (const void *)(pid_data + pid_start + index), count * sizeof(T));
|
||||
memcpy(reinterpret_cast<void *>(ret.pid_data + ret.pid_start),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
count * sizeof(T));
|
||||
|
||||
size_t os = pid_size - index - count;
|
||||
const size_t os = pid_size - index - count;
|
||||
if (os <= index) {
|
||||
if (os > 0) {
|
||||
memmove((void *)(pid_data + pid_start + index), (const void *)(pid_data + pid_start + index + count), os * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index + count),
|
||||
os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
if (index > 0) {
|
||||
memmove((void *)(pid_data + pid_start + count), (const void *)(pid_data + pid_start), index * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + count),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
index * sizeof(T));
|
||||
}
|
||||
pid_start += count;
|
||||
}
|
||||
@@ -2551,9 +2575,10 @@ private:
|
||||
return pid_rsize * 2;
|
||||
}
|
||||
size_t t = _PIContainerConstants<T>::minCountPoT();
|
||||
size_t s_ = s - 1;
|
||||
while (s_ >> t)
|
||||
s -= 1;
|
||||
while (s >> t) {
|
||||
++t;
|
||||
}
|
||||
return (1 << t);
|
||||
}
|
||||
|
||||
@@ -2568,7 +2593,7 @@ private:
|
||||
template<typename T1 = T, typename std::enable_if<std::is_trivially_copyable<T1>::value, int>::type = 0>
|
||||
inline void newT(T * dst, const T * src, size_t s) {
|
||||
PIINTROSPECTION_CONTAINER_USED(T, s)
|
||||
memcpy((void *)(dst), (const void *)(src), s * sizeof(T));
|
||||
memcpy(reinterpret_cast<void *>(dst), reinterpret_cast<const void *>(src), s * sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T1 = T, typename std::enable_if<!std::is_trivially_copyable<T1>::value, int>::type = 0>
|
||||
@@ -2616,7 +2641,7 @@ private:
|
||||
|
||||
inline void dealloc() {
|
||||
if (pid_data != nullptr) {
|
||||
free((void *)pid_data);
|
||||
free(reinterpret_cast<void *>(pid_data));
|
||||
pid_data = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -2627,15 +2652,19 @@ private:
|
||||
if (pid_start < (pid_size * 2) || ssize_t(pid_start) > (ssize_t(pid_rsize) - (ssize_t(pid_size) * 2))) {
|
||||
size_t ns = (pid_rsize - pid_size) / 2;
|
||||
if (pid_start != ns) {
|
||||
memmove((void *)(pid_data + ns), (const void *)(pid_data + pid_start), pid_size * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(pid_data + ns),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
pid_size * sizeof(T));
|
||||
pid_start = ns;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
size_t ns = (pid_rsize - pid_size) / 2;
|
||||
const size_t ns = (pid_rsize - pid_size) / 2;
|
||||
if (pid_start != ns) {
|
||||
memmove((void *)(pid_data + ns), (const void *)(pid_data + pid_start), pid_size * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(pid_data + ns),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
pid_size * sizeof(T));
|
||||
pid_start = ns;
|
||||
}
|
||||
}
|
||||
@@ -2648,10 +2677,10 @@ private:
|
||||
return;
|
||||
}
|
||||
pid_size = new_size;
|
||||
size_t as = asize(pid_start + new_size);
|
||||
const size_t as = asize(pid_start + new_size);
|
||||
if (as != pid_rsize) {
|
||||
PIINTROSPECTION_CONTAINER_ALLOC(T, (as - pid_rsize))
|
||||
T * p_d = (T *)(realloc((void *)(pid_data), as * sizeof(T)));
|
||||
T * p_d = reinterpret_cast<T *>(realloc(reinterpret_cast<void *>(pid_data), as * sizeof(T)));
|
||||
#ifndef NDEBUG
|
||||
if (!p_d) {
|
||||
printf("error with PIDeque<%s>::alloc\n", __PIP_TYPENAME__(T));
|
||||
@@ -2664,18 +2693,13 @@ private:
|
||||
}
|
||||
|
||||
inline void alloc_backward(size_t new_size, ssize_t start_offset = 0) {
|
||||
size_t as;
|
||||
if (ssize_t(pid_start) + start_offset < 0) {
|
||||
as = asize(pid_rsize - start_offset);
|
||||
} else {
|
||||
as = pid_rsize;
|
||||
}
|
||||
const size_t as = ssize_t(pid_start) + start_offset < 0 ? asize(pid_rsize - start_offset) : pid_rsize;
|
||||
if (as > pid_rsize) {
|
||||
T * td = (T *)(malloc(as * sizeof(T)));
|
||||
size_t ns = pid_start + as - pid_rsize;
|
||||
T * td = reinterpret_cast<T *>(malloc(as * sizeof(T)));
|
||||
const size_t ns = pid_start + as - pid_rsize;
|
||||
PIINTROSPECTION_CONTAINER_ALLOC(T, (as - pid_rsize))
|
||||
if (pid_rsize > 0 && pid_data != 0) {
|
||||
memcpy((void *)(td + ns), (const void *)(pid_data + pid_start), pid_size * sizeof(T));
|
||||
memcpy(reinterpret_cast<void *>(td + ns), reinterpret_cast<const void *>(pid_data + pid_start), pid_size * sizeof(T));
|
||||
dealloc();
|
||||
}
|
||||
pid_data = td;
|
||||
@@ -2688,7 +2712,7 @@ private:
|
||||
}
|
||||
|
||||
inline void expand(size_t new_size, const T & e = T()) {
|
||||
size_t os = pid_size;
|
||||
const size_t os = pid_size;
|
||||
alloc_forward(new_size);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size - os))
|
||||
for (size_t i = os + pid_start; i < new_size + pid_start; ++i) {
|
||||
@@ -2697,7 +2721,7 @@ private:
|
||||
}
|
||||
|
||||
inline void expand(size_t new_size, std::function<T(size_t i)> f) {
|
||||
size_t os = pid_size;
|
||||
const size_t os = pid_size;
|
||||
alloc_forward(new_size);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size - os))
|
||||
for (size_t i = os + pid_start; i < new_size + pid_start; ++i) {
|
||||
|
||||
@@ -318,7 +318,7 @@ public:
|
||||
//! \~\sa \a insert(), \a value(), \a key()
|
||||
inline T & operator[](const Key & key) {
|
||||
bool f(false);
|
||||
ssize_t i = _find(key, f);
|
||||
const ssize_t i = _find(key, f);
|
||||
if (f) return pim_content[pim_index[i].index];
|
||||
pim_content.push_back(T());
|
||||
pim_index.insert(i, MapIndex(key, pim_content.size() - 1));
|
||||
@@ -334,7 +334,7 @@ public:
|
||||
//! \~russian Удаляет элемент с ключом `key` из массива и возвращает его.
|
||||
inline T take(const Key & key, const T & default_ = T()) {
|
||||
bool f(false);
|
||||
ssize_t i = _find(key, f);
|
||||
const ssize_t i = _find(key, f);
|
||||
if (!f) return default_;
|
||||
T ret(pim_content[pim_index[i].index]);
|
||||
_remove(i);
|
||||
@@ -398,7 +398,7 @@ public:
|
||||
//! \~russian Удаляет элемент с ключом `key` из массива.
|
||||
inline PIMap<Key, T> & remove(const Key & key) {
|
||||
bool f(false);
|
||||
ssize_t i = _find(key, f);
|
||||
const ssize_t i = _find(key, f);
|
||||
if (f) _remove(i);
|
||||
return *this;
|
||||
}
|
||||
@@ -452,7 +452,7 @@ public:
|
||||
//! \~russian Если элемент с ключом `key` уже существует, то он будет перезаписан на значение `value`.
|
||||
inline PIMap<Key, T> & insert(const Key & key, const T & value) {
|
||||
bool f(false);
|
||||
ssize_t i = _find(key, f);
|
||||
const ssize_t i = _find(key, f);
|
||||
if (f) {
|
||||
pim_content[pim_index[i].index] = value;
|
||||
} else {
|
||||
@@ -464,7 +464,7 @@ public:
|
||||
|
||||
inline PIMap<Key, T> & insert(const Key & key, T && value) {
|
||||
bool f(false);
|
||||
ssize_t i = _find(key, f);
|
||||
const ssize_t i = _find(key, f);
|
||||
if (f) {
|
||||
pim_content[pim_index[i].index] = std::move(value);
|
||||
} else {
|
||||
@@ -481,7 +481,7 @@ public:
|
||||
//! \~russian Первый элемент пары является ключом, а второй значением.
|
||||
inline PIMap<Key, T> & insert(const PIPair<Key, T> & pair) {
|
||||
bool f(false);
|
||||
ssize_t i = _find(pair.first, f);
|
||||
const ssize_t i = _find(pair.first, f);
|
||||
if (f) {
|
||||
pim_content[pim_index[i].index] = pair.second;
|
||||
} else {
|
||||
@@ -494,7 +494,7 @@ public:
|
||||
inline PIMap<Key, T> & insert(PIPair<Key, T> && pair) {
|
||||
bool f(false);
|
||||
Key k(std::move(pair.first));
|
||||
ssize_t i = _find(k, f);
|
||||
const ssize_t i = _find(k, f);
|
||||
if (f) {
|
||||
pim_content[pim_index[i].index] = std::move(pair.second);
|
||||
} else {
|
||||
@@ -510,7 +510,7 @@ public:
|
||||
//! или `default_` если такого элемента нет.
|
||||
inline T value(const Key & key, const T & default_ = T()) const {
|
||||
bool f(false);
|
||||
ssize_t i = _find(key, f);
|
||||
const ssize_t i = _find(key, f);
|
||||
if (!f) return default_;
|
||||
return pim_content[pim_index[i].index];
|
||||
}
|
||||
@@ -611,7 +611,7 @@ private:
|
||||
friend PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
|
||||
|
||||
inline ssize_t _binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const {
|
||||
ssize_t mid;
|
||||
ssize_t mid = 0;
|
||||
while (first <= last) {
|
||||
mid = (first + last) / 2;
|
||||
if (key > pim_index[mid].key)
|
||||
@@ -636,7 +636,7 @@ private:
|
||||
}
|
||||
|
||||
inline void _remove(ssize_t index) {
|
||||
size_t ci = pim_index[index].index, bi = pim_index.size() - 1;
|
||||
const size_t ci = pim_index[index].index, bi = pim_index.size() - 1;
|
||||
pim_index.remove(index);
|
||||
for (size_t i = 0; i < pim_index.size(); ++i) {
|
||||
if (pim_index[i].index == bi) {
|
||||
|
||||
@@ -54,11 +54,18 @@ public:
|
||||
|
||||
//! \~english Constructs PIPair from [std::tuple](https://en.cppreference.com/w/cpp/utility/tuple).
|
||||
//! \~russian Создает PIPair из [std::tuple](https://ru.cppreference.com/w/cpp/utility/tuple).
|
||||
PIPair(std::tuple<Type0, Type1> tuple) {
|
||||
explicit PIPair(std::tuple<Type0, Type1> tuple) {
|
||||
first = std::get<0>(tuple);
|
||||
second = std::get<1>(tuple);
|
||||
}
|
||||
|
||||
//! \~english Constructs PIPair from [std::pair](https://en.cppreference.com/w/cpp/utility/pair).
|
||||
//! \~russian Создает PIPair из [std::pair](https://ru.cppreference.com/w/cpp/utility/pair).
|
||||
explicit PIPair(std::pair<Type0, Type1> pair) {
|
||||
first = pair.first;
|
||||
second = pair.second;
|
||||
}
|
||||
|
||||
//! \~english Constructs PIPair from values `value0` and `value1`.
|
||||
//! \~russian Создает PIPair из `value0` и `value1`.
|
||||
PIPair(const Type0 & value0, const Type1 & value1) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
PISet() {}
|
||||
|
||||
//! Contructs set with one element "value"
|
||||
PISet(const T & value) { _CSet::insert(value, 0); }
|
||||
explicit PISet(const T & value) { _CSet::insert(value, 0); }
|
||||
|
||||
//! Contructs set with elements "v0" and "v1"
|
||||
PISet(const T & v0, const T & v1) {
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
}
|
||||
|
||||
//! Contructs set from vector of elements
|
||||
PISet(const PIVector<T> & values) {
|
||||
explicit PISet(const PIVector<T> & values) {
|
||||
if (values.isEmpty()) return;
|
||||
for (int i = 0; i < values.size_s(); ++i) {
|
||||
_CSet::insert(values[i], 0);
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
}
|
||||
|
||||
//! Contructs set from deque of elements
|
||||
PISet(const PIDeque<T> & values) {
|
||||
explicit PISet(const PIDeque<T> & values) {
|
||||
if (values.isEmpty()) return;
|
||||
for (int i = 0; i < values.size_s(); ++i) {
|
||||
_CSet::insert(values[i], 0);
|
||||
|
||||
@@ -74,9 +74,9 @@
|
||||
//! if the number of elements is known beforehand.
|
||||
//!
|
||||
//! The complexity (efficiency) of common operations on PIVector is as follows:
|
||||
//! - Random access - constant 𝓞(1)
|
||||
//! - Insertion or removal of elements at the end - amortized constant 𝓞(1)
|
||||
//! - Insertion or removal of elements - linear in the distance to the end of the array 𝓞(n)
|
||||
//! - Random access - constant O(1)
|
||||
//! - Insertion or removal of elements at the end - amortized constant O(1)
|
||||
//! - Insertion or removal of elements - linear in the distance to the end of the array O(n)
|
||||
//!
|
||||
//! \~russian
|
||||
//! Элементы хранятся непрерывно, а значит доступны не только через итераторы,
|
||||
@@ -109,9 +109,9 @@
|
||||
//! если количество элементов известно заранее.
|
||||
//!
|
||||
//! Сложность (эффективность) обычных операций над PIVector следующая:
|
||||
//! - Произвольный доступ — постоянная 𝓞(1)
|
||||
//! - Вставка и удаление элементов в конце — амортизированная постоянная 𝓞(1)
|
||||
//! - Вставка и удаление элементов — линейная по расстоянию до конца массива 𝓞(n)
|
||||
//! - Произвольный доступ — постоянная O(1)
|
||||
//! - Вставка и удаление элементов в конце — амортизированная постоянная O(1)
|
||||
//! - Вставка и удаление элементов — линейная по расстоянию до конца массива O(n)
|
||||
//!
|
||||
//! \~\sa \a PIDeque, \a PIMap
|
||||
template<typename T>
|
||||
@@ -164,7 +164,7 @@ public:
|
||||
|
||||
//! \~english Contructs array with size `size` filled elements `e`.
|
||||
//! \~russian Создает массив из `size` элементов заполненных `e`.
|
||||
inline PIVector(size_t size, const T & e = T()) {
|
||||
inline explicit PIVector(size_t size, const T & e = T()) {
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
expand(size, e);
|
||||
}
|
||||
@@ -248,7 +248,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline iterator operator++(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -257,7 +257,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline iterator operator--(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -327,7 +327,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline const_iterator operator++(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -336,7 +336,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline const_iterator operator--(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -408,7 +408,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline reverse_iterator operator++(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -417,7 +417,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline reverse_iterator operator--(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -486,7 +486,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline const_reverse_iterator operator++(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -495,7 +495,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
inline const_reverse_iterator operator--(int) {
|
||||
auto tmp = *this;
|
||||
const auto tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
@@ -725,7 +725,7 @@ public:
|
||||
//! заданному в передаваемой функции `test`, или `def` если такого элемента нет.
|
||||
//! \~\sa \a indexWhere()
|
||||
inline const T & atWhere(std::function<bool(const T & e)> test, ssize_t start = 0, const T & def = T()) const {
|
||||
ssize_t i = indexWhere(test, start);
|
||||
const ssize_t i = indexWhere(test, start);
|
||||
if (i < 0)
|
||||
return def;
|
||||
else
|
||||
@@ -739,7 +739,7 @@ public:
|
||||
//! заданному в передаваемой функции `test`, или `def` если такого элемента нет.
|
||||
//! \~\sa \a lastIndexWhere()
|
||||
inline const T & lastAtWhere(std::function<bool(const T & e)> test, ssize_t start = -1, const T & def = T()) const {
|
||||
ssize_t i = lastIndexWhere(test, start);
|
||||
const ssize_t i = lastIndexWhere(test, start);
|
||||
if (i < 0)
|
||||
return def;
|
||||
else
|
||||
@@ -1286,7 +1286,7 @@ public:
|
||||
//! \~\sa \a size(), \a capacity(), \a resize()
|
||||
inline PIVector<T> & reserve(size_t new_size) {
|
||||
if (new_size <= piv_rsize) return *this;
|
||||
size_t os = piv_size;
|
||||
const size_t os = piv_size;
|
||||
alloc(new_size);
|
||||
piv_size = os;
|
||||
return *this;
|
||||
@@ -1306,8 +1306,8 @@ public:
|
||||
inline PIVector<T> & insert(size_t index, const T & e = T()) {
|
||||
alloc(piv_size + 1);
|
||||
if (index < piv_size - 1) {
|
||||
size_t os = piv_size - index - 1;
|
||||
memmove((void *)(piv_data + index + 1), (const void *)(piv_data + index), os * sizeof(T));
|
||||
const size_t os = piv_size - index - 1;
|
||||
memmove(reinterpret_cast<void *>(piv_data + index + 1), reinterpret_cast<const void *>(piv_data + index), os * sizeof(T));
|
||||
}
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
||||
elementNew(piv_data + index, e);
|
||||
@@ -1323,8 +1323,8 @@ public:
|
||||
inline PIVector<T> & insert(size_t index, T && e) {
|
||||
alloc(piv_size + 1);
|
||||
if (index < piv_size - 1) {
|
||||
size_t os = piv_size - index - 1;
|
||||
memmove((void *)(piv_data + index + 1), (const void *)(piv_data + index), os * sizeof(T));
|
||||
const size_t os = piv_size - index - 1;
|
||||
memmove(reinterpret_cast<void *>(piv_data + index + 1), reinterpret_cast<const void *>(piv_data + index), os * sizeof(T));
|
||||
}
|
||||
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
||||
elementNew(piv_data + index, std::move(e));
|
||||
@@ -1345,10 +1345,12 @@ public:
|
||||
}
|
||||
#endif
|
||||
assert(&v != this);
|
||||
ssize_t os = piv_size - index;
|
||||
const ssize_t os = piv_size - index;
|
||||
alloc(piv_size + v.piv_size);
|
||||
if (os > 0) {
|
||||
memmove((void *)(piv_data + index + v.piv_size), (const void *)(piv_data + index), os * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(piv_data + index + v.piv_size),
|
||||
reinterpret_cast<const void *>(piv_data + index),
|
||||
os * sizeof(T));
|
||||
}
|
||||
newT(piv_data + index, v.piv_data, v.piv_size);
|
||||
return *this;
|
||||
@@ -1366,10 +1368,12 @@ public:
|
||||
//! \~\sa \a append(), \a prepend(), \a remove()
|
||||
inline PIVector<T> & insert(size_t index, std::initializer_list<T> init_list) {
|
||||
if (init_list.size() == 0) return *this;
|
||||
ssize_t os = piv_size - index;
|
||||
const ssize_t os = piv_size - index;
|
||||
alloc(piv_size + init_list.size());
|
||||
if (os > 0) {
|
||||
memmove((void *)(piv_data + index + init_list.size()), (const void *)(piv_data + index), os * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(piv_data + index + init_list.size()),
|
||||
reinterpret_cast<const void *>(piv_data + index),
|
||||
os * sizeof(T));
|
||||
}
|
||||
newT(piv_data + index, init_list.begin(), init_list.size());
|
||||
return *this;
|
||||
@@ -1392,9 +1396,9 @@ public:
|
||||
piv_size = index;
|
||||
}
|
||||
} else {
|
||||
size_t os = piv_size - index - count;
|
||||
const size_t os = piv_size - index - count;
|
||||
deleteT(piv_data + index, count);
|
||||
memmove((void *)(piv_data + index), (const void *)(piv_data + index + count), os * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(piv_data + index), reinterpret_cast<const void *>(piv_data + index + count), os * sizeof(T));
|
||||
piv_size -= count;
|
||||
}
|
||||
return *this;
|
||||
@@ -1483,7 +1487,7 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a reversed()
|
||||
inline PIVector<T> & reverse() {
|
||||
size_t s2 = piv_size / 2;
|
||||
const size_t s2 = piv_size / 2;
|
||||
for (size_t i = 0; i < s2; ++i) {
|
||||
piSwap<T>(piv_data[i], piv_data[piv_size - i - 1]);
|
||||
}
|
||||
@@ -1514,7 +1518,7 @@ public:
|
||||
//! Если `add_size < 0` и в массиве меньше элементов чем указано, то массив становится пустым.
|
||||
//! \~\sa \a resize()
|
||||
inline PIVector<T> & enlarge(ssize_t add_size, const T & e = T()) {
|
||||
ssize_t ns = size_s() + add_size;
|
||||
const ssize_t ns = size_s() + add_size;
|
||||
if (ns <= 0)
|
||||
clear();
|
||||
else
|
||||
@@ -1637,7 +1641,7 @@ public:
|
||||
//! \~\sa \a push_back()
|
||||
inline PIVector<T> & push_back(std::initializer_list<T> init_list) {
|
||||
if (init_list.size() == 0) return *this;
|
||||
size_t ps = piv_size;
|
||||
const size_t ps = piv_size;
|
||||
alloc(piv_size + init_list.size());
|
||||
newT(piv_data + ps, init_list.begin(), init_list.size());
|
||||
return *this;
|
||||
@@ -1657,7 +1661,7 @@ public:
|
||||
}
|
||||
#endif
|
||||
assert(&v != this);
|
||||
size_t ps = piv_size;
|
||||
const size_t ps = piv_size;
|
||||
alloc(piv_size + v.piv_size);
|
||||
newT(piv_data + ps, v.piv_data, v.piv_size);
|
||||
return *this;
|
||||
@@ -1909,7 +1913,7 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a take_front(), \a pop_back(), \a pop_front()
|
||||
inline T take_back() {
|
||||
T e(back());
|
||||
const T e(back());
|
||||
pop_back();
|
||||
return e;
|
||||
}
|
||||
@@ -1924,7 +1928,7 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a take_front(), \a pop_back(), \a pop_front()
|
||||
inline T take_front() {
|
||||
T e(front());
|
||||
const T e(front());
|
||||
pop_front();
|
||||
return e;
|
||||
}
|
||||
@@ -2327,8 +2331,8 @@ public:
|
||||
inline PIVector<C> flatten(ReshapeOrder order = ReshapeByRow) const {
|
||||
PIVector<C> ret;
|
||||
if (isEmpty()) return ret;
|
||||
size_t rows = size();
|
||||
size_t cols = at(0).size();
|
||||
const size_t rows = size();
|
||||
const size_t cols = at(0).size();
|
||||
ret.reserve(rows * cols);
|
||||
if (order == ReshapeByRow) {
|
||||
for (size_t r = 0; r < rows; r++) {
|
||||
@@ -2399,11 +2403,11 @@ public:
|
||||
inline PIVector<PIVector<T>> splitBySize(size_t sz) const {
|
||||
PIVector<PIVector<T>> ret;
|
||||
if (isEmpty() || sz == 0) return ret;
|
||||
size_t ch = piv_size / sz;
|
||||
const size_t ch = piv_size / sz;
|
||||
for (size_t i = 0; i < ch; ++i) {
|
||||
ret << PIVector<T>(piv_data + sz * i, sz);
|
||||
}
|
||||
size_t t = ch * sz;
|
||||
const size_t t = ch * sz;
|
||||
if (t < piv_size) {
|
||||
ret << PIVector<T>(piv_data + t, piv_size - t);
|
||||
}
|
||||
@@ -2431,10 +2435,10 @@ public:
|
||||
if (index >= piv_size || count == 0) return ret;
|
||||
if (index + count > piv_size) count = piv_size - index;
|
||||
ret.alloc(count);
|
||||
memcpy((void *)ret.piv_data, (const void *)(piv_data + index), count * sizeof(T));
|
||||
size_t os = piv_size - index - count;
|
||||
memcpy(reinterpret_cast<void *>(ret.piv_data), reinterpret_cast<const void *>(piv_data + index), count * sizeof(T));
|
||||
const size_t os = piv_size - index - count;
|
||||
if (os > 0) {
|
||||
memmove((void *)(piv_data + index), (const void *)(piv_data + index + count), os * sizeof(T));
|
||||
memmove(reinterpret_cast<void *>(piv_data + index), reinterpret_cast<const void *>(piv_data + index + count), os * sizeof(T));
|
||||
piv_size -= count;
|
||||
} else {
|
||||
piv_size = index;
|
||||
@@ -2454,8 +2458,9 @@ private:
|
||||
if (piv_rsize * 2 >= s && piv_rsize < s) {
|
||||
return piv_rsize * 2;
|
||||
}
|
||||
ssize_t t = _PIContainerConstants<T>::minCountPoT(), s_ = s - 1;
|
||||
while (s_ >> t)
|
||||
ssize_t t = _PIContainerConstants<T>::minCountPoT();
|
||||
s -= 1;
|
||||
while (s >> t)
|
||||
++t;
|
||||
return (1 << t);
|
||||
}
|
||||
@@ -2471,7 +2476,7 @@ private:
|
||||
template<typename T1 = T, typename std::enable_if<std::is_trivially_copyable<T1>::value, int>::type = 0>
|
||||
inline void newT(T * dst, const T * src, size_t s) {
|
||||
PIINTROSPECTION_CONTAINER_USED(T, s)
|
||||
memcpy((void *)(dst), (const void *)(src), s * sizeof(T));
|
||||
memcpy(reinterpret_cast<void *>(dst), reinterpret_cast<const void *>(src), s * sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T1 = T, typename std::enable_if<!std::is_trivially_copyable<T1>::value, int>::type = 0>
|
||||
@@ -2519,13 +2524,13 @@ private:
|
||||
|
||||
inline void dealloc() {
|
||||
if (piv_data != nullptr) {
|
||||
free((void *)piv_data);
|
||||
free(reinterpret_cast<void *>(piv_data));
|
||||
piv_data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
inline void expand(size_t new_size, const T & e = T()) {
|
||||
size_t os = piv_size;
|
||||
const size_t os = piv_size;
|
||||
alloc(new_size);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size - os))
|
||||
for (size_t i = os; i < new_size; ++i) {
|
||||
@@ -2534,7 +2539,7 @@ private:
|
||||
}
|
||||
|
||||
inline void expand(size_t new_size, std::function<T(size_t i)> f) {
|
||||
size_t os = piv_size;
|
||||
const size_t os = piv_size;
|
||||
alloc(new_size);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size - os))
|
||||
for (size_t i = os; i < new_size; ++i) {
|
||||
@@ -2548,10 +2553,10 @@ private:
|
||||
return;
|
||||
}
|
||||
piv_size = new_size;
|
||||
size_t as = asize(new_size);
|
||||
const size_t as = asize(new_size);
|
||||
if (as == piv_rsize) return;
|
||||
PIINTROSPECTION_CONTAINER_ALLOC(T, (as - piv_rsize))
|
||||
T * p_d = (T *)(realloc((void *)(piv_data), as * sizeof(T)));
|
||||
T * p_d = reinterpret_cast<T *>(realloc(reinterpret_cast<void *>(piv_data), as * sizeof(T)));
|
||||
#ifndef NDEBUG
|
||||
if (!p_d) {
|
||||
printf("error with PIVector<%s>::alloc\n", __PIP_TYPENAME__(T));
|
||||
|
||||
@@ -98,12 +98,12 @@ public:
|
||||
inline const T * data(size_t index = 0) const { return p_->data(st_ + index); }
|
||||
inline Row & operator=(const Row & other) {
|
||||
if (p_ == other.p_ && st_ == other.st_) return *this;
|
||||
size_t sz = piMin<size_t>(sz_, other.sz_);
|
||||
const size_t sz = piMin<size_t>(sz_, other.sz_);
|
||||
p_->_copyRaw(p_->data(st_), other.data(), sz);
|
||||
return *this;
|
||||
}
|
||||
inline Row & operator=(const PIVector<T> & other) {
|
||||
size_t sz = piMin<size_t>(sz, other.size());
|
||||
const size_t sz = piMin<size_t>(sz, other.size());
|
||||
p_->_copyRaw(p_->data(st_), other.data(), sz);
|
||||
return *this;
|
||||
}
|
||||
@@ -130,13 +130,13 @@ public:
|
||||
inline const T * data(size_t index = 0) const { return p_->data(index * step_ + row_); }
|
||||
inline Col & operator=(const Col & other) {
|
||||
if (p_ == other.p_ && row_ == other.row_) return *this;
|
||||
size_t sz = piMin<size_t>(sz_, other.sz_);
|
||||
const size_t sz = piMin<size_t>(sz_, other.sz_);
|
||||
for (int i = 0; i < sz; ++i)
|
||||
(*p_)[i * step_ + row_] = other[i];
|
||||
return *this;
|
||||
}
|
||||
inline Row & operator=(const PIVector<T> & other) {
|
||||
size_t sz = piMin<size_t>(sz_, other.size());
|
||||
const size_t sz = piMin<size_t>(sz_, other.size());
|
||||
for (int i = 0; i < sz; ++i)
|
||||
(*p_)[i * step_ + row_] = other[i];
|
||||
return *this;
|
||||
@@ -206,24 +206,24 @@ public:
|
||||
inline Col col(size_t index) { return Col(this, index); }
|
||||
inline ColConst col(size_t index) const { return ColConst(this, index); }
|
||||
inline PIVector2D<T> & setRow(size_t row, const Row & other) {
|
||||
size_t sz = piMin<size_t>(cols_, other.sz_);
|
||||
const size_t sz = piMin<size_t>(cols_, other.sz_);
|
||||
mat._copyRaw(mat.data(cols_ * row), other.data(), sz);
|
||||
return *this;
|
||||
}
|
||||
inline PIVector2D<T> & setRow(size_t row, const RowConst & other) {
|
||||
size_t sz = piMin<size_t>(cols_, other.sz_);
|
||||
const size_t sz = piMin<size_t>(cols_, other.sz_);
|
||||
mat._copyRaw(mat.data(cols_ * row), other.data(), sz);
|
||||
return *this;
|
||||
}
|
||||
inline PIVector2D<T> & setRow(size_t row, const PIVector<T> & other) {
|
||||
size_t sz = piMin<size_t>(cols_, other.size());
|
||||
const size_t sz = piMin<size_t>(cols_, other.size());
|
||||
mat._copyRaw(mat.data(cols_ * row), other.data(), sz);
|
||||
return *this;
|
||||
}
|
||||
inline PIVector2D<T> & addRow(const Row & other) {
|
||||
if (cols_ == 0) cols_ = other.sz_;
|
||||
size_t sz = piMin<size_t>(cols_, other.sz_);
|
||||
size_t ps = mat.size();
|
||||
const size_t sz = piMin<size_t>(cols_, other.sz_);
|
||||
const size_t ps = mat.size();
|
||||
mat.resize(mat.size() + cols_);
|
||||
mat._copyRaw(mat.data(ps), other.data(), sz);
|
||||
rows_++;
|
||||
@@ -231,8 +231,8 @@ public:
|
||||
}
|
||||
inline PIVector2D<T> & addRow(const RowConst & other) {
|
||||
if (cols_ == 0) cols_ = other.sz_;
|
||||
size_t sz = piMin<size_t>(cols_, other.sz_);
|
||||
size_t ps = mat.size();
|
||||
const size_t sz = piMin<size_t>(cols_, other.sz_);
|
||||
const size_t ps = mat.size();
|
||||
mat.resize(mat.size() + cols_);
|
||||
mat._copyRaw(mat.data(ps), other.data(), sz);
|
||||
rows_++;
|
||||
@@ -240,8 +240,8 @@ public:
|
||||
}
|
||||
inline PIVector2D<T> & addRow(const PIVector<T> & other) {
|
||||
if (cols_ == 0) cols_ = other.size();
|
||||
size_t sz = piMin<size_t>(cols_, other.size());
|
||||
size_t ps = mat.size();
|
||||
const size_t sz = piMin<size_t>(cols_, other.size());
|
||||
const size_t ps = mat.size();
|
||||
mat.resize(mat.size() + cols_);
|
||||
mat._copyRaw(mat.data(ps), other.data(), sz);
|
||||
rows_++;
|
||||
@@ -251,7 +251,7 @@ public:
|
||||
inline PIVector2D<T> & resize(size_t rows, size_t cols, const T & f = T()) {
|
||||
mat.resize(rows * cols_, f);
|
||||
rows_ = rows;
|
||||
int cs = (cols - cols_);
|
||||
const int cs = (cols - cols_);
|
||||
if (cs < 0) {
|
||||
for (size_t r = 0; r < rows; ++r) {
|
||||
mat.remove(r * cols + cols, -cs);
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
//! \~english Add argument with name "name", short key = "shortKey" and full key = name.
|
||||
//! \~russian Добавляет аргумент с именем "name", коротким ключом = "shortKey" и полным ключом = имени.
|
||||
void addArgument(const PIString & name, const char * shortKey, bool value = false) {
|
||||
_args << Argument(name, PIChar(shortKey), name, value);
|
||||
_args << Argument(name, PIChar::fromUTF8(shortKey), name, value);
|
||||
needParse = true;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
//! \~english Add argument with name "name", short key = "shortKey" and full key = "fullKey".
|
||||
//! \~russian Добавляет аргумент с именем "name", коротким ключом = "shortKey" и полным ключом = "fullKey".
|
||||
void addArgument(const PIString & name, const char * shortKey, const PIString & fullKey, bool value = false) {
|
||||
_args << Argument(name, PIChar(shortKey), fullKey, value);
|
||||
_args << Argument(name, PIChar::fromUTF8(shortKey), fullKey, value);
|
||||
needParse = true;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
//! \~russian Возвращает короткий ключ аргумента "name" или пустую строку, если аргумента нет.
|
||||
PIString argumentShortKey(const PIString & name) {
|
||||
piForeach(Argument & i, _args)
|
||||
if (i.name == name) return i.short_key;
|
||||
if (i.name == name) return PIString(i.short_key);
|
||||
return PIString();
|
||||
}
|
||||
|
||||
|
||||
@@ -175,11 +175,11 @@ public:
|
||||
|
||||
void setVendorID(ushort vid) {
|
||||
vid_ = vid;
|
||||
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, "0") + ":" + PIString::fromNumber(pid_, 16).expandLeftTo(4, "0"));
|
||||
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, '0') + ':' + PIString::fromNumber(pid_, 16).expandLeftTo(4, '0'));
|
||||
}
|
||||
void setProductID(ushort pid) {
|
||||
pid_ = pid;
|
||||
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, "0") + ":" + PIString::fromNumber(pid_, 16).expandLeftTo(4, "0"));
|
||||
setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, '0') + ':' + PIString::fromNumber(pid_, 16).expandLeftTo(4, '0'));
|
||||
}
|
||||
|
||||
bool setConfiguration(uchar value);
|
||||
|
||||
@@ -111,11 +111,6 @@ bool winIsCharType(const ushort * ch, int type) {
|
||||
}
|
||||
|
||||
|
||||
PIChar::PIChar(const char * c, int * bytes) {
|
||||
ch = charFromCodepage(c, 4, __syslocname__, bytes);
|
||||
}
|
||||
|
||||
|
||||
PIChar PIChar::fromConsole(char c) {
|
||||
PIChar ret;
|
||||
ret.ch = charFromCodepage(&c, 1, __sysoemname__);
|
||||
@@ -130,10 +125,20 @@ PIChar PIChar::fromSystem(char c) {
|
||||
}
|
||||
|
||||
|
||||
PIChar PIChar::fromSystem(const char * c) {
|
||||
PIChar ret;
|
||||
int l = 0;
|
||||
while (c[l] != '\0' && l < 4)
|
||||
++l;
|
||||
ret.ch = charFromCodepage(c, l, __syslocname__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIChar PIChar::fromUTF8(const char * c) {
|
||||
PIChar ret;
|
||||
int l = 0;
|
||||
while (c[l] != '\0')
|
||||
while (c[l] != '\0' && l < 4)
|
||||
++l;
|
||||
ret.ch = charFromCodepage(c, l, __utf8name__);
|
||||
return ret;
|
||||
|
||||
@@ -57,9 +57,9 @@ public:
|
||||
//! \~russian Создает 2-байтный символ из `wchar_t`
|
||||
PIChar(wchar_t c) { ch = c; }
|
||||
|
||||
//! \~english Contructs symbol from system locale and no more than 4 bytes of string
|
||||
//! \~russian Создает символ из системной локали не более 4 байт длины
|
||||
PIChar(const char * c, int * bytes = 0);
|
||||
//! \~english Contructs 2-bytes symbol from `char16_t`
|
||||
//! \~russian Создает 2-байтный символ из `char16_t`
|
||||
PIChar(char16_t c) { ch = c; }
|
||||
|
||||
//! \~english Copy operator
|
||||
//! \~russian Оператор присваивания
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
bool operator!=(const PIChar & o) const { return !(o == *this); }
|
||||
bool operator!=(const PIChar & o) const { return !(*this == o); }
|
||||
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
@@ -177,6 +177,10 @@ public:
|
||||
//! \~russian Возвращает символ из системной кодировки
|
||||
static PIChar fromSystem(char c);
|
||||
|
||||
//! \~english Returns symbol from system codepage
|
||||
//! \~russian Возвращает символ из системной кодировки
|
||||
static PIChar fromSystem(const char * c);
|
||||
|
||||
//! \~english Returns symbol from UTF8 codepage
|
||||
//! \~russian Возвращает символ из UTF8 кодировки
|
||||
static PIChar fromUTF8(const char * c);
|
||||
@@ -225,76 +229,39 @@ inline bool operator<=(const char v, const PIChar & c) {
|
||||
return (PIChar(v) <= c);
|
||||
}
|
||||
|
||||
|
||||
//! \relatesalso PIChar
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator==(const char * v, const PIChar & c) {
|
||||
inline bool operator==(ushort v, const PIChar & c) {
|
||||
return (PIChar(v) == c);
|
||||
}
|
||||
|
||||
//! \relatesalso PIChar
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator>(const char * v, const PIChar & c) {
|
||||
inline bool operator>(ushort v, const PIChar & c) {
|
||||
return (PIChar(v) > c);
|
||||
}
|
||||
|
||||
//! \relatesalso PIChar
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator<(const char * v, const PIChar & c) {
|
||||
inline bool operator<(ushort v, const PIChar & c) {
|
||||
return (PIChar(v) < c);
|
||||
}
|
||||
|
||||
//! \relatesalso PIChar
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator>=(const char * v, const PIChar & c) {
|
||||
inline bool operator>=(ushort v, const PIChar & c) {
|
||||
return (PIChar(v) >= c);
|
||||
}
|
||||
|
||||
//! \relatesalso PIChar
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator<=(const char * v, const PIChar & c) {
|
||||
inline bool operator<=(ushort v, const PIChar & c) {
|
||||
return (PIChar(v) <= c);
|
||||
}
|
||||
|
||||
|
||||
//! \relatesalso PIChar
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator==(const int v, const PIChar & c) {
|
||||
return (PIChar((ushort)v) == c);
|
||||
}
|
||||
|
||||
//! \relatesalso PIChar
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator>(const int v, const PIChar & c) {
|
||||
return (PIChar((ushort)v) > c);
|
||||
}
|
||||
|
||||
//! \relatesalso PIChar
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator<(const int v, const PIChar & c) {
|
||||
return (PIChar((ushort)v) < c);
|
||||
}
|
||||
|
||||
//! \relatesalso PIChar
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator>=(const int v, const PIChar & c) {
|
||||
return (PIChar((ushort)v) >= c);
|
||||
}
|
||||
|
||||
//! \relatesalso PIChar
|
||||
//! \~english Compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator<=(const int v, const PIChar & c) {
|
||||
return (PIChar((ushort)v) <= c);
|
||||
}
|
||||
|
||||
#endif // PICHAR_H
|
||||
|
||||
@@ -405,6 +405,16 @@ PIString PIString::fromAscii(const char * s, int len) {
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::fromAscii(const PIByteArray & ascii) {
|
||||
PIString ret;
|
||||
ret.resize(ascii.size());
|
||||
for (int l = 0; l < ret.size_s(); ++l) {
|
||||
ret[l] = PIChar(ascii[l]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::fromCodepage(const char * s, const char * c) {
|
||||
PIString ret;
|
||||
if (s[0] > '\0')
|
||||
@@ -573,12 +583,6 @@ PIString & PIString::operator+=(const char * str) {
|
||||
}
|
||||
|
||||
|
||||
PIString & PIString::operator+=(const PIByteArray & ba) {
|
||||
appendFromChars((const char *)ba.data(), ba.size_s(), __utf8name__);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIString::~PIString() {
|
||||
deleteData();
|
||||
}
|
||||
@@ -594,6 +598,16 @@ PIString & PIString::operator+=(const wchar_t * str) {
|
||||
}
|
||||
|
||||
|
||||
PIString & PIString::operator+=(const char16_t * str) {
|
||||
if (!str) return *this;
|
||||
int i = -1;
|
||||
while (str[++i]) {
|
||||
d.push_back(PIChar(str[i]));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIString & PIString::operator+=(const PIString & str) {
|
||||
d.append(str.d);
|
||||
return *this;
|
||||
@@ -1162,12 +1176,24 @@ int PIString::entries(const PIChar c) const {
|
||||
}
|
||||
|
||||
|
||||
bool PIString::startsWith(const PIChar c) const {
|
||||
if (isEmpty()) return false;
|
||||
return front() == c;
|
||||
}
|
||||
|
||||
|
||||
bool PIString::startsWith(const PIString & str) const {
|
||||
if (size() < str.size()) return false;
|
||||
return str == left(str.size());
|
||||
}
|
||||
|
||||
|
||||
bool PIString::endsWith(const PIChar c) const {
|
||||
if (isEmpty()) return false;
|
||||
return back() == c;
|
||||
}
|
||||
|
||||
|
||||
bool PIString::endsWith(const PIString & str) const {
|
||||
if (size() < str.size()) return false;
|
||||
return str == right(str.size());
|
||||
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
}
|
||||
PIString & operator+=(const char * str);
|
||||
PIString & operator+=(const wchar_t * str);
|
||||
PIString & operator+=(const PIByteArray & ba);
|
||||
PIString & operator+=(const char16_t * str);
|
||||
PIString & operator+=(const PIString & str);
|
||||
PIString & operator+=(const PIConstChars & str);
|
||||
|
||||
@@ -143,9 +143,17 @@ public:
|
||||
//! \endcode
|
||||
PIString(const wchar_t * str) { *this += str; }
|
||||
|
||||
//! \~english Contructs string from byte array "ba" (as UTF-8).
|
||||
//! \~russian Создает строку из байтового массива "ba" (как UTF-8).
|
||||
PIString(const PIByteArray & ba) { *this += ba; }
|
||||
//! \~english Contructs string from \c char16_t C-string "str".
|
||||
//! \~russian Создает строку из \c char16_t C-строки "str".
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! "str" should be null-terminated
|
||||
//! \~russian
|
||||
//! "str" должна заканчиваться нулевым \c char16_t
|
||||
//! \~\code
|
||||
//! PIString s(u"string");
|
||||
//! \endcode
|
||||
PIString(const char16_t * str) { *this += str; }
|
||||
|
||||
//! \~english Contructs string from "len" characters of buffer "str".
|
||||
//! \~russian Создает строку из "len" символов массива "str".
|
||||
@@ -217,6 +225,14 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIString & operator=(const char16_t * o) {
|
||||
d.clear();
|
||||
*this += o;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Compare operator.
|
||||
//! \~russian Оператор сравнения.
|
||||
bool operator==(const PIString & str) const;
|
||||
@@ -452,6 +468,13 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Insert string "str" at the begin of string.
|
||||
//! \~russian Вставляет "str" в начало строки.
|
||||
PIString & push_front(const char16_t * str) {
|
||||
insert(0, str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Insert string "str" at the begin of string.
|
||||
//! \~russian Вставляет "str" в начало строки.
|
||||
PIString & push_front(const PIString & str) {
|
||||
@@ -480,6 +503,13 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Insert string "str" at the end of string.
|
||||
//! \~russian Вставляет "str" в конец строки.
|
||||
PIString & append(const char16_t * str) {
|
||||
*this += str;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Insert string "str" at the end of string.
|
||||
//! \~russian Вставляет "str" в конец строки.
|
||||
PIString & append(const PIString & str) {
|
||||
@@ -787,6 +817,16 @@ public:
|
||||
//! \endcode
|
||||
PIString & insert(const int index, const char * c) { return insert(index, PIString(c)); }
|
||||
|
||||
//! \~english Insert string "str" after index "index" and return this string.
|
||||
//! \~russian Вставляет строку "str" после позиции "index" и возвращает эту строку.
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! PIString s("stg");
|
||||
//! s.insert(2, u"rin");
|
||||
//! piCout << s; // s = "string"
|
||||
//! \endcode
|
||||
PIString & insert(const int index, const char16_t * c) { return insert(index, PIString(c)); }
|
||||
|
||||
//! \~english Enlarge string to length "len" by addition characters "c" at the end, and return this string.
|
||||
//! \~russian Увеличивает длину строки до "len" добавлением символов "c" в конец и возвращает эту строку.
|
||||
//! \~\details
|
||||
@@ -1184,19 +1224,26 @@ public:
|
||||
//! \endcode
|
||||
int entries(const PIChar c) const;
|
||||
|
||||
//! \~english Returns number of occurrences of character "c".
|
||||
//! \~russian Возвращает число вхождений символа "c".
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! piCout << PIString(".str.0").entries('.'); // 2
|
||||
//! piCout << PIString(".str.0").entries('0'); // 1
|
||||
//! \endcode
|
||||
int entries(char c) const { return entries(PIChar(c)); }
|
||||
//! \~english Returns if string starts with "c".
|
||||
//! \~russian Возвращает начинается ли строка с "c".
|
||||
bool startsWith(const char c) const { return startsWith(PIChar(c)); }
|
||||
|
||||
//! \~english Returns if string starts with "c".
|
||||
//! \~russian Возвращает начинается ли строка с "c".
|
||||
bool startsWith(const PIChar c) const;
|
||||
|
||||
//! \~english Returns if string starts with "str".
|
||||
//! \~russian Возвращает начинается ли строка со "str".
|
||||
bool startsWith(const PIString & str) const;
|
||||
|
||||
//! \~english Returns if string ends with "c".
|
||||
//! \~russian Возвращает оканчивается ли строка на "c".
|
||||
bool endsWith(const char c) const { return endsWith(PIChar(c)); }
|
||||
|
||||
//! \~english Returns if string ends with "c".
|
||||
//! \~russian Возвращает оканчивается ли строка на "c".
|
||||
bool endsWith(const PIChar c) const;
|
||||
|
||||
//! \~english Returns if string ends with "str".
|
||||
//! \~russian Возвращает оканчивается ли строка на "str".
|
||||
bool endsWith(const PIString & str) const;
|
||||
@@ -1714,6 +1761,10 @@ public:
|
||||
//! \~russian Возвращает строку созданную из "len" символов ASCII.
|
||||
static PIString fromAscii(const char * s, int len);
|
||||
|
||||
//! \~english Returns string constructed from ASCII.
|
||||
//! \~russian Возвращает строку созданную из ASCII.
|
||||
static PIString fromAscii(const PIByteArray & ascii);
|
||||
|
||||
//! \~english Returns string constructed from "cp" codepage.
|
||||
//! \~russian Возвращает строку созданную из кодировки "cp".
|
||||
static PIString fromCodepage(const char * s, const char * cp);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#ifdef QNX
|
||||
typedef std::basic_string<wchar_t> wstring;
|
||||
#endif
|
||||
#include "piliterals.h"
|
||||
#include "pistringlist.h"
|
||||
|
||||
|
||||
@@ -117,12 +118,12 @@ inline std::istream & operator>>(std::istream & s, PIString & v) {
|
||||
|
||||
//! \relatesalso PIStringList \brief Output operator to std::ostream (cout)
|
||||
inline std::ostream & operator<<(std::ostream & s, const PIStringList & v) {
|
||||
s << PIChar("{");
|
||||
s << PIChar('{');
|
||||
for (uint i = 0; i < v.size(); ++i) {
|
||||
s << PIChar("\"") << v[i] << PIChar("\"");
|
||||
if (i < v.size() - 1) s << PIStringAscii(", ");
|
||||
s << PIChar('"') << v[i] << PIChar('"');
|
||||
if (i < v.size() - 1) s << ", "_a;
|
||||
}
|
||||
s << PIChar("}");
|
||||
s << PIChar('}');
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,8 @@ PIByteArray PIByteArray::toBase64() const {
|
||||
if (isEmpty()) return PIByteArray();
|
||||
base64HelpStruct hs;
|
||||
PIByteArray ret;
|
||||
int sz = (size_s() / 3) * 3, ri = -1;
|
||||
const int sz = (size_s() / 3) * 3;
|
||||
int ri = -1;
|
||||
uchar t[4];
|
||||
ret.resize(((size_s() - 1) / 3 + 1) * 4);
|
||||
for (int i = 0; i < sz; i += 3) {
|
||||
@@ -154,7 +155,7 @@ PIByteArray PIByteArray::toBase64() const {
|
||||
ret[++ri] = (t[2]);
|
||||
ret[++ri] = (t[3]);
|
||||
}
|
||||
int der = size_s() % 3;
|
||||
const int der = size_s() % 3;
|
||||
switch (der) {
|
||||
case 1:
|
||||
hs.setBytes(data(sz), 1);
|
||||
@@ -182,7 +183,8 @@ PIByteArray PIByteArray::fromBase64(const PIByteArray & base64) {
|
||||
if (base64.isEmpty()) return PIByteArray();
|
||||
base64HelpStruct hs;
|
||||
PIByteArray ret;
|
||||
int sz = base64.size_s(), ind = -1;
|
||||
const int sz = base64.size_s();
|
||||
int ind = -1;
|
||||
uchar t[4];
|
||||
ret.resize(sz / 4 * 3);
|
||||
for (int i = 0; i < sz; i += 4) {
|
||||
@@ -206,7 +208,9 @@ PIByteArray PIByteArray::fromBase64(const PIString & base64) {
|
||||
|
||||
PIByteArray & PIByteArray::compressRLE(uchar threshold) {
|
||||
PIByteArray t;
|
||||
uchar fb, clen, mlen = 255 - threshold;
|
||||
uchar fb;
|
||||
uchar clen;
|
||||
const uchar mlen = 255 - threshold;
|
||||
for (uint i = 0; i < size();) {
|
||||
fb = at(i);
|
||||
clen = 1;
|
||||
@@ -232,7 +236,8 @@ PIByteArray & PIByteArray::compressRLE(uchar threshold) {
|
||||
|
||||
PIByteArray & PIByteArray::decompressRLE(uchar threshold) {
|
||||
PIByteArray t;
|
||||
uchar fb, clen;
|
||||
uchar fb;
|
||||
uchar clen;
|
||||
for (uint i = 0; i < size(); ++i) {
|
||||
fb = at(i);
|
||||
if (fb >= threshold) {
|
||||
@@ -264,7 +269,7 @@ PIByteArray & PIByteArray::decompressRLE(uchar threshold) {
|
||||
//! \endcode
|
||||
uchar PIByteArray::checksumPlain8(bool inverse) const {
|
||||
uchar c = 0;
|
||||
int sz = size_s();
|
||||
const int sz = size_s();
|
||||
for (int i = 0; i < sz; ++i)
|
||||
c += at(i);
|
||||
if (inverse) c = ~(c + 1);
|
||||
@@ -300,7 +305,7 @@ uint PIByteArray::checksumCRC32() const {
|
||||
//! \endcode
|
||||
uint PIByteArray::checksumPlain32(bool inverse) const {
|
||||
uint c = 0;
|
||||
int sz = size_s();
|
||||
const int sz = size_s();
|
||||
for (int i = 0; i < sz; ++i)
|
||||
c += at(i) * (i + 1);
|
||||
if (inverse) c = ~(c + 1);
|
||||
@@ -315,7 +320,7 @@ uint PIByteArray::hash() const {
|
||||
|
||||
PIString PIByteArray::toString(int base) const {
|
||||
PIString ret;
|
||||
int sz = size_s();
|
||||
const int sz = size_s();
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
if (i > 0) ret += " ";
|
||||
if (base == 2) ret += "b";
|
||||
@@ -343,7 +348,7 @@ PIString PIByteArray::toHex() const {
|
||||
else
|
||||
hexData[i * 2 + 1] = (j + 'a' - 10);
|
||||
}
|
||||
return PIString(hex);
|
||||
return PIString::fromAscii(hex);
|
||||
}
|
||||
|
||||
|
||||
@@ -351,10 +356,10 @@ PIByteArray PIByteArray::fromUserInput(PIString str) {
|
||||
PIByteArray ret;
|
||||
if (str.trim().isEmpty()) return ret;
|
||||
str.replaceAll("\n", " ").replaceAll("\t", " ").replaceAll(" ", " ");
|
||||
PIStringList bl(str.split(" "));
|
||||
const PIStringList bl(str.split(" "));
|
||||
bool ok(false);
|
||||
piForeachC(PIString & b, bl) {
|
||||
int bv = b.toInt(-1, &ok);
|
||||
for (const auto & b: bl) {
|
||||
const int bv = b.toInt(-1, &ok);
|
||||
if (ok) ret << uchar(bv);
|
||||
}
|
||||
return ret;
|
||||
@@ -362,7 +367,7 @@ PIByteArray PIByteArray::fromUserInput(PIString str) {
|
||||
|
||||
|
||||
PIByteArray PIByteArray::fromHex(PIString str) {
|
||||
PIByteArray hexEncoded = str.toByteArray();
|
||||
const PIByteArray hexEncoded = str.toByteArray();
|
||||
PIByteArray res((hexEncoded.size() + 1) / 2);
|
||||
uchar * result = res.data() + res.size();
|
||||
bool odd_digit = true;
|
||||
|
||||
@@ -53,14 +53,14 @@ public:
|
||||
|
||||
//! \~english Constructs copy of byte array "o"
|
||||
//! \~russian Создает копию байтового массива "o"
|
||||
PIByteArray(const PIDeque<uchar> & o): d(o) {}
|
||||
explicit PIByteArray(const PIDeque<uchar> & o): d(o) {}
|
||||
|
||||
PIByteArray(PIByteArray && o): d(std::move(o.d)) {}
|
||||
PIByteArray(PIDeque<uchar> && o): d(std::move(o)) {}
|
||||
|
||||
//! \~english Constructs 0-filled byte array with size "size"
|
||||
//! \~russian Создает заполненный "0" байтовый массив размером "size"
|
||||
PIByteArray(const uint size) { resize(size); }
|
||||
explicit PIByteArray(const uint size) { resize(size); }
|
||||
|
||||
//! \~english Constructs byte array from data "data" and size "size"
|
||||
//! \~russian Создает байтовый массив из данных по указателю "data" размером "size"
|
||||
@@ -784,7 +784,7 @@ public:
|
||||
//! \~english Add to the end data "data" with size "size"
|
||||
//! \~russian Добавляет в конец массива данные по указателю "data" размером "size"
|
||||
PIByteArray & push_back(const void * data_, int size_) {
|
||||
uint ps = size();
|
||||
const uint ps = size();
|
||||
enlarge(size_);
|
||||
memcpy(data(ps), data_, size_);
|
||||
return *this;
|
||||
@@ -1083,7 +1083,7 @@ public:
|
||||
//! \~english Add to the end data "data" with size "size"
|
||||
//! \~russian Добавляет в конец массива данные по указателю "data" размером "size"
|
||||
PIByteArray & append(const void * data_, int size_) {
|
||||
uint ps = size();
|
||||
const uint ps = size();
|
||||
enlarge(size_);
|
||||
memcpy(data(ps), data_, size_);
|
||||
return *this;
|
||||
@@ -1092,7 +1092,7 @@ public:
|
||||
//! \~english Add to the end byte array "data"
|
||||
//! \~russian Добавляет в конец массива содержимое массива "data"
|
||||
PIByteArray & append(const PIByteArray & data_) {
|
||||
uint ps = size();
|
||||
const uint ps = size();
|
||||
enlarge(data_.size_s());
|
||||
memcpy(data(ps), data_.data(), data_.size());
|
||||
return *this;
|
||||
@@ -1176,8 +1176,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
bool binaryStreamTakeImp(void * d_, size_t s) {
|
||||
size_t rs = size();
|
||||
if (rs > s) rs = s;
|
||||
const size_t rs = s < size() ? s : size();
|
||||
memcpy(d_, data(), rs);
|
||||
remove(0, rs);
|
||||
return rs == s;
|
||||
|
||||
@@ -139,7 +139,7 @@ void PIOpenCL::Initializer::init() {
|
||||
|
||||
|
||||
PIOpenCL::Context::Context() {
|
||||
PRIVATE->complex_src = PIResources::get("3rd/clcomplex.h") + "\n";
|
||||
PRIVATE->complex_src = PIString::fromUTF8(PIResources::get("3rd/clcomplex.h")) + "\n";
|
||||
zero();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ int main(int argc, char * argv[]) {
|
||||
CONNECTL(&c, threadedReadEvent, ([&](const uchar * readed, ssize_t size) {
|
||||
PIByteArray ba(readed, size);
|
||||
if (size < 1024) {
|
||||
PIString str = PIString(ba);
|
||||
PIString str = PIString::fromUTF8(ba);
|
||||
piCout << "[Client] data:" << str;
|
||||
if (str == "ping_S") c.write(PIString("pong_S").toByteArray());
|
||||
} else
|
||||
@@ -44,7 +44,7 @@ int main(int argc, char * argv[]) {
|
||||
clients->append(cl);
|
||||
CONNECTL(cl, threadedReadEvent, ([cl, &rnd](const uchar * readed, ssize_t size) {
|
||||
PIByteArray ba(readed, size);
|
||||
PIString str = PIString(ba);
|
||||
PIString str = PIString::fromUTF8(ba);
|
||||
piCout << "[Server] data from" << cl << ":" << str;
|
||||
if (str == "ping") {
|
||||
cl->write(PIString("pong").toByteArray());
|
||||
|
||||
@@ -12,7 +12,7 @@ TEST(PIString_Tests, constructor_empty) {
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_pichar) {
|
||||
PIString str1 = "AB C";
|
||||
const PIChar str2 = " ";
|
||||
const PIChar str2 = ' ';
|
||||
str1 += str2;
|
||||
PIString res = "AB C ";
|
||||
ASSERT_EQ(str1, res);
|
||||
@@ -20,7 +20,7 @@ TEST(PIString_Tests, operator_concatenation_pichar) {
|
||||
|
||||
TEST(PIString_Tests, operator_concatenation_pichar_zero1) {
|
||||
PIString str1 = "";
|
||||
const PIChar str2 = "D";
|
||||
const PIChar str2 = 'D';
|
||||
str1 += str2;
|
||||
ASSERT_EQ(str1, "D");
|
||||
}
|
||||
@@ -120,7 +120,7 @@ TEST(PIString_Tests, construct_pistring) {
|
||||
TEST(PIString_Tests, construct_pistring_move) {
|
||||
PIString str1 = "New";
|
||||
PIString res = str1;
|
||||
PIString str(move(str1));
|
||||
PIString str(std::move(str1));
|
||||
ASSERT_EQ(res, str);
|
||||
}
|
||||
|
||||
@@ -192,14 +192,14 @@ TEST(PIString_Tests, operator_assignment) {
|
||||
TEST(PIString_Tests, operator_assignment_move) {
|
||||
PIString str1 = "testing";
|
||||
PIString str;
|
||||
str = move(str1);
|
||||
str = std::move(str1);
|
||||
ASSERT_EQ(PIString("testing"), str);
|
||||
ASSERT_TRUE(str1.isEmpty());
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_symbol) {
|
||||
PIString str1 = "testing";
|
||||
PIChar symbo = "i";
|
||||
PIChar symbo = 'i';
|
||||
ASSERT_EQ(symbo, str1[4]);
|
||||
}
|
||||
|
||||
@@ -217,13 +217,13 @@ TEST(PIString_Tests, operator_equal_pistring_false) {
|
||||
|
||||
TEST(PIString_Tests, operator_equal_pichar_true) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
PIChar str2 = 't';
|
||||
ASSERT_TRUE(str1 == str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_equal_pichar_false) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "p";
|
||||
PIChar str2 = 'p';
|
||||
ASSERT_FALSE(str1 == str2);
|
||||
}
|
||||
|
||||
@@ -253,13 +253,13 @@ TEST(PIString_Tests, operator_not_equal_pistring_true) {
|
||||
|
||||
TEST(PIString_Tests, operator_not_equal_pichar_false) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
PIChar str2 = 't';
|
||||
ASSERT_FALSE(str1 != str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_not_equal_pichar_true) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "p";
|
||||
PIChar str2 = 'p';
|
||||
ASSERT_TRUE(str1 != str2);
|
||||
}
|
||||
|
||||
@@ -295,19 +295,19 @@ TEST(PIString_Tests, operator_less_pistring_false_equal) {
|
||||
|
||||
TEST(PIString_Tests, operator_less_pichar_true) {
|
||||
PIString str1 = "a";
|
||||
PIChar str2 = "t";
|
||||
PIChar str2 = 't';
|
||||
ASSERT_TRUE(str1 < str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_pichar_false) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "a";
|
||||
PIChar str2 = 'a';
|
||||
ASSERT_FALSE(str1 < str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_pichar_false_equal) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
PIChar str2 = 't';
|
||||
ASSERT_FALSE(str1 < str2);
|
||||
}
|
||||
|
||||
@@ -349,19 +349,19 @@ TEST(PIString_Tests, operator_grater_pistring_false_equal) {
|
||||
|
||||
TEST(PIString_Tests, operator_grater_pichar_true) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "a";
|
||||
PIChar str2 = 'a';
|
||||
ASSERT_TRUE(str1 > str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_grater_pichar_false) {
|
||||
PIString str1 = "a";
|
||||
PIChar str2 = "t";
|
||||
PIChar str2 = 't';
|
||||
ASSERT_FALSE(str1 > str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_grater_pichar_false_equal) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
PIChar str2 = 't';
|
||||
ASSERT_FALSE(str1 > str2);
|
||||
}
|
||||
|
||||
@@ -403,19 +403,19 @@ TEST(PIString_Tests, operator_less_eq_pistring_true_equal) {
|
||||
|
||||
TEST(PIString_Tests, operator_less_eq_pichar_true) {
|
||||
PIString str1 = "a";
|
||||
PIChar str2 = "t";
|
||||
PIChar str2 = 't';
|
||||
ASSERT_TRUE(str1 <= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_eq_pichar_false) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "a";
|
||||
PIChar str2 = 'a';
|
||||
ASSERT_FALSE(str1 <= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_less_eq_pichar_true_equal) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
PIChar str2 = 't';
|
||||
ASSERT_TRUE(str1 <= str2);
|
||||
}
|
||||
|
||||
@@ -457,19 +457,19 @@ TEST(PIString_Tests, operator_grater_eq_pistring_true_equal) {
|
||||
|
||||
TEST(PIString_Tests, operator_grater_eq_pichar_true) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "a";
|
||||
PIChar str2 = 'a';
|
||||
ASSERT_TRUE(str1 >= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_grater_eq_pichar_false) {
|
||||
PIString str1 = "a";
|
||||
PIChar str2 = "t";
|
||||
PIChar str2 = 't';
|
||||
ASSERT_FALSE(str1 >= str2);
|
||||
}
|
||||
|
||||
TEST(PIString_Tests, operator_grater_eq_pichar_true_equal) {
|
||||
PIString str1 = "t";
|
||||
PIChar str2 = "t";
|
||||
PIChar str2 = 't';
|
||||
ASSERT_TRUE(str1 >= str2);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ int main(int argc, char * argv[]) {
|
||||
}
|
||||
if (cli.hasArgument("pass")) secret = crypt.hash(cli.argumentValue("pass"));
|
||||
if (cli.hasArgument("secret")) secret = PIByteArray::fromBase64(cli.argumentValue("secret").toByteArray());
|
||||
if (cli.hasArgument("hex")) secret = PIByteArray::fromHex(cli.argumentValue("hex").toByteArray());
|
||||
if (cli.hasArgument("hex")) secret = PIByteArray::fromHex(PIString::fromAscii(cli.argumentValue("hex").toByteArray()));
|
||||
if (secret.size() == crypt.sizeKey()) {
|
||||
PIFile inf;
|
||||
PIString in_file;
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "picli.h"
|
||||
#include "pidir.h"
|
||||
#include "piiostream.h"
|
||||
#include "piprocess.h"
|
||||
|
||||
#define DELIM "::"
|
||||
|
||||
@@ -251,7 +250,7 @@ void checkQtLib(PIString lib) {
|
||||
for (int i = 0;; ++i) {
|
||||
if (qt_deps[i].lib.isEmpty()) break;
|
||||
if (qt_deps[i].lib == base) {
|
||||
qt_plugins << qt_deps[i].plugins;
|
||||
qt_plugins << PISet<PIString>(qt_deps[i].plugins);
|
||||
// piCout << "add qt plugins" << qt_deps[i].plugins << "now" << qt_plugins;
|
||||
need_qt = true;
|
||||
qt_libs << lib;
|
||||
@@ -615,7 +614,7 @@ int main(int argc, char * argv[]) {
|
||||
out_dir = cli.argumentValue("output");
|
||||
lib_dirs = cli.argumentValue("search_path").split(DELIM);
|
||||
add_libs = cli.argumentValue("add_libs").split(DELIM);
|
||||
ignore_libs = cli.argumentValue("ignore").split(DELIM);
|
||||
ignore_libs = PISet<PIString>(cli.argumentValue("ignore").split(DELIM));
|
||||
qt_dir = cli.argumentValue("qtdir");
|
||||
ldd = cli.argumentValue("ldd");
|
||||
readelf = cli.argumentValue("Lreadelf");
|
||||
|
||||
Reference in New Issue
Block a user