Skip to content
Snippets Groups Projects
Commit 1b43f4bb authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

add missing compcache files

parent 77920c76
No related branches found
No related tags found
No related merge requests found
#include "compcache.h"
#include <string>
#include <vector>
#include <map>
#include <complex>
#include <dlfcn.h>
using namespace eis;
std::string eis::getTempdir()
{
char* tmpEnv = getenv("TMP");
char* tempEnv = getenv("TEMP");
char* tempDirEnv = getenv("TEMPDIR");
std::filesystem::path path;
if(tmpEnv && std::string(tmpEnv).length() > 1)
path = tmpEnv;
else if(tempEnv && std::string(tempEnv).length() > 1)
path = tempEnv;
else if(tempDirEnv && std::string(tempDirEnv).length() > 1)
path = tempDirEnv;
else
path = "/tmp";
path = path/"eis_models";
if(!std::filesystem::is_directory(path))
{
if(!std::filesystem::create_directory(path))
throw std::runtime_error(path.string() +
"is not a directory and a directory can not be created at this locaion");
}
return path.string();
}
CompCache* CompCache::getInstance()
{
if(!instance)
instance = new CompCache();
return instance;
}
bool CompCache::addObject(size_t uuid, const CompiledObject& object)
{
CompiledObject* foundobject = getObject(uuid);
if(foundobject)
return false;
objects.insert({uuid, new CompiledObject(object)});
return true;
}
CompiledObject* CompCache::getObject(size_t uuid)
{
auto search = objects.find(uuid);
if(search == objects.end())
return nullptr;
else
return search->second;
}
void CompCache::dropAllObjects()
{
for(std::pair<size_t, CompiledObject*> object : objects)
{
dlclose(object.second->objectCode);
delete object.second;
}
objects.clear();
}
#include <string>
#include <vector>
#include <map>
#include <complex>
#include "eistype.h"
namespace eis
{
std::string getTempdir();
struct CompiledObject
{
void* objectCode;
std::vector<std::complex<fvalue>>(*symbol)(const std::vector<fvalue>&, const std::vector<fvalue>&);
};
class CompCache
{
public:
private:
inline static CompCache* instance = nullptr;
std::map<size_t, CompiledObject*> objects;
CompCache() {};
public:
static CompCache* getInstance();
CompCache(const CompCache&) = delete;
CompCache& operator=(const CompCache&) = delete;
bool addObject(size_t uuid, const CompiledObject& object);
CompiledObject* getObject(size_t uuid);
void dropAllObjects();
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment