Removed comment header and global scope operators

This commit is contained in:
Bob Polis 2022-09-14 09:55:51 +02:00
parent e7bb903f03
commit e44b5c79c3

View File

@ -1,11 +1,3 @@
//
// plugin.hpp
// plugins
//
// Created by Bob Polis at 2019-06-09
// Copyright (c) 2019 SwiftCoder. All rights reserved.
//
#ifndef _plugin_H_ #ifndef _plugin_H_
#define _plugin_H_ #define _plugin_H_
@ -25,10 +17,10 @@ namespace sc {
class plugin { class plugin {
public: public:
static void scan_plugins(const std::string& dir, const std::string& ext) { static void scan_plugins(const std::string& dir, const std::string& ext) {
DIR* plugins_dir = ::opendir(dir.c_str()); DIR* plugins_dir = opendir(dir.c_str());
throw_if_null_msg(plugins_dir, (dir + " could not be opened").c_str()); throw_if_null_msg(plugins_dir, (dir + " could not be opened").c_str());
struct dirent* info; struct dirent* info;
while ((info = ::readdir(plugins_dir)) != nullptr) { while ((info = readdir(plugins_dir)) != nullptr) {
if (info->d_name[0] != '.') { if (info->d_name[0] != '.') {
std::string plugname {info->d_name}; std::string plugname {info->d_name};
std::string::size_type lastdot = plugname.rfind("."); std::string::size_type lastdot = plugname.rfind(".");
@ -39,7 +31,7 @@ namespace sc {
} }
} }
} }
throw_if_min1(::closedir(plugins_dir)); throw_if_min1(closedir(plugins_dir));
} }
using processor = std::function<void(const plugin&)>; using processor = std::function<void(const plugin&)>;
@ -64,12 +56,12 @@ namespace sc {
static size_t count() { return plugins.size(); } static size_t count() { return plugins.size(); }
plugin(const std::string& path) : _path {path} { plugin(const std::string& path) : _path {path} {
_plugin = ::dlopen(path.c_str(), RTLD_LAZY); _plugin = dlopen(path.c_str(), RTLD_LAZY);
const char* err {::dlerror()}; const char* err {dlerror()};
if (err) std::cerr << err << '\n'; if (err) std::cerr << err << '\n';
if (_plugin) { if (_plugin) {
_factory = reinterpret_cast<factory>(::dlsym(_plugin, "create_instance")); _factory = reinterpret_cast<factory>(dlsym(_plugin, "create_instance"));
if (!_factory) { if (!_factory) {
std::cerr << "create_instance() function not found in " << path << '\n'; std::cerr << "create_instance() function not found in " << path << '\n';
} }
@ -78,7 +70,7 @@ namespace sc {
~plugin() { ~plugin() {
if (_plugin) { if (_plugin) {
::dlclose(_plugin); dlclose(_plugin);
_plugin = nullptr; _plugin = nullptr;
} }
} }