This commit is contained in:
2021-10-14 13:47:35 +02:00
commit 6625a8dfaa
4026 changed files with 844291 additions and 0 deletions
@@ -0,0 +1,23 @@
PROJECT(openvibe-stimulation-generator)
SET(PROJECT_VERSION_MAJOR ${OV_GLOBAL_VERSION_MAJOR})
SET(PROJECT_VERSION_MINOR ${OV_GLOBAL_VERSION_MINOR})
SET(PROJECT_VERSION_PATCH ${OV_GLOBAL_VERSION_PATCH})
SET(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
FILE(GLOB_RECURSE SRC_FILES src/*.cpp src/*.h src/*.inl)
ADD_EXECUTABLE(openvibe-stimulation-generator ${SRC_FILES})
# if(UNIX)
# SET(stim_generator_path "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "stim_generator_path")
# else()
# get_property(path_to_target TARGET openvibe-stimulation-generator PROPERTY LOCATION)
# SET(stim_generator_path "${path_to_target}" CACHE INTERNAL "stim_generator_path")
# MESSAGE(STATUS "MOO ${stim_generator_path}")
#endif()
# ---------------------------------
# Target macros
# Defines target operating system, architecture and compiler
# ---------------------------------
SET_BUILD_PLATFORM()
@@ -0,0 +1,32 @@
#include "ovbt_sg_defines.h"
#include <fstream>
bool CCppCodeGenerator::openFile(const char* filename)
{
m_file.open(filename, std::ios::out | std::ios::trunc);
if (!m_file.is_open()) { return false; }
m_file << "#include \"toolkit/ovtk_all.h\"" << std::endl << std::endl;
m_file << "using namespace OpenViBE;" << std::endl;
m_file << "using namespace /*OpenViBE::*/Kernel;" << std::endl;
m_file << "using namespace /*OpenViBE::*/Toolkit;" << std::endl << std::endl << std::endl;
m_file << "bool Toolkit::initializeStimulationList(const Kernel::IKernelContext& ctx)" << std::endl;
m_file << "{" << std::endl;
m_file << "\tITypeManager& typeManager=ctx.getTypeManager();" << std::endl << std::endl;
return true;
}
bool CCppCodeGenerator::appendStimulation(SStimulation& stim)
{
m_file << "\ttypeManager.registerEnumerationEntry(OV_TypeId_Stimulation, \"" << stim.name << "\", " << stim.id << ");" << std::endl;
return true;
}
bool CCppCodeGenerator::closeFile()
{
m_file << std::endl << "\treturn true;" << std::endl << "}" << std::endl;
m_file.close();
return true;
}
@@ -0,0 +1,25 @@
#include "ovbt_sg_defines.h"
#include <fstream>
bool CCppDefineGenerator::openFile(const char* filename)
{
m_file.open(filename, std::ios::out | std::ios::trunc);
if (!m_file.is_open()) { return false; }
m_file << "#pragma once" << std::endl << std::endl;
return true;
}
bool CCppDefineGenerator::appendStimulation(SStimulation& stim)
{
m_file << "#define " << stim.id << " " << stim.hexa << std::endl;
return true;
}
bool CCppDefineGenerator::closeFile()
{
m_file << std::endl;
m_file.close();
return true;
}
@@ -0,0 +1,47 @@
#pragma once
#include <string>
#include <fstream>
struct SStimulation
{
std::string name;
std::string id;
std::string hexa;
};
class CFileGeneratorBase
{
public:
virtual ~CFileGeneratorBase() = default;
virtual bool openFile(const char* filename) = 0;
virtual bool appendStimulation(SStimulation& stim) = 0;
virtual bool closeFile() = 0;
protected:
std::ofstream m_file;
};
class CCppDefineGenerator final : public CFileGeneratorBase
{
public:
bool openFile(const char* filename) override;
bool appendStimulation(SStimulation& stim) override;
bool closeFile() override;
};
class CCppCodeGenerator final : public CFileGeneratorBase
{
public:
bool openFile(const char* filename) override;
bool appendStimulation(SStimulation& stim) override;
bool closeFile() override;
};
class CMatlabGenerator final : public CFileGeneratorBase
{
public:
bool openFile(const char* filename) override;
bool appendStimulation(SStimulation& stim) override;
bool closeFile() override;
};
@@ -0,0 +1,89 @@
#include "ovbt_sg_defines.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
enum class EGenerationTypes { CPP, MATLAB, PYTHON, LUA, UNKNOWN };
EGenerationTypes parse_argument(std::string option)
{
if (option == "--cpp") { return EGenerationTypes::CPP; }
if (option == "--matlab") { return EGenerationTypes::MATLAB; }
if (option == "--python") { return EGenerationTypes::PYTHON; }
if (option == "--lua") { return EGenerationTypes::LUA; }
return EGenerationTypes::UNKNOWN;
}
int generate_generator_list(std::vector<CFileGeneratorBase*>& list, EGenerationTypes type, int argc, char** argv)
{
switch (type)
{
case EGenerationTypes::CPP:
{
if (argc < 4) { return -1; }
CFileGeneratorBase* gen = new CCppDefineGenerator();
if (!gen->openFile(argv[3]))
{
std::cerr << "Unable to open " << argv[3] << std::endl;
return -1;
}
list.push_back(gen);
gen = new CCppCodeGenerator();
if (!gen->openFile(argv[4]))
{
std::cerr << "Unable to open " << argv[4] << std::endl;
return -1;
}
list.push_back(gen);
return 0;
}
case EGenerationTypes::MATLAB:
{
CFileGeneratorBase* gen = new CMatlabGenerator();
if (!gen->openFile(argv[3]))
{
std::cerr << "Unable to open " << argv[3] << std::endl;
return -1;
}
list.push_back(gen);
return 0;
}
case EGenerationTypes::PYTHON:
case EGenerationTypes::LUA:
case EGenerationTypes::UNKNOWN:
default:
{
std::cerr << "Unhandle type. Fatal error" << std::endl;
return -1;
}
}
}
int main(int argc, char** argv)
{
if (argc < 3) { return -1; }
EGenerationTypes type = parse_argument(argv[1]);
std::vector<SStimulation> stimulations;
std::vector<CFileGeneratorBase*> generators;
std::ifstream file(argv[2]);
std::string name, id, hexaCode;
while (file >> name >> id >> hexaCode)
{
SStimulation temp = { name, id, hexaCode };
stimulations.push_back(temp);
}
if (generate_generator_list(generators, type, argc, argv)) { return -1; }
//Now we generate all files that needs to be done
for (auto& s : stimulations) { for (auto& g : generators) { g->appendStimulation(s); } }
for (auto& g : generators) { g->closeFile(); }
return 0;
}
@@ -0,0 +1,38 @@
#include "ovbt_sg_defines.h"
#include <fstream>
std::string getBrutHexaCode(std::string formatedHexaCode)
{
std::string res = formatedHexaCode;
res.erase(res.begin(), res.begin() + 2);
return res;
}
bool CMatlabGenerator::openFile(const char* filename)
{
m_file.open(filename, std::ios::out | std::ios::trunc);
if (!m_file.is_open()) { return false; }
m_file << "function OV_stimulations()" << std::endl << std::endl;
m_file << "global OVTK_StimulationId_LabelStart;" << std::endl;
m_file << "OVTK_StimulationId_LabelStart = uint64(hex2dec('00008100'));" << std::endl << std::endl;
m_file << "global OVTK_StimulationId_LabelEnd;" << std::endl;
m_file << "OVTK_StimulationId_LabelEnd = uint64(hex2dec('000081ff'));" << std::endl << std::endl;
return true;
}
bool CMatlabGenerator::appendStimulation(SStimulation& stim)
{
m_file << "\tglobal " << stim.id << ";" << std::endl;
m_file << "\t" << stim.id << " = uint64(hex2dec('" << getBrutHexaCode(stim.hexa) << "'));" << std::endl << std::endl;
return true;
}
bool CMatlabGenerator::closeFile()
{
m_file << "end" << std::endl;
m_file.close();
return true;
}