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 ...@@ -185,7 +185,7 @@ SET(HDRS_UTILS
include/core/utils/converter.h include/core/utils/converter.h
include/core/utils/eigen_assert.h include/core/utils/eigen_assert.h
include/core/utils/eigen_predicates.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/logging.h
include/core/utils/make_unique.h include/core/utils/make_unique.h
include/core/utils/params_server.h include/core/utils/params_server.h
...@@ -322,6 +322,7 @@ SET(SRCS_MATH ...@@ -322,6 +322,7 @@ SET(SRCS_MATH
SET(SRCS_UTILS SET(SRCS_UTILS
src/utils/converter_utils.cpp src/utils/converter_utils.cpp
src/utils/params_server.cpp src/utils/params_server.cpp
src/utils/loader.cpp
) )
SET(SRCS_CAPTURE SET(SRCS_CAPTURE
......
#ifndef LOADER_HPP #ifndef LOADER_H
#define LOADER_HPP #define LOADER_H
#include <dlfcn.h>
#include <string> #include <string>
#include <stdexcept>
class Loader{ class Loader{
protected: protected:
std::string path_; std::string path_;
public: public:
Loader(std::string _file){ Loader(std::string _file);
this->path_ = _file;
}
virtual void load() = 0; virtual void load() = 0;
virtual void close() = 0; virtual void close() = 0;
}; };
class LoaderRaw: public Loader{ class LoaderRaw: public Loader{
void* resource_; void* resource_;
public: public:
LoaderRaw(std::string _file): LoaderRaw(std::string _file);
Loader(_file) ~LoaderRaw();
{ void load();
// void close();
}
~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_);
}
}; };
// class LoaderPlugin: public Loader{ // class LoaderPlugin: public Loader{
// ClassLoader* resource_; // ClassLoader* resource_;
...@@ -42,4 +29,4 @@ public: ...@@ -42,4 +29,4 @@ public:
// delete this->resource_; // delete this->resource_;
// } // }
// }; // };
#endif #endif
\ No newline at end of file
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "core/state_block/state_block.h" #include "core/state_block/state_block.h"
#include "core/utils/logging.h" #include "core/utils/logging.h"
#include "core/utils/params_server.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/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