2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
29 class FileModel final : public luci::Model
32 explicit FileModel(const std::string &filename) : _filename(filename) {}
35 FileModel(const FileModel &) = delete;
36 FileModel(FileModel &&) = delete;
39 const ::circle::Model *model(void) override
41 std::ifstream file(_filename, std::ios::binary | std::ios::in);
45 file.unsetf(std::ios::skipws);
47 std::streampos fileSize;
48 file.seekg(0, std::ios::end);
49 fileSize = file.tellg();
50 file.seekg(0, std::ios::beg);
53 _data.reserve(fileSize);
56 file.read(_data.data(), fileSize);
60 return ::circle::GetModel(_data.data());
64 const std::string _filename;
65 std::vector<char> _data;
73 std::unique_ptr<Model> load_model(const std::string &path)
75 return std::unique_ptr<Model>{new FileModel(path)};