#pragma once #include namespace DB { class Stmt; /** * @brief A smart pointer class extended from std::shared_ptr * * @tparam T Type of the pointer * @warning This class is only for internal use(Session, Stmt and so on). * So do not use this class directly, use std::shared_ptr instead. */ template class SharedPointer : public std::shared_ptr { public: SharedPointer(T* ptr = nullptr) : std::shared_ptr(ptr) {} SharedPointer(const std::shared_ptr& ptr) : std::shared_ptr(ptr) {} SharedPointer(std::shared_ptr&& ptr) : std::shared_ptr(ptr) {} SharedPointer(const SharedPointer& other) : std::shared_ptr(other) {} SharedPointer(SharedPointer&& other) : std::shared_ptr(other) {} ~SharedPointer() { } inline SharedPointer& operator=(const SharedPointer& other) { std::shared_ptr::operator=(other); return *this; } inline SharedPointer& operator=(SharedPointer&& other) noexcept { std::shared_ptr::operator=(other); return *this; } template inline SharedPointer operator<<(const U& v) { auto ptr = std::shared_ptr::get(); if (!ptr) throw std::runtime_error("The pointer is nullptr"); //Logger("DBG").debug("operator<< {}", (void*)ptr); return (*ptr) << v; } template inline SharedPointer operator>>(U& v) { auto ptr = std::shared_ptr::get(); if (!ptr) throw std::runtime_error("The pointer is nullptr"); return (*ptr) >> v; } template inline SharedPointer operator,(U v) { auto ptr = std::shared_ptr::get(); if (!ptr) throw std::runtime_error("The pointer is nullptr"); return ptr->operator,(v); } }; } // namespace DB