diff options
author | leo <[email protected]> | 2022-02-10 16:46:40 +0300 |
---|---|---|
committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:46:40 +0300 |
commit | 99609724f661f7e21d1cb08e8d80e87c3632fdb3 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /util/system/dynlib.h | |
parent | 980edcd3304699edf9d4e4d6a656e585028e2a72 (diff) |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'util/system/dynlib.h')
-rw-r--r-- | util/system/dynlib.h | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/util/system/dynlib.h b/util/system/dynlib.h index ef4ab298232..66eaf4a5c1c 100644 --- a/util/system/dynlib.h +++ b/util/system/dynlib.h @@ -1,5 +1,5 @@ #pragma once - + #include "defaults.h" #include <util/generic/ptr.h> @@ -7,7 +7,7 @@ #define Y_GET_FUNC(dll, name) FUNC_##name((dll).Sym(#name)) #define Y_GET_FUNC_OPTIONAL(dll, name) FUNC_##name((dll).SymOptional(#name)) - + #ifdef _win32_ #define DEFAULT_DLLOPEN_FLAGS 0 #else @@ -25,95 +25,95 @@ public: TDynamicLibrary() noexcept; TDynamicLibrary(const TString& path, int flags = DEFAULT_DLLOPEN_FLAGS); ~TDynamicLibrary(); - + void Open(const char* path, int flags = DEFAULT_DLLOPEN_FLAGS); void Close() noexcept; void* SymOptional(const char* name) noexcept; void* Sym(const char* name); bool IsLoaded() const noexcept; void SetUnloadable(bool unloadable); // Set to false to avoid unloading on destructor - + private: class TImpl; THolder<TImpl> Impl_; -}; - -// a wrapper for a symbol -template <class TLib> +}; + +// a wrapper for a symbol +template <class TLib> class TExternalSymbol { -private: +private: TLib* PLib; TDynamicLibrary* DLib; TString lname; TString vname; -public: +public: TExternalSymbol() noexcept { PLib = nullptr; DLib = nullptr; - } + } TExternalSymbol(const TExternalSymbol& es) { PLib = nullptr; DLib = nullptr; - if (es.IsDynamic()) + if (es.IsDynamic()) Open(es.LibName().data(), es.VtblName().data()); - else if (es.IsStatic()) - SetSym(es.Symbol()); - } + else if (es.IsStatic()) + SetSym(es.Symbol()); + } TExternalSymbol& operator=(const TExternalSymbol& es) { - if (this != &es) { - Close(); - if (es.IsDynamic()) + if (this != &es) { + Close(); + if (es.IsDynamic()) Open(es.LibName().data(), es.VtblName().data()); - else if (es.IsStatic()) - SetSym(es.Symbol()); - } - return *this; - } + else if (es.IsStatic()) + SetSym(es.Symbol()); + } + return *this; + } ~TExternalSymbol() { - delete DLib; - } - // set the symbol from dynamic source + delete DLib; + } + // set the symbol from dynamic source void Open(const char* lib_name, const char* vtbl_name) { if (DLib != nullptr || PLib != nullptr) - return; - try { - DLib = new TDynamicLibrary(); - DLib->Open(lib_name); + return; + try { + DLib = new TDynamicLibrary(); + DLib->Open(lib_name); PLib = (TLib*)DLib->Sym(vtbl_name); } catch (...) { - delete DLib; + delete DLib; DLib = nullptr; - throw; - } - lname = lib_name; - vname = vtbl_name; - } - // set the symbol from static source + throw; + } + lname = lib_name; + vname = vtbl_name; + } + // set the symbol from static source void SetSym(TLib* pl) noexcept { if (DLib == nullptr && PLib == nullptr) - PLib = pl; - } + PLib = pl; + } void Close() noexcept { - delete DLib; - DLib = 0; - PLib = 0; - lname.remove(); - vname.remove(); - } + delete DLib; + DLib = 0; + PLib = 0; + lname.remove(); + vname.remove(); + } TLib* Symbol() const noexcept { - return PLib; - } + return PLib; + } const TString& LibName() const noexcept { - return lname; - } + return lname; + } const TString& VtblName() const noexcept { - return vname; - } + return vname; + } bool IsStatic() const noexcept { return DLib == nullptr && PLib != nullptr; - } + } bool IsDynamic() const noexcept { return DLib && DLib->IsLoaded() && PLib != nullptr; - } -}; + } +}; |