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

#include <src/libslic3r/Config.hpp>

+ Inheritance diagram for Slic3r::ConfigOptionStrings:
+ Collaboration diagram for Slic3r::ConfigOptionStrings:

Public Member Functions

 ConfigOptionStrings ()
 
 ConfigOptionStrings (size_t n, const std::string &value)
 
 ConfigOptionStrings (const std::vector< std::string > &values)
 
 ConfigOptionStrings (std::vector< std::string > &&values)
 
 ConfigOptionStrings (std::initializer_list< std::string > il)
 
ConfigOptionType type () const override
 
ConfigOptionclone () const override
 
ConfigOptionStringsoperator= (const ConfigOption *opt)
 
bool operator== (const ConfigOptionStrings &rhs) const throw ()
 
bool operator< (const ConfigOptionStrings &rhs) const throw ()
 
bool is_nil (size_t) const override
 
std::string serialize () const override
 
std::vector< std::string > vserialize () const override
 
bool deserialize (const std::string &str, bool append=false) override
 
void set (const ConfigOption *rhs) override
 
void set (const std::vector< const ConfigOption * > &rhs) override
 
void set_at (const ConfigOption *rhs, size_t i, size_t j) override
 
const std::string & get_at (size_t i) const
 
std::string & get_at (size_t i)
 
void resize (size_t n, const ConfigOption *opt_default=nullptr) override
 
void clear () override
 
size_t size () const override
 
bool empty () const override
 
bool operator== (const ConfigOption &rhs) const override
 
bool operator== (const std::vector< std::string > &rhs) const throw ()
 
bool operator!= (const std::vector< std::string > &rhs) const throw ()
 
bool operator!= (const ConfigOption &rhs) const
 
size_t hash () const override throw ()
 
bool overriden_by (const ConfigOption *rhs) const override
 
bool apply_override (const ConfigOption *rhs) override
 
virtual bool is_nil () const
 
virtual int getInt () const
 
virtual double getFloat () const
 
virtual bool getBool () const
 
virtual void setInt (int)
 
bool is_scalar () const
 
bool is_vector () const
 
virtual bool nullable () const
 

Static Public Member Functions

static ConfigOptionType static_type ()
 

Public Attributes

std::vector< std::string > values
 

Protected Member Functions

ConfigOptionType scalar_type () const
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar)
 

Friends

class cereal::access
 

Detailed Description

Constructor & Destructor Documentation

◆ ConfigOptionStrings() [1/5]

Slic3r::ConfigOptionStrings::ConfigOptionStrings ( )
inline
881: ConfigOptionVector<std::string>() {}

Referenced by clone().

+ Here is the caller graph for this function:

◆ ConfigOptionStrings() [2/5]

Slic3r::ConfigOptionStrings::ConfigOptionStrings ( size_t  n,
const std::string &  value 
)
inlineexplicit
882: ConfigOptionVector<std::string>(n, value) {}

◆ ConfigOptionStrings() [3/5]

Slic3r::ConfigOptionStrings::ConfigOptionStrings ( const std::vector< std::string > &  values)
inlineexplicit
883: ConfigOptionVector<std::string>(values) {}
std::vector< std::string > values
Definition Config.hpp:382

◆ ConfigOptionStrings() [4/5]

Slic3r::ConfigOptionStrings::ConfigOptionStrings ( std::vector< std::string > &&  values)
inlineexplicit
884: ConfigOptionVector<std::string>(std::move(values)) {}

◆ ConfigOptionStrings() [5/5]

Slic3r::ConfigOptionStrings::ConfigOptionStrings ( std::initializer_list< std::string >  il)
inlineexplicit
885: ConfigOptionVector<std::string>(std::move(il)) {}

Member Function Documentation

◆ apply_override()

bool Slic3r::ConfigOptionVector< std::string >::apply_override ( const ConfigOption rhs)
inlineoverridevirtualinherited

Reimplemented from Slic3r::ConfigOption.

515 {
516 if (this->nullable())
517 throw ConfigurationError("Cannot override a nullable ConfigOption.");
518 if (rhs->type() != this->type())
519 throw ConfigurationError("ConfigOptionVector.apply_override() applied to different types.");
520 auto rhs_vec = static_cast<const ConfigOptionVector<T>*>(rhs);
521 if (! rhs->nullable()) {
522 // Overridding a non-nullable object with another non-nullable object.
523 if (this->values != rhs_vec->values) {
524 this->values = rhs_vec->values;
525 return true;
526 }
527 return false;
528 }
529 size_t i = 0;
530 size_t cnt = std::min(this->size(), rhs_vec->size());
531 bool modified = false;
532 for (; i < cnt; ++ i)
533 if (! rhs_vec->is_nil(i) && this->values[i] != rhs_vec->values[i]) {
534 this->values[i] = rhs_vec->values[i];
535 modified = true;
536 }
537 for (; i < rhs_vec->size(); ++ i)
538 if (! rhs_vec->is_nil(i)) {
539 if (this->values.empty())
540 this->values.resize(i + 1);
541 else
542 this->values.resize(i + 1, this->values.front());
543 this->values[i] = rhs_vec->values[i];
544 modified = true;
545 }
546 return modified;
547 }
virtual bool nullable() const
Definition Config.hpp:280
size_t size() const override
Definition Config.hpp:471

