mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
commit 7e52f767ca130a49abb90ec922d74d2f5e9be078 Author: blueloveTH <blueloveTH@foxmail.com> Date: Sat Jun 1 12:49:46 2024 +0800 some optimize commit 3e2ad5b1fbad4367c80ea1325d1aa379282c10c4 Author: blueloveTH <blueloveTH@foxmail.com> Date: Sat Jun 1 12:29:53 2024 +0800 some fix commit bc0e530c72896a23cb6616ff4197ac36913389a4 Author: blueloveTH <blueloveTH@foxmail.com> Date: Sat Jun 1 00:00:47 2024 +0800 some fix commit f17ddcf8299c5d6803085cd3263181f44284f31b Author: blueloveTH <blueloveTH@foxmail.com> Date: Fri May 31 23:56:15 2024 +0800 some fix commit cc63926c8bb89df2d99d8c92c2e18bd5a0180a2c Author: blueloveTH <blueloveTH@foxmail.com> Date: Fri May 31 23:44:09 2024 +0800 some fix commit 3d3fb042651579cbdbcf3255398276ebb7b81e58 Author: blueloveTH <blueloveth@foxmail.com> Date: Fri May 31 17:28:13 2024 +0800 deprecate `PK_OBJ_MARK` commit 3df5f1cf128f157fb3a7aac2ceeeb47c55f5bb3b Author: blueloveTH <blueloveth@foxmail.com> Date: Fri May 31 17:18:34 2024 +0800 init
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#include "pocketpy/obj.h"
|
|
|
|
namespace pkpy{
|
|
PyVar::PyVar(PyObject* p): PyVar(p->type, p) {}
|
|
|
|
bool Bytes::operator==(const Bytes& rhs) const{
|
|
if(_size != rhs._size) return false;
|
|
for(int i=0; i<_size; i++) if(_data[i] != rhs._data[i]) return false;
|
|
return true;
|
|
}
|
|
bool Bytes::operator!=(const Bytes& rhs) const{ return !(*this == rhs); }
|
|
|
|
Bytes::Bytes(std::string_view sv){
|
|
_data = new unsigned char[sv.size()];
|
|
_size = sv.size();
|
|
for(int i=0; i<_size; i++) _data[i] = sv[i];
|
|
}
|
|
|
|
// copy constructor
|
|
Bytes::Bytes(const Bytes& rhs){
|
|
_data = new unsigned char[rhs._size];
|
|
_size = rhs._size;
|
|
for(int i=0; i<_size; i++) _data[i] = rhs._data[i];
|
|
}
|
|
|
|
// move constructor
|
|
Bytes::Bytes(Bytes&& rhs) noexcept {
|
|
_data = rhs._data;
|
|
_size = rhs._size;
|
|
rhs._data = nullptr;
|
|
rhs._size = 0;
|
|
}
|
|
|
|
// move assignment
|
|
Bytes& Bytes::operator=(Bytes&& rhs) noexcept {
|
|
delete[] _data;
|
|
_data = rhs._data;
|
|
_size = rhs._size;
|
|
rhs._data = nullptr;
|
|
rhs._size = 0;
|
|
return *this;
|
|
}
|
|
|
|
std::pair<unsigned char*, int> Bytes::detach() noexcept {
|
|
unsigned char* p = _data;
|
|
int size = _size;
|
|
_data = nullptr;
|
|
_size = 0;
|
|
return {p, size};
|
|
}
|
|
} // namespace pkpy
|