diff options
Diffstat (limited to 'compiler/luci/tester/src/Model.cpp')
-rw-r--r-- | compiler/luci/tester/src/Model.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/compiler/luci/tester/src/Model.cpp b/compiler/luci/tester/src/Model.cpp new file mode 100644 index 000000000..b02c19161 --- /dev/null +++ b/compiler/luci/tester/src/Model.cpp @@ -0,0 +1,62 @@ +#include "Model.h" + +#include <fstream> +#include <vector> + +#include <fcntl.h> +#include <unistd.h> +#include <sys/stat.h> + +namespace +{ + +class FileModel final : public luci::Model +{ +public: + explicit FileModel(const std::string &filename) : _filename(filename) {} + +public: + FileModel(const FileModel &) = delete; + FileModel(FileModel &&) = delete; + +public: + const ::circle::Model *model(void) override + { + std::ifstream file(_filename, std::ios::binary | std::ios::in); + if (!file.good()) + return nullptr; + + file.unsetf(std::ios::skipws); + + std::streampos fileSize; + file.seekg(0, std::ios::end); + fileSize = file.tellg(); + file.seekg(0, std::ios::beg); + + // reserve capacity + _data.reserve(fileSize); + + // read the data + file.read(_data.data(), fileSize); + if (file.fail()) + return nullptr; + + return ::circle::GetModel(_data.data()); + } + +private: + const std::string _filename; + std::vector<char> _data; +}; + +} // namespace + +namespace luci +{ + +std::unique_ptr<Model> load_model(const std::string &path) +{ + return std::make_unique<FileModel>(path); +} + +} // namespace luci |