◆ clear()

void Slic3r::ConfigOptionVector< std::string >::clear ( )
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

470{ this->values.clear(); }

◆ clone()

ConfigOption * Slic3r::ConfigOptionStrings::clone ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOption.

889{ return new ConfigOptionStrings(*this); }
ConfigOptionStrings()
Definition Config.hpp:881

References ConfigOptionStrings().

+ Here is the call graph for this function:

◆ deserialize()

bool Slic3r::ConfigOptionStrings::deserialize ( const std::string &  str,
bool  append = false 
)
inlineoverridevirtual

Implements Slic3r::ConfigOption.

906 {
907 if (! append)
908 this->values.clear();
909 return unescape_strings_cstyle(str, this->values);
910 }
bool unescape_strings_cstyle(const std::string &str, std::vector< std::string > &out)
Definition Config.cpp:130
void append(std::vector< T, Alloc > &dest, const std::vector< T, Alloc2 > &src)
Definition libslic3r.h:110

References Slic3r::append(), and Slic3r::unescape_strings_cstyle().

+ Here is the call graph for this function:

◆ empty()

bool Slic3r::ConfigOptionVector< std::string >::empty ( ) const
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

472{ return this->values.empty(); }

◆ get_at() [1/2]

std::string & Slic3r::ConfigOptionVector< std::string >::get_at ( size_t  i)
inlineinherited
442{ return const_cast<T&>(std::as_const(*this).get_at(i)); }

◆ get_at() [2/2]

const std::string & Slic3r::ConfigOptionVector< std::string >::get_at ( size_t  i) const
inlineinherited
437 {
438 assert(! this->values.empty());
439 return (i < this->values.size()) ? this->values[i] : this->values.front();
440 }

◆ getBool()

virtual bool Slic3r::ConfigOption::getBool ( ) const
inlinevirtualinherited

Reimplemented in Slic3r::ConfigOptionBool.

272{ throw BadOptionTypeException("Calling ConfigOption::getBool on a non-boolean ConfigOption"); }

Referenced by Slic3r::client::MyContext::scalar_variable_to_expr().

+ Here is the caller graph for this function:

◆ getFloat()

virtual double Slic3r::ConfigOption::getFloat ( ) const
inlinevirtualinherited

Reimplemented in Slic3r::ConfigOptionFloat.

271{ throw BadOptionTypeException("Calling ConfigOption::getFloat on a non-float ConfigOption"); }

Referenced by Slic3r::GUI::TabSLAMaterial::build(), Slic3r::GUI::get_string_value(), Slic3r::client::MyContext::scalar_variable_to_expr(), and Slic3r::GUI::Sidebar::update_sliced_info_sizer().

+ Here is the caller graph for this function:

◆ getInt()

virtual int Slic3r::ConfigOption::getInt ( ) const
inlinevirtualinherited

◆ hash()

size_t Slic3r::ConfigOptionVector< std::string >::hash ( ) const
throw (
)
inlineoverridevirtualinherited

Implements Slic3r::ConfigOption.

485 {
486 std::hash<T> hasher;
487 size_t seed = 0;
488 for (const auto &v : this->values)
489 boost::hash_combine(seed, hasher(v));
490 return seed;
491 }
Definition args.hpp:18

◆ is_nil() [1/2]

virtual bool Slic3r::ConfigOption::is_nil ( ) const
inlinevirtualinherited

Reimplemented from Slic3r::ConfigOption.

282{ return false; }

◆ is_nil() [2/2]

bool Slic3r::ConfigOptionStrings::is_nil ( size_t  ) const
inlineoverridevirtual

Implements Slic3r::ConfigOptionVectorBase.

893{ return false; }

◆ is_scalar()

bool Slic3r::ConfigOption::is_scalar ( ) const
inlineinherited
277{ return (int(this->type()) & int(coVectorType)) == 0; }
virtual ConfigOptionType type() const =0
@ coVectorType
Definition Config.hpp:161

References Slic3r::coVectorType, and Slic3r::ConfigOption::type().

Referenced by Slic3r::PresetBundle::full_fff_config(), Slic3r::client::MyContext::is_nil_test(), Slic3r::ConfigOption::is_vector(), Slic3r::client::MyContext::legacy_variable_expansion(), Slic3r::PresetBundle::load_config_file_config(), Slic3r::client::MyContext::scalar_variable_assign_scalar(), Slic3r::client::MyContext::scalar_variable_to_expr(), Slic3r::client::MyContext::vector_variable_assign_array(), Slic3r::client::MyContext::vector_variable_assign_initializer_list(), and Slic3r::client::MyContext::vector_variable_new_from_array().

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

