ONE - On-device Neural Engine
Loading...
Searching...
No Matches
foder::FileLoader Class Reference

#include <FileLoader.h>

Public Member Functions

 FileLoader (const std::string &path)
 
 FileLoader (const FileLoader &)=delete
 
FileLoaderoperator= (const FileLoader &)=delete
 
DataBuffer load (void) const
 

Detailed Description

Definition at line 26 of file FileLoader.h.

Constructor & Destructor Documentation

◆ FileLoader() [1/2]

foder::FileLoader::FileLoader ( const std::string &  path)
inlineexplicit

Definition at line 32 of file FileLoader.h.

32: _path(path) {}

◆ FileLoader() [2/2]

foder::FileLoader::FileLoader ( const FileLoader )
delete

Member Function Documentation

◆ load()

DataBuffer foder::FileLoader::load ( void  ) const
inline

Definition at line 39 of file FileLoader.h.

40 {
41 std::ifstream file(_path, std::ios::binary | std::ios::in);
42 if (!file.good())
43 {
44 std::string errmsg = "Failed to open file: " + _path;
45 throw std::runtime_error(errmsg.c_str());
46 }
47
48 file.unsetf(std::ios::skipws);
49
50 file.seekg(0, std::ios::end);
51 auto fileSize = file.tellg();
52 file.seekg(0, std::ios::beg);
53
54 // reserve capacity
55 DataBuffer data(fileSize);
56
57 // read the data
58 file.read(data.data(), fileSize);
59 if (file.fail())
60 {
61 std::string errmsg = "Failed to read file: " + _path;
62 throw std::runtime_error(errmsg.c_str());
63 }
64
65 return data;
66 }

Referenced by entry(), crew::read_ini(), and VerifyFlatbuffers::run().

◆ operator=()

FileLoader & foder::FileLoader::operator= ( const FileLoader )
delete

The documentation for this class was generated from the following file: