#pragma once #include #include #include #include #include #include #include #include "os_python.h" #include "PConv.h" #include "pymol/type_traits.h" #include "pymol/algorithm.h" #include namespace pymol { /** * Basic PyMOL Instance & Globals for C-testing purposes. */ class PyMOLInstance { public: PyMOLInstance(); PyMOLInstance(const PyMOLInstance&) = delete; PyMOLInstance& operator=(const PyMOLInstance&) = delete; PyMOLInstance(PyMOLInstance&&) = delete; PyMOLInstance& operator=(PyMOLInstance&&) = delete; ~PyMOLInstance(); /** * @return PyMOLGlobals pointer */ PyMOLGlobals* G() noexcept; private: CPyMOL* m_Inst; PyMOLGlobals* m_G; }; namespace test { // Checks whether obj is zero'd out (Struct of all PoD Types without non-default // values are 0) template static bool isStructZero(const T &obj) { const auto size = sizeof(T); std::array buffer{}; return std::memcmp(buffer.data(), &obj, size) == 0; } // Checks whether array arr is zeroed template static bool isArrayZero(const T *arr, const std::size_t len) { auto bytelen = len * sizeof(T); std::vector buffer(bytelen, 0); return std::memcmp(buffer.data(), arr, bytelen) == 0; } // Checks whether arrays are equal template static bool isArrayEqual(const T *arr1, const T *arr2, const std::size_t len) { return std::equal(arr1, arr1 + len, arr2); } // Checks whether type has all special member functions template static bool isRegular() { return std::is_default_constructible::value && std::is_copy_constructible::value && std::is_copy_assignable::value && std::is_move_constructible::value && std::is_move_assignable::value && std::is_destructible::value; //std::is_nothrow_swappable::value; C++17 } // Checks whether ptr is equal to nullptr template static bool isNullptr(const T *ptr) { return ptr == nullptr; } class TmpFILE { std::string tmpFilename; public: TmpFILE(); TmpFILE(const TmpFILE&) = delete; TmpFILE& operator=(const TmpFILE&) = delete; TmpFILE(TmpFILE&&) = default; TmpFILE& operator=(TmpFILE&&) = default; ~TmpFILE() {std::remove(tmpFilename.c_str()); } const char* getFilename() const { return tmpFilename.c_str(); } const std::string& getFilenameStr() const { return tmpFilename; } }; }; // namespace test }; // namespace pymol