◆ is_vector()

◆ nullable()

virtual bool Slic3r::ConfigOption::nullable ( ) const
inlinevirtualinherited

◆ operator!=() [1/2]

bool Slic3r::ConfigOption::operator!= ( const ConfigOption rhs) const
inlineinherited
275{ return ! (*this == rhs); }

◆ operator!=() [2/2]

bool Slic3r::ConfigOptionVector< std::string >::operator!= ( const std::vector< std::string > &  rhs) const
throw (
)
inlineinherited
483{ return this->values != rhs; }

◆ operator<()

bool Slic3r::ConfigOptionStrings::operator< ( const ConfigOptionStrings rhs) const
throw (
)
inline
892{ return this->values < rhs.values; }

◆ operator=()

ConfigOptionStrings & Slic3r::ConfigOptionStrings::operator= ( const ConfigOption opt)
inline
890{ this->set(opt); return *this; }
void set(const ConfigOption *rhs) override
Definition Config.hpp:384

References Slic3r::ConfigOptionVector< std::string >::set().

+ Here is the call graph for this function:

◆ operator==() [1/3]

bool Slic3r::ConfigOptionVector< std::string >::operator== ( const ConfigOption rhs) const
inlineoverridevirtualinherited

Implements Slic3r::ConfigOption.

475 {
476 if (rhs.type() != this->type())
477 throw ConfigurationError("ConfigOptionVector: Comparing incompatible types");
478 assert(dynamic_cast<const ConfigOptionVector<T>*>(&rhs));
479 return this->values == static_cast<const ConfigOptionVector<T>*>(&rhs)->values;
480 }

◆ operator==() [2/3]

bool Slic3r::ConfigOptionStrings::operator== ( const ConfigOptionStrings rhs) const
throw (
)
inline
891{ return this->values == rhs.values; }

◆ operator==() [3/3]

bool Slic3r::ConfigOptionVector< std::string >::operator== ( const std::vector< std::string > &  rhs) const
throw (
)
inlineinherited
482{ return this->values == rhs; }

◆ overriden_by()

bool Slic3r::ConfigOptionVector< std::string >::overriden_by ( const ConfigOption rhs) const
inlineoverridevirtualinherited

Reimplemented from Slic3r::ConfigOption.

495 {
496 if (this->nullable())
497 throw ConfigurationError("Cannot override a nullable ConfigOption.");
498 if (rhs->type() != this->type())
499 throw ConfigurationError("ConfigOptionVector.overriden_by() applied to different types.");
500 auto rhs_vec = static_cast<const ConfigOptionVector<T>*>(rhs);
501 if (! rhs->nullable())
502 // Overridding a non-nullable object with another non-nullable object.
503 return this->values != rhs_vec->values;
504 size_t i = 0;
505 size_t cnt = std::min(this->size(), rhs_vec->size());
506 for (; i < cnt; ++ i)
507 if (! rhs_vec->is_nil(i) && this->values[i] != rhs_vec->values[i])
508 return true;
509 for (; i < rhs_vec->size(); ++ i)
510 if (! rhs_vec->is_nil(i))
511 return true;
512 return false;
513 }

◆ resize()

void Slic3r::ConfigOptionVector< std::string >::resize ( size_t  n,
const ConfigOption opt_default = nullptr 
)
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

447 {
448 assert(opt_default == nullptr || opt_default->is_vector());
449// assert(opt_default == nullptr || dynamic_cast<ConfigOptionVector<T>>(opt_default));
450 assert(! this->values.empty() || opt_default != nullptr);
451 if (n == 0)
452 this->values.clear();
453 else if (n < this->values.size())
454 this->values.erase(this->values.begin() + n, this->values.end());
455 else if (n > this->values.size()) {
456 if (this->values.empty()) {
457 if (opt_default == nullptr)
458 throw ConfigurationError("ConfigOptionVector::resize(): No default value provided.");
459 if (opt_default->type() != this->type())
460 throw ConfigurationError("ConfigOptionVector::resize(): Extending with an incompatible type.");
461 this->values.resize(n, static_cast<const ConfigOptionVector<T>*>(opt_default)->values.front());
462 } else {
463 // Resize by duplicating the last value.
464 this->values.resize(n, this->values./*back*/front());
465 }
466 }
467 }

◆ scalar_type()

ConfigOptionType Slic3r::ConfigOptionVectorBase::scalar_type ( ) const
inlineprotectedinherited
369{ return static_cast<ConfigOptionType>(this->type() - coVectorType); }
ConfigOptionType
Definition Config.hpp:160

