Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::ConfigOptionEnumDef Class Reference

#include <src/libslic3r/Config.hpp>

+ Collaboration diagram for Slic3r::ConfigOptionEnumDef:

Public Member Functions

bool has_values () const
 
bool has_labels () const
 
const std::vector< std::string > & values () const
 
const std::string & value (int idx) const
 
const std::vector< std::string > & enums () const
 
const std::vector< std::string > & labels () const
 
const std::string & label (int idx) const
 
int index_to_enum (int index) const
 
std::optional< int > enum_to_index (int enum_val) const
 
std::optional< int > value_to_index (const std::string &value) const
 
std::optional< int > label_to_index (const std::string &value) const
 
std::optional< std::reference_wrapper< const std::string > > enum_to_value (int enum_val) const
 
std::optional< std::reference_wrapper< const std::string > > enum_to_label (int enum_val) const
 
bool is_valid_closed_enum () const
 
bool is_valid_open_enum () const
 
void clear ()
 
ConfigOptionEnumDefclone () const
 

Private Member Functions

 ConfigOptionEnumDef ()=default
 
void set_values (const std::vector< std::string > &v)
 
void set_values (const std::initializer_list< std::string_view > il)
 
void set_values (const std::initializer_list< std::pair< std::string_view, std::string_view > > il)
 
void set_labels (const std::initializer_list< std::string_view > il)
 
void finalize_closed_enum ()
 
template<typename EnumType >
void set_enum_map ()
 

Private Attributes

friend ConfigDef
 
friend ConfigOptionDef
 
std::vector< std::string > m_values
 
std::vector< std::string > m_labels
 
bool m_values_ordinary { false }
 
const t_config_enum_namesm_enum_names { nullptr }
 
const t_config_enum_valuesm_enum_keys_map { nullptr }
 

Detailed Description

Constructor & Destructor Documentation

◆ ConfigOptionEnumDef()

Slic3r::ConfigOptionEnumDef::ConfigOptionEnumDef ( )
privatedefault

Member Function Documentation

◆ clear()

void Slic3r::ConfigOptionEnumDef::clear ( )
inline
1715 {
1716 m_values_ordinary = false;
1717 m_enum_names = nullptr;
1718 m_enum_keys_map = nullptr;
1719 m_values.clear();
1720 m_labels.clear();
1721 }
bool m_values_ordinary
Definition Config.hpp:1778
std::vector< std::string > m_values
Definition Config.hpp:1774
const t_config_enum_values * m_enum_keys_map
Definition Config.hpp:1792
const t_config_enum_names * m_enum_names
Definition Config.hpp:1789
std::vector< std::string > m_labels
Definition Config.hpp:1775

References m_enum_keys_map, m_enum_names, m_labels, m_values, and m_values_ordinary.

◆ clone()

ConfigOptionEnumDef * Slic3r::ConfigOptionEnumDef::clone ( ) const
inline
1723{ return new ConfigOptionEnumDef{ *this }; }

◆ enum_to_index()

std::optional< int > Slic3r::ConfigOptionEnumDef::enum_to_index ( int  enum_val) const
inline
1660 {
1661 assert(this->is_valid_closed_enum());
1662 assert(enum_val >= 0 && enum_val < int(m_enum_names->size()));
1664 return { enum_val };
1665 else {
1666 auto it = std::find(m_values.begin(), m_values.end(), (*m_enum_names)[enum_val]);
1667 return it == m_values.end() ? std::optional<int>{} : std::optional<int>{ int(it - m_values.begin()) };
1668 }
1669 }
bool is_valid_closed_enum() const
Definition Config.hpp:1705

References is_valid_closed_enum(), m_enum_names, m_values, and m_values_ordinary.

Referenced by enum_to_label(), and enum_to_value().

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

◆ enum_to_label()

std::optional< std::reference_wrapper< const std::string > > Slic3r::ConfigOptionEnumDef::enum_to_label ( int  enum_val) const
inline
1696 {
1697 assert(this->is_valid_closed_enum());
1698 auto opt = this->enum_to_index(enum_val);
1699 return opt.has_value() ?
1700 std::optional<std::reference_wrapper<const std::string>>{ this->label(*opt) } :
1701 std::optional<std::reference_wrapper<const std::string>>{};
1702 }
const std::string & label(int idx) const
Definition Config.hpp:1641
std::optional< int > enum_to_index(int enum_val) const
Definition Config.hpp:1660

References enum_to_index(), is_valid_closed_enum(), and label().

+ Here is the call graph for this function:

◆ enum_to_value()

