OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Index Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Config/Version.hpp>

Collaboration diagram for Index:

Public Types

typedef std::vector< Version >::const_iterator const_iterator

Public Member Functions

size_t load (const boost::filesystem::path &path)
const std::string & vendor () const
Semver version () const
const_iterator begin () const
const_iterator end () const
const_iterator find (const Semver &ver) const
const std::vector< Version > & configs () const
const_iterator recommended () const
const_iterator recommended (const Semver &slic3r_version) const
const boost::filesystem::path & path () const

Static Public Member Functions

static std::vector< Index > load_db ()

Private Attributes

std::string m_vendor
std::vector< Version > m_configs
boost::filesystem::path m_path

Detailed Description

Member Typedef Documentation

◆ const_iterator

typedef std::vector<Version>::const_iterator Slic3r::GUI::Config::Index::const_iterator

Member Function Documentation

◆ begin()

67{ return m_configs.begin(); }
std::vector< Version > m_configs
Definition Version.hpp:87

◆ configs()

const std::vector< Version > & Slic3r::GUI::Config::Index::configs ( ) const
inline
70{ return m_configs; }

◆ end()

68{ return m_configs.end(); }

◆ find()

296{
297 Version key;
298 key.config_version = ver;
299 auto it = std::lower_bound(m_configs.begin(), m_configs.end(), key,
300 [](const Version &v1, const Version &v2) { return v1.config_version < v2.config_version; });
301 return (it == m_configs.end() || it->config_version == ver) ? it : m_configs.end();
302}
@ Version
Definition PluginSort.hpp:22
Semver config_version
Definition Version.hpp:20

◆ load()

size_t Slic3r::GUI::Config::Index::load ( const boost::filesystem::path & path)
206{
207 m_configs.clear();
208 m_vendor = path.stem().string();
209 m_path = path;
210
211 boost::nowide::ifstream ifs(path.string());
212 std::string line;
213 size_t idx_line = 0;
214 Version ver;
215 while (std::getline(ifs, line)) {
216#ifndef _MSVCVER
217 // On a Unix system, getline does not remove the trailing carriage returns, if the index is shared over a Windows filesystem. Remove them manually.
218 while (! line.empty() && line.back() == '\r')
219 line.pop_back();
220#endif
221 ++ idx_line;
222 // Skip the initial white spaces.
223 char *key = left_trim(line.data());
224 if (*key == '#')
225 // Skip a comment line.
226 continue;
227 // Right trim the line.
228 char *end = right_trim(key);
229 if (key == end)
230 // Skip an empty line.
231 continue;
232 // Keyword may only contain alphanumeric characters. Semantic version may in addition contain "+.-".
233 char *key_end = key;
234 bool maybe_semver = true;
235 for (; *key_end != 0; ++ key_end) {
236 if (std::isalnum(*key_end) || strchr("+.-", *key_end) != nullptr) {
237 // It may be a semver.
238 } else if (*key_end == '_') {
239 // Cannot be a semver, but it may be a key.
240 maybe_semver = false;
241 } else
242 // End of semver or keyword.
243 break;
244 }
245 if (*key_end != 0 && *key_end != ' ' && *key_end != '\t' && *key_end != '=')
246 throw file_parser_error("Invalid keyword or semantic version", path, idx_line);
247 char *value = left_trim(key_end);
248 bool key_value_pair = *value == '=';
249 if (key_value_pair)
250 value = left_trim(value + 1);
251 *key_end = 0;
252 boost::optional<Semver> semver;
253 if (maybe_semver)
254 semver = Semver::parse(key);
255 if (key_value_pair) {
256 if (semver)
257 throw file_parser_error("Key cannot be a semantic version", path, idx_line);\
258 // Verify validity of the key / value pair.
259 std::string svalue = unquote_value(value, end, path.string(), idx_line);
260 if (strcmp(key, "min_slic3r_version") == 0 || strcmp(key, "max_slic3r_version") == 0) {
261 if (! svalue.empty())
262 semver = Semver::parse(svalue);
263 if (! semver)
264 throw file_parser_error(std::string(key) + " must referece a valid semantic version", path, idx_line);
265 if (strcmp(key, "min_slic3r_version") == 0)
266 ver.min_slic3r_version = *semver;
267 else
268 ver.max_slic3r_version = *semver;
269 } else {
270 // Ignore unknown keys, as there may come new keys in the future.
271 }
272 continue;
273 }
274 if (! semver)
275 throw file_parser_error("Invalid semantic version", path, idx_line);
276 ver.config_version = *semver;
277 ver.comment = (end <= key_end) ? "" : unquote_version_comment(value, end, path.string(), idx_line);
278 m_configs.emplace_back(ver);
279 }
280
281 // Sort the configs by their version.
282 std::sort(m_configs.begin(), m_configs.end(), [](const Version &v1, const Version &v2) { return v1.config_version < v2.config_version; });
283 return m_configs.size();
284}
std::string m_vendor
Definition Version.hpp:86
const boost::filesystem::path & path() const
Definition Version.hpp:79
boost::filesystem::path m_path
Definition Version.hpp:88
const_iterator end() const
Definition Version.hpp:68
char * left_trim(char *c)
Definition Version.cpp:159
std::string unquote_version_comment(char *value, char *end, const std::string &path, int idx_line)
Definition Version.cpp:189
char * right_trim(char *start)
Definition Version.cpp:165
std::string unquote_value(char *value, char *end, const std::string &path, int idx_line)
Definition Version.cpp:173
Semver min_slic3r_version
Definition Version.hpp:22
std::string comment
Definition Version.hpp:28
Semver max_slic3r_version
Definition Version.hpp:26

◆ load_db()

std::vector< Index > Slic3r::GUI::Config::Index::load_db ( )
static
320{
321 boost::filesystem::path cache_dir = boost::filesystem::path(Slic3r::data_dir()) / "ota";
322
323 std::vector<Index> index_db;
324 std::string errors_cummulative;
325 for (auto &dir_entry : boost::filesystem::directory_iterator(cache_dir))
326 if (Slic3r::is_idx_file(dir_entry)) {
327 Index idx;
328 try {
329 idx.load(dir_entry.path());
330 } catch (const std::runtime_error &err) {
331 errors_cummulative += err.what();
332 errors_cummulative += "\n";
333 continue;
334 }
335 index_db.emplace_back(std::move(idx));
336 }
337
338 if (! errors_cummulative.empty())
339 throw Slic3r::RuntimeError(errors_cummulative);
340 return index_db;
341}
size_t load(const boost::filesystem::path &path)
Definition Version.cpp:205
const std::string & data_dir()
Definition utils.cpp:365
bool is_idx_file(const boost::filesystem::directory_entry &dir_entry)
Definition utils.cpp:1202

◆ path()

const boost::filesystem::path & Slic3r::GUI::Config::Index::path ( ) const
inline
79{ return m_path; }

◆ recommended() [1/2]

315{
316 return this->recommended(Slic3r::SEMVER);
317}
const_iterator recommended() const
Definition Version.cpp:314
Semver SEMVER
Definition Semver.cpp:6

◆ recommended() [2/2]

Index::const_iterator Slic3r::GUI::Config::Index::recommended ( const Semver & slic3r_version) const
305{
306 const_iterator highest = this->end();
307 for (const_iterator it = this->begin(); it != this->end(); ++ it)
308 if (it->is_slic3r_supported(slic3r_version) &&
309 (highest == this->end() || highest->config_version < it->config_version))
310 highest = it;
311 return highest;
312}
const_iterator begin() const
Definition Version.hpp:67
std::vector< Version >::const_iterator const_iterator
Definition Version.hpp:57

◆ vendor()

const std::string & Slic3r::GUI::Config::Index::vendor ( ) const
inline
62{ return m_vendor; }

◆ version()

287{
288 Semver ver = Semver::zero();
289 for (const Version &cv : m_configs)
290 if (cv.config_version >= ver)
291 ver = cv.config_version;
292 return ver;
293}

Member Data Documentation

◆ m_configs

◆ m_path

boost::filesystem::path Slic3r::GUI::Config::Index::m_path
private

◆ m_vendor


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Config/Version.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Config/Version.cpp