References Slic3r::coVectorType, and Slic3r::ConfigOption::type().

Referenced by Slic3r::ConfigOptionVector< T >::set(), and Slic3r::ConfigOptionVector< T >::set_at().

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

◆ serialize() [1/2]

std::string Slic3r::ConfigOptionStrings::serialize ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOption.

896 {
897 return escape_strings_cstyle(this->values);
898 }
std::string escape_strings_cstyle(const std::vector< std::string > &strs)
Definition Config.cpp:56

References Slic3r::escape_strings_cstyle().

+ Here is the call graph for this function:

◆ serialize() [2/2]

template<class Archive >
void Slic3r::ConfigOptionStrings::serialize ( Archive &  ar)
inlineprivate
914{ ar(cereal::base_class<ConfigOptionVector<std::string>>(this)); }

◆ set() [1/2]

void Slic3r::ConfigOptionVector< std::string >::set ( const ConfigOption rhs)
inlineoverridevirtualinherited

Implements Slic3r::ConfigOption.

385 {
386 if (rhs->type() != this->type())
387 throw ConfigurationError("ConfigOptionVector: Assigning an incompatible type");
388 assert(dynamic_cast<const ConfigOptionVector<T>*>(rhs));
389 this->values = static_cast<const ConfigOptionVector<T>*>(rhs)->values;
390 }

◆ set() [2/2]

void Slic3r::ConfigOptionVector< std::string >::set ( const std::vector< const ConfigOption * > &  rhs)
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

397 {
398 this->values.clear();
399 this->values.reserve(rhs.size());
400 for (const ConfigOption *opt : rhs) {
401 if (opt->type() == this->type()) {
402 auto other = static_cast<const ConfigOptionVector<T>*>(opt);
403 if (other->values.empty())
404 throw ConfigurationError("ConfigOptionVector::set(): Assigning from an empty vector");
405 this->values.emplace_back(other->values.front());
406 } else if (opt->type() == this->scalar_type())
407 this->values.emplace_back(static_cast<const ConfigOptionSingle<T>*>(opt)->value);
408 else
409 throw ConfigurationError("ConfigOptionVector::set():: Assigning an incompatible type");
410 }
411 }
ConfigOptionType scalar_type() const
Definition Config.hpp:369

◆ set_at()

void Slic3r::ConfigOptionVector< std::string >::set_at ( const ConfigOption rhs,
size_t  i,
size_t  j 
)
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

416 {
417 // It is expected that the vector value has at least one value, which is the default, if not overwritten.
418 assert(! this->values.empty());
419 if (this->values.size() <= i) {
420 // Resize this vector, fill in the new vector fields with the copy of the first field.
421 T v = this->values.front();
422 this->values.resize(i + 1, v);
423 }
424 if (rhs->type() == this->type()) {
425 // Assign the first value of the rhs vector.
426 auto other = static_cast<const ConfigOptionVector<T>*>(rhs);
427 if (other->values.empty())
428 throw ConfigurationError("ConfigOptionVector::set_at(): Assigning from an empty vector");
429 this->values[i] = other->get_at(j);
430 } else if (rhs->type() == this->scalar_type())
431 this->values[i] = static_cast<const ConfigOptionSingle<T>*>(rhs)->value;
432 else
433 throw ConfigurationError("ConfigOptionVector::set_at(): Assigning an incompatible type");
434 }

◆ setInt()

virtual void Slic3r::ConfigOption::setInt ( int  )
inlinevirtualinherited

Reimplemented in Slic3r::ConfigOptionInt, and Slic3r::ConfigOptionEnum< T >.

273{ throw BadOptionTypeException("Calling ConfigOption::setInt on a non-int ConfigOption"); }

◆ size()

size_t Slic3r::ConfigOptionVector< std::string >::size ( ) const
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

471{ return this->values.size(); }

◆ static_type()

static ConfigOptionType Slic3r::ConfigOptionStrings::static_type ( )
inlinestatic
887{ return coStrings; }
@ coStrings
Definition Config.hpp:174

References Slic3r::coStrings.

Referenced by type().

+ Here is the caller graph for this function:

◆ type()

ConfigOptionType Slic3r::ConfigOptionStrings::type ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOption.

888{ return static_type(); }
static ConfigOptionType static_type()
Definition Config.hpp:887

References static_type().

+ Here is the call graph for this function:

◆ vserialize()

std::vector< std::string > Slic3r::ConfigOptionStrings::vserialize ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOptionVectorBase.

901 {
902 return this->values;
903 }

References Slic3r::ConfigOptionVector< std::string >::values.

Friends And Related Symbol Documentation

◆ cereal::access

friend class cereal::access
friend

Member Data Documentation

◆ values

std::vector<std::string > Slic3r::ConfigOptionVector< std::string >::values
inherited

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