#ifndef AFUN_TOOL_DLC_INLINE_H #define AFUN_TOOL_DLC_INLINE_H #ifdef __cplusplus #include "tool_dlc.h" #ifndef AFUN_TOOL_C namespace aFuntool { #endif template DlcSymbol DlcHandle::getSymbol(const std::string &name){ return handle_ != nullptr ? handle_->getSymbol(name) : DlcSymbol(); } DlcHandle::~DlcHandle() noexcept { this->close(); } bool DlcHandle::isOpen() const { return handle_ != nullptr ? handle_->isOpen() : false; } void DlcHandle::close(){ if (handle_ == nullptr) return; (*handle_)--; handle_ = nullptr; } int DlcHandle::operator++(int){ return (*handle_)++; } int DlcHandle::operator--(int){ return (*handle_)--; } DlcHandle &DlcHandle::operator=(const DlcHandle &dlc_handle) noexcept { if (&dlc_handle == this) return *this; this->close(); handle_ = dlc_handle.handle_; if (handle_ != nullptr) (*handle_)++; return *this; } DlcHandle::DlcHandle(const DlcHandle &dlc_handle) noexcept { handle_ = dlc_handle.handle_; if (handle_ != nullptr) (*handle_)++; } DlcHandle::DlcHandle(DlcHandle &&dlc_handle)noexcept { handle_ = dlc_handle.handle_; dlc_handle.handle_ = nullptr; } template DlcSymbol DlcHandle::Handle::getSymbol(const std::string &name){ if (handle_ == nullptr) return DlcSymbol(); auto symbol = (SYMBOL *)dlsym(handle_, name.c_str()); if (symbol == nullptr) return DlcSymbol(); return DlcSymbol(symbol, this); } bool DlcHandle::Handle::isOpen() const { return handle_ != nullptr; } #ifndef AFUN_TOOL_C } #endif #endif #endif //AFUN_TOOL_DLC_INLINE_H