std::optional< std::reference_wrapper< const std::string > > Slic3r::ConfigOptionEnumDef::enum_to_value ( int  enum_val) const
inline
1688 {
1689 assert(this->is_valid_closed_enum());
1690 auto opt = this->enum_to_index(enum_val);
1691 return opt.has_value() ?
1692 std::optional<std::reference_wrapper<const std::string>>{ this->value(*opt) } :
1693 std::optional<std::reference_wrapper<const std::string>>{};
1694 }
const std::string & value(int idx) const
Definition Config.hpp:1632

References enum_to_index(), is_valid_closed_enum(), and value().

+ Here is the call graph for this function:

◆ enums()

const std::vector< std::string > & Slic3r::ConfigOptionEnumDef::enums ( ) const
inline
1635 {
1636 assert(this->is_valid_open_enum());
1637 return this->has_values() ? m_values : m_labels;
1638 }
bool has_values() const
Definition Config.hpp:1629
bool is_valid_open_enum() const
Definition Config.hpp:1709

References has_values(), is_valid_open_enum(), m_labels, and m_values.

+ Here is the call graph for this function:

◆ finalize_closed_enum()

void Slic3r::ConfigOptionEnumDef::finalize_closed_enum ( )
inlineprivate
1760 {
1761 assert(this->is_valid_closed_enum());
1762 // Check whether def.enum_values contains all the values of def.enum_keys_map and
1763 // that they are sorted by their ordinary values.
1764 m_values_ordinary = true;
1765 for (const auto& [enum_name, enum_int] : *m_enum_keys_map) {
1766 assert(enum_int >= 0);
1767 if (enum_int >= int(this->values().size()) || this->value(enum_int) != enum_name) {
1768 m_values_ordinary = false;
1769 break;
1770 }
1771 }
1772 }
const std::vector< std::string > & values() const
Definition Config.hpp:1631
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183

References is_valid_closed_enum(), m_enum_keys_map, m_values_ordinary, value(), and values().

+ Here is the call graph for this function:

◆ has_labels()

bool Slic3r::ConfigOptionEnumDef::has_labels ( ) const
inline
1630{ return ! m_labels.empty(); }

References m_labels.

Referenced by labels().

+ Here is the caller graph for this function:

◆ has_values()

bool Slic3r::ConfigOptionEnumDef::has_values ( ) const
inline
1629{ return ! m_values.empty(); }

References m_values.

Referenced by enums().

+ Here is the caller graph for this function:

◆ index_to_enum()

int Slic3r::ConfigOptionEnumDef::index_to_enum ( int  index) const
inline
1645 {
1646 // It has to be a closed enum, thus values have to be defined.
1647 assert(this->is_valid_closed_enum());
1648 assert(index >= 0 && index < int(m_values.size()));
1650 return index;
1651 else {
1652 auto it = m_enum_keys_map->find(m_values[index]);
1653 assert(it != m_enum_keys_map->end());
1654 return it->second;
1655 }
1656 }

References is_valid_closed_enum(), m_enum_keys_map, m_values, and m_values_ordinary.

+ Here is the call graph for this function:

◆ is_valid_closed_enum()

bool Slic3r::ConfigOptionEnumDef::is_valid_closed_enum ( ) const
inline
1705 {
1706 return m_enum_names != nullptr && m_enum_keys_map != nullptr &&
1707 ! m_values.empty() && (m_labels.empty() || m_values.size() == m_labels.size());
1708 }

References m_enum_keys_map, m_enum_names, m_labels, and m_values.

Referenced by enum_to_index(), enum_to_label(), enum_to_value(), finalize_closed_enum(), index_to_enum(), and value_to_index().

+ Here is the caller graph for this function:

◆ is_valid_open_enum()

bool Slic3r::ConfigOptionEnumDef::is_valid_open_enum ( ) const
inline
1709 {
1710 return m_enum_names == nullptr && m_enum_keys_map == nullptr &&
1711 (! m_values.empty() || ! m_labels.empty()) && (m_values.empty() || m_labels.empty() || m_values.size() == m_labels.size());
1712 }

References m_enum_keys_map, m_enum_names, m_labels, and m_values.

Referenced by enums(), label_to_index(), and value_to_index().

+ Here is the caller graph for this function:

◆ label()

const std::string & Slic3r::ConfigOptionEnumDef::label ( int  idx) const
inline
1641{ return this->labels()[idx]; }
const std::vector< std::string > & labels() const
Definition Config.hpp:1640

References labels().

Referenced by enum_to_label().

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

◆ label_to_index()

std::optional< int > Slic3r::ConfigOptionEnumDef::label_to_index ( const std::string &  value) const
inline
1680 {
1681 assert(is_valid_open_enum());
1682 const auto &ls = this->labels();
1683 auto it = std::find(ls.begin(), ls.end(), value);
1684 return it == ls.end() ?
1685 std::optional<int>{} : std::optional<int>{ it - ls.begin() };
1686 }

