Skip to content
Snippets Groups Projects
Commit a6d764bd authored by Joaquim Casals Buñuel's avatar Joaquim Casals Buñuel
Browse files

Split loader.hpp -> {.h, .cpp}

parent 409fdcf1
No related branches found
No related tags found
No related merge requests found
Pipeline #5067 passed
......@@ -185,7 +185,7 @@ SET(HDRS_UTILS
include/core/utils/converter.h
include/core/utils/eigen_assert.h
include/core/utils/eigen_predicates.h
include/core/utils/loader.hpp
include/core/utils/loader.h
include/core/utils/logging.h
include/core/utils/make_unique.h
include/core/utils/params_server.h
......@@ -322,6 +322,7 @@ SET(SRCS_MATH
SET(SRCS_UTILS
src/utils/converter_utils.cpp
src/utils/params_server.cpp
src/utils/loader.cpp
)
SET(SRCS_CAPTURE
......
#ifndef LOADER_HPP
#define LOADER_HPP
#include <dlfcn.h>
#ifndef LOADER_H
#define LOADER_H
#include <string>
#include <stdexcept>
class Loader{
protected:
std::string path_;
public:
Loader(std::string _file){
this->path_ = _file;
}
Loader(std::string _file);
virtual void load() = 0;
virtual void close() = 0;
};
class LoaderRaw: public Loader{
void* resource_;
public:
LoaderRaw(std::string _file):
Loader(_file)
{
//
}
~LoaderRaw(){
this->close();
}
void load(){
this->resource_ = dlopen(this->path_.c_str(), RTLD_LAZY);
if(not this->resource_)
throw std::runtime_error("Couldn't load resource with path " + this->path_ + "\n" + "Error info: " + dlerror());
}
void close(){
if(this->resource_) dlclose(this->resource_);
}
LoaderRaw(std::string _file);
~LoaderRaw();
void load();
void close();
};
// class LoaderPlugin: public Loader{
// ClassLoader* resource_;
......@@ -42,4 +29,4 @@ public:
// delete this->resource_;
// }
// };
#endif
\ No newline at end of file
#endif
......@@ -13,7 +13,7 @@
#include "core/state_block/state_block.h"
#include "core/utils/logging.h"
#include "core/utils/params_server.h"
#include "core/utils/loader.hpp"
#include "core/utils/loader.h"
#include "core/utils/check_log.hpp"
......
#include "core/utils/loader.h"
#include <dlfcn.h>
#include <stdexcept>
Loader::Loader(std::string _file)
{
path_ = _file;
}
LoaderRaw::LoaderRaw(std::string _file) : Loader(_file)
{
//
}
LoaderRaw::~LoaderRaw()
{
close();
}
void LoaderRaw::load()
{
resource_ = dlopen(path_.c_str(), RTLD_LAZY);
if (not resource_)
throw std::runtime_error("Couldn't load resource with path " + path_ + "\n" + "Error info: " + dlerror());
}
void LoaderRaw::close()
{
if (resource_)
dlclose(resource_);
}
// class LoaderPlugin: public Loader{
// ClassLoader* resource_;
// void load(){
// resource_ = new ClassLoader(path_);
// }
// void close(){
// delete resource_;
// }
// };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment