OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::CacheDictionary Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/PresetCacheFormat.hpp>

Collaboration diagram for Slic3r::CacheDictionary:

Public Member Functions

 CacheDictionary ()
void collect (const DynamicPrintConfig &config)
uint16_t key_index (const t_config_option_key &key) const
uint16_t enum_index (const std::string &name) const
const ConfigOptionDef * def_at (uint16_t idx) const
ConfigOptionType type_at (uint16_t idx) const
const std::string & enum_name_at (uint16_t idx) const
bool valid_key_index (uint16_t idx) const
bool valid_enum_index (uint16_t idx) const
void save (cereal::BinaryOutputArchive &ar) const
void load (cereal::BinaryInputArchive &ar)

Static Public Attributes

static constexpr uint16_t ENUM_UNNAMED = 0

Private Attributes

std::vector< std::string > m_keys
std::vector< uint16_t > m_types
std::vector< std::string > m_enum_values
std::unordered_map< std::string, uint16_t > m_key_index
std::unordered_map< std::string, uint16_t > m_enum_index
std::vector< const ConfigOptionDef * > m_defs

Static Private Attributes

static constexpr size_t MAX_ENTRIES = 0xFFFF

Detailed Description

Constructor & Destructor Documentation

◆ CacheDictionary()

Slic3r::CacheDictionary::CacheDictionary ( )
39{
40 // ENUM_UNNAMED is index 0 and always the empty name.
41 m_enum_values.emplace_back();
42}
std::vector< std::string > m_enum_values
Definition PresetCacheFormat.hpp:95

References m_enum_values.

Member Function Documentation

◆ collect()

void Slic3r::CacheDictionary::collect ( const DynamicPrintConfig & config)
65{
66 for (auto it = config.cbegin(); it != config.cend(); ++ it) {
67 const ConfigOptionDef* def = print_config_def.get(it->first);
68 if (def == nullptr)
69 continue; // save_config does not write it either
70 if (m_key_index.try_emplace(it->first, uint16_t(m_keys.size())).second) {
71 m_keys.push_back(it->first);
72 m_types.push_back(uint16_t(def->type));
73 }
74 if (def->type != coEnum && def->type != coEnums)
75 continue;
76 for (int value : enum_ints(*def, it->second.get())) {
77 std::string name = enum_name_of(*def, value);
78 if (! name.empty() && m_enum_index.try_emplace(name, uint16_t(m_enum_values.size())).second)
79 m_enum_values.push_back(std::move(name));
80 }
81 }
82}
std::vector< uint16_t > m_types
Definition PresetCacheFormat.hpp:94
std::unordered_map< std::string, uint16_t > m_key_index
Definition PresetCacheFormat.hpp:98
std::vector< std::string > m_keys
Definition PresetCacheFormat.hpp:90
std::unordered_map< std::string, uint16_t > m_enum_index
Definition PresetCacheFormat.hpp:99
const ConfigOptionDef * get(const t_config_option_key &opt_key) const
Definition Config.hpp:2662
static std::vector< int > enum_ints(const ConfigOptionDef &def, const ConfigOption *opt)
Definition PresetCacheFormat.cpp:45
const PrintConfigDef print_config_def
Definition PrintConfig.cpp:10099
static std::string enum_name_of(const ConfigOptionDef &def, int value)
Definition PresetCacheFormat.cpp:55
@ coEnum
Definition Config.hpp:214
@ coEnums
Definition Config.hpp:216

References Slic3r::DynamicConfig::cbegin(), Slic3r::DynamicConfig::cend(), Slic3r::coEnum, Slic3r::coEnums, Slic3r::enum_ints(), Slic3r::enum_name_of(), m_enum_index, m_enum_values, m_key_index, m_keys, m_types, Slic3r::print_config_def, and Slic3r::ConfigOptionDef::type.

Referenced by Slic3r::VendorCacheFile::save().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ def_at()

const ConfigOptionDef * Slic3r::CacheDictionary::def_at ( uint16_t idx) const
inline
69{ return m_defs[idx]; }
std::vector< const ConfigOptionDef * > m_defs
Definition PresetCacheFormat.hpp:101

References m_defs.

Referenced by Slic3r::read_config().

Here is the caller graph for this function:

◆ enum_index()

uint16_t Slic3r::CacheDictionary::enum_index ( const std::string & name) const
93{
94 if (name.empty())
95 return ENUM_UNNAMED;
96 auto it = m_enum_index.find(name);
97 return it == m_enum_index.end() ? ENUM_UNNAMED : it->second;
98}
static constexpr uint16_t ENUM_UNNAMED
Definition PresetCacheFormat.hpp:50

References ENUM_UNNAMED, and m_enum_index.

Referenced by Slic3r::save_enum_option().

Here is the caller graph for this function:

◆ enum_name_at()

const std::string & Slic3r::CacheDictionary::enum_name_at ( uint16_t idx) const
inline
71{ return m_enum_values[idx]; }

References m_enum_values.

Referenced by Slic3r::load_enum_option().

Here is the caller graph for this function:

◆ key_index()

uint16_t Slic3r::CacheDictionary::key_index ( const t_config_option_key & key) const
85{
86 auto it = m_key_index.find(key);
87 if (it == m_key_index.end())
88 throw std::runtime_error("preset cache: option " + key + " was never collected into the dictionary");
89 return it->second;
90}

References m_key_index.

Referenced by Slic3r::save_config().

Here is the caller graph for this function:

◆ load()

void Slic3r::CacheDictionary::load ( cereal::BinaryInputArchive & ar)
110{
112 if (m_keys.size() != m_types.size())
113 throw std::runtime_error("preset cache: dictionary key and type tables differ in length");
114 if (m_keys.size() > MAX_ENTRIES || m_enum_values.size() > MAX_ENTRIES)
115 throw std::runtime_error("preset cache: dictionary is larger than the uint16 it is indexed with");
116 if (m_enum_values.empty() || ! m_enum_values.front().empty())
117 throw std::runtime_error("preset cache: dictionary is missing its unnamed-enum slot");
118 // Resolved once per file: every option read after this is a vector index.
119 m_defs.resize(m_keys.size());
120 for (size_t i = 0; i < m_keys.size(); ++ i) {
121 const ConfigOptionDef* def = print_config_def.get(m_keys[i]);
122 m_defs[i] = (def != nullptr && uint16_t(def->type) == m_types[i]) ? def : nullptr;
123 }
124}
static constexpr size_t MAX_ENTRIES
Definition PresetCacheFormat.hpp:88

References m_defs, m_enum_values, m_keys, m_types, MAX_ENTRIES, Slic3r::print_config_def, and Slic3r::ConfigOptionDef::type.

Referenced by Slic3r::VendorCacheFile::carries_preset(), and Slic3r::read_cache_up_to_presets().

Here is the caller graph for this function:

◆ save()

void Slic3r::CacheDictionary::save ( cereal::BinaryOutputArchive & ar) const
101{
102 // Checked here rather than left to the caller: an index that wrapped would
103 // be written silently, and nothing downstream could tell.
104 if (m_keys.size() > MAX_ENTRIES || m_enum_values.size() > MAX_ENTRIES)
105 throw std::runtime_error("preset cache: the option dictionary outgrew the uint16 it is indexed with");
107}

References m_enum_values, m_keys, m_types, and MAX_ENTRIES.

Referenced by Slic3r::VendorCacheFile::save().

Here is the caller graph for this function:

◆ type_at()

ConfigOptionType Slic3r::CacheDictionary::type_at ( uint16_t idx) const
inline
70{ return ConfigOptionType(m_types[idx]); }
ConfigOptionType
Definition Config.hpp:180

References m_types.

Referenced by Slic3r::read_config().

Here is the caller graph for this function:

◆ valid_enum_index()

bool Slic3r::CacheDictionary::valid_enum_index ( uint16_t idx) const
inline
75{ return size_t(idx) < m_enum_values.size(); }

References m_enum_values.

Referenced by Slic3r::load_enum_option().

Here is the caller graph for this function:

◆ valid_key_index()

bool Slic3r::CacheDictionary::valid_key_index ( uint16_t idx) const
inline
74{ return size_t(idx) < m_defs.size(); }

References m_defs.

Referenced by Slic3r::read_config().

Here is the caller graph for this function:

Member Data Documentation

◆ ENUM_UNNAMED

uint16_t Slic3r::CacheDictionary::ENUM_UNNAMED = 0
staticconstexpr

◆ m_defs

std::vector<const ConfigOptionDef*> Slic3r::CacheDictionary::m_defs
private

Referenced by def_at(), load(), and valid_key_index().

◆ m_enum_index

std::unordered_map<std::string, uint16_t> Slic3r::CacheDictionary::m_enum_index
private

Referenced by collect(), and enum_index().

◆ m_enum_values

std::vector<std::string> Slic3r::CacheDictionary::m_enum_values
private

◆ m_key_index

std::unordered_map<std::string, uint16_t> Slic3r::CacheDictionary::m_key_index
private

Referenced by collect(), and key_index().

◆ m_keys

std::vector<std::string> Slic3r::CacheDictionary::m_keys
private

Referenced by collect(), load(), and save().

◆ m_types

std::vector<uint16_t> Slic3r::CacheDictionary::m_types
private

Referenced by collect(), load(), save(), and type_at().

◆ MAX_ENTRIES

size_t Slic3r::CacheDictionary::MAX_ENTRIES = 0xFFFF
staticconstexprprivate

Referenced by load(), and save().


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