<commit_before>//
// ulib - a collection of useful classes
// Copyright (C) 2000-2020 <NAME>
//
/// \file DynamicLibrary.hpp dynamic library loading
//
#pragma once

/// dynamic library loading
class DynamicLibrary
{
public:
   /// ctor; loads module
   explicit DynamicLibrary(LPCTSTR moduleFilename)
      :m_module(LoadLibrary(moduleFilename))
   {
   }

   /// copy ctor; not available
   DynamicLibrary(const DynamicLibrary& other) = delete;

   // move ctor
   DynamicLibrary(DynamicLibrary&& other) noexcept
      :m_module(std::move(other.m_module))
   {
   }

   /// dtor; frees module again
   ~DynamicLibrary()
   {
      FreeLibrary(m_module);
   }

   /// copy assignment operator; not available
   DynamicLibrary& operator=(const DynamicLibrary& other) = delete;

   /// move assignment operator
   DynamicLibrary& operator=(DynamicLibrary&& other) noexcept
   {
      m_module = std::move(other.m_module);
      return *this;
   }

   /// checks if library is loaded
   bool IsLoaded() const { return m_module != nullptr; }

   /// checks if function with given name is available
   bool IsFunctionAvail(LPCSTR functionName) const
   {
      return GetProcAddress(m_module, functionName) != nullptr;
   }

   /// returns function with given function name and given function signature
   template <typename Signature>
   Signature GetFunction(LPCSTR functionName)
   {
      return reinterpret_cast<Signature>(GetProcAddress(m_module, functionName));
   }

private:
   /// dynamic library module handle
   HMODULE m_module;
};<commit_msg>reimplemented DynamicLibrary using std::shared_ptr for module handle<commit_after>//
// ulib - a collection of useful classes
// Copyright (C) 2000-2020 <NAME>
//
/// \file DynamicLibrary.hpp dynamic library loading
//
#pragma once

/// dynamic library loading
class DynamicLibrary
{
public:
   /// ctor; loads module
   explicit DynamicLibrary(LPCTSTR moduleFilename)
      :m_module(LoadLibrary(moduleFilename), &FreeLibrary)
   {
   }

   /// checks if library is loaded
   bool IsLoaded() const { return m_module != nullptr; }

   /// checks if function with given name is available
   bool IsFunctionAvail(LPCSTR functionName) const
   {
      return IsLoaded() &&
         GetProcAddress(GetModule(), functionName) != nullptr;
   }

   /// returns function with given function name and given function signature
   template <typename Signature>
   Signature GetFunction(LPCSTR functionName) const
   {
      return reinterpret_cast<Signature>(GetProcAddress(GetModule(), functionName));
   }

   /// returns module handle of library
   HMODULE GetModule() const { return reinterpret_cast<HMODULE>(m_module.get()); }

private:
   /// dynamic library module handle
   std::shared_ptr<void> m_module;
};
{'fraction_non_alphanumeric': 0.10119695321001088, 'fraction_numerical': 0.005803409503083061, 'mean_word_length': 3.4198717948717947, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '912084', 'n_tokens_mistral': 787, 'n_tokens_neox': 745, 'n_words': 228}