References is_valid_open_enum(), labels(), and value().

+ Here is the call graph for this function:

◆ labels()

const std::vector< std::string > & Slic3r::ConfigOptionEnumDef::labels ( ) const
inline
1640{ return this->has_labels() ? m_labels : m_values; }
bool has_labels() const
Definition Config.hpp:1630

References has_labels(), m_labels, and m_values.

Referenced by label(), and label_to_index().

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

◆ set_enum_map()

template<typename EnumType >
void Slic3r::ConfigOptionEnumDef::set_enum_map ( )
inlineprivate
1782 {
1785 }
static const t_config_enum_names & get_enum_names()
static const t_config_enum_values & get_enum_values()

References Slic3r::ConfigOptionEnum< T >::get_enum_names(), Slic3r::ConfigOptionEnum< T >::get_enum_values(), m_enum_keys_map, and m_enum_names.

+ Here is the call graph for this function:

◆ set_labels()

void Slic3r::ConfigOptionEnumDef::set_labels ( const std::initializer_list< std::string_view >  il)
inlineprivate
1753 {
1754 m_labels.clear();
1755 m_labels.reserve(il.size());
1756 for (const std::string_view& p : il)
1757 m_labels.emplace_back(p);
1758 assert(m_values.empty() || m_labels.size() == m_values.size());
1759 }

References m_labels, and m_values.

◆ set_values() [1/3]

void Slic3r::ConfigOptionEnumDef::set_values ( const std::initializer_list< std::pair< std::string_view, std::string_view > >  il)
inlineprivate
1743 {
1744 m_values.clear();
1745 m_values.reserve(il.size());
1746 m_labels.clear();
1747 m_labels.reserve(il.size());
1748 for (const std::pair<std::string_view, std::string_view>& p : il) {
1749 m_values.emplace_back(p.first);
1750 m_labels.emplace_back(p.second);
1751 }
1752 }

References m_labels, and m_values.

◆ set_values() [2/3]

void Slic3r::ConfigOptionEnumDef::set_values ( const std::initializer_list< std::string_view >  il)
inlineprivate
1736 {
1737 m_values.clear();
1738 m_values.reserve(il.size());
1739 for (const std::string_view& p : il)
1740 m_values.emplace_back(p);
1741 assert(m_labels.empty() || m_labels.size() == m_values.size());
1742 }

References m_labels, and m_values.

◆ set_values() [3/3]

void Slic3r::ConfigOptionEnumDef::set_values ( const std::vector< std::string > &  v)
inlineprivate
1732 {
1733 m_values = v;
1734 assert(m_labels.empty() || m_labels.size() == m_values.size());
1735 }

References m_labels, and m_values.

◆ value()

const std::string & Slic3r::ConfigOptionEnumDef::value ( int  idx) const
inline
1632{ return m_values[idx]; }

References m_values.

Referenced by enum_to_value(), finalize_closed_enum(), label_to_index(), and value_to_index().

+ Here is the caller graph for this function:

◆ value_to_index()

std::optional< int > Slic3r::ConfigOptionEnumDef::value_to_index ( const std::string &  value) const
inline
1672 {
1673 assert(this->is_valid_open_enum() || this->is_valid_closed_enum());
1674 auto it = std::find(m_values.begin(), m_values.end(), value);
1675 return it == m_values.end() ?
1676 std::optional<int>{} : std::optional<int>{ it - m_values.begin() };
1677 }

References is_valid_closed_enum(), is_valid_open_enum(), m_values, and value().

+ Here is the call graph for this function:

◆ values()

const std::vector< std::string > & Slic3r::ConfigOptionEnumDef::values ( ) const
inline
1631{ return m_values; }

References m_values.

Referenced by finalize_closed_enum().

+ Here is the caller graph for this function:

Member Data Documentation

◆ ConfigDef

friend Slic3r::ConfigOptionEnumDef::ConfigDef
private

◆ ConfigOptionDef

friend Slic3r::ConfigOptionEnumDef::ConfigOptionDef
private

◆ m_enum_keys_map

const t_config_enum_values* Slic3r::ConfigOptionEnumDef::m_enum_keys_map { nullptr }
private

◆ m_enum_names

const t_config_enum_names* Slic3r::ConfigOptionEnumDef::m_enum_names { nullptr }
private

◆ m_labels

std::vector<std::string> Slic3r::ConfigOptionEnumDef::m_labels
private

◆ m_values

◆ m_values_ordinary

bool Slic3r::ConfigOptionEnumDef::m_values_ordinary { false }
private

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