Commit f2468418 authored by Tom Niget's avatar Tom Niget

Update PyObj definition

parent ddd2df9a
......@@ -36,7 +36,7 @@
#define FUNCTION(ret, name, args, ...) \
struct { \
ret operator() args __VA_ARGS__ \
ret operator() args const __VA_ARGS__ \
} static constexpr name;
using namespace std::literals;
......@@ -59,7 +59,67 @@ template <PySmartPtr T> struct RealType<T> {
using type = typename T::element_type;
};
template <typename T> using PyObj = std::shared_ptr<typename RealType<T>::type>;
//template <typename T> using PyObj = std::shared_ptr<typename RealType<T>::type>;
template<typename T>
class PyObj : public std::shared_ptr<typename RealType<T>::type> {
public:
using inner = typename RealType<T>::type;
/*PyObj() : std::shared_ptr<inner>() {}
PyObj(std::nullptr_t) : std::shared_ptr<inner>(nullptr) {}
PyObj(inner *ptr) : std::shared_ptr<inner>(ptr) {}
PyObj(const std::shared_ptr<inner> &ptr) : std::shared_ptr<inner>(ptr) {}
PyObj(std::shared_ptr<inner> &&ptr) : std::shared_ptr<inner>(ptr) {}
PyObj(const PyObj &ptr) : std::shared_ptr<inner>(ptr) {}
PyObj(PyObj &&ptr) : std::shared_ptr<inner>(ptr) {}
PyObj &operator=(const PyObj &ptr) { std::shared_ptr<inner>::operator=(ptr); return *this; }
PyObj &operator=(PyObj &&ptr) { std::shared_ptr<inner>::operator=(ptr); return *this; }
PyObj &operator=(std::nullptr_t) { std::shared_ptr<inner>::operator=(nullptr); return *this; }
PyObj &operator=(inner *ptr) { std::shared_ptr<inner>::operator=(ptr); return *this; }
PyObj &operator=(const std::shared_ptr<inner> &ptr) { std::shared_ptr<inner>::operator=(ptr); return *this; }
template<typename U>
PyObj(const PyObj<U> &ptr) : std::shared_ptr<inner>(ptr) {}
template<typename U>
PyObj(PyObj<U> &&ptr) : std::shared_ptr<inner>(ptr) {}*/
template<typename... Args>
PyObj(Args&&... args) : std::shared_ptr<inner>(std::forward<Args>(args)...) {}
// using make_shared
template<class U>
PyObj(const U& other) : std::shared_ptr<inner>(std::make_shared<T>(other)) {}
template<class U>
bool operator==(const PyObj<U> &other) const {
// check null
if (this->get() == other.get()) {
return true;
}
if (this->get() == nullptr || other.get() == nullptr) {
return false;
}
return *this->get() == *other.get();
}
template<class U>
bool operator==(const U& other) const {
if (this->get() == nullptr) {
return false;
}
return *this->get() == other;
}
template<class U>
bool py_is(const PyObj<U> &other) const {
return this->get() == other.get();
}
};
template <typename T, typename... Args> auto pyobj(Args &&...args) -> PyObj<T> {
return std::make_shared<typename RealType<T>::type>(
......@@ -123,14 +183,7 @@ std::ostream &operator<<(std::ostream &os, std::optional<T> const &opt) {
bool is_cpp() { return true; }
class NoneType {
public:
template <typename T> operator T *() const { return nullptr; }
template <typename T> operator std::optional<T>() const {
return std::nullopt;
}
} PyNone{};
static constexpr auto PyNone = std::nullopt;
#define system_error(err, message) \
do { \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment