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,34 @@
#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,26 @@
#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 <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "ovbt_sg_defines.h"
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, hexa;
while (file >> name >> id >> hexa)
{
SStimulation tmp = { name, id, hexa };
stimulations.push_back(tmp);
}
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,39 @@
#include "ovbt_sg_defines.h"
#include <fstream>
std::string getBrutHexaCode(const 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;
}