Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::ConfigOptionIntsTempl< NULLABLE > Class Template Reference

#include <src/libslic3r/Config.hpp>

+ Inheritance diagram for Slic3r::ConfigOptionIntsTempl< NULLABLE >:
+ Collaboration diagram for Slic3r::ConfigOptionIntsTempl< NULLABLE >:

Public Member Functions

 ConfigOptionIntsTempl ()
 
 ConfigOptionIntsTempl (size_t n, int value)
 
 ConfigOptionIntsTempl (std::initializer_list< int > il)
 
 ConfigOptionIntsTempl (const std::vector< int > &v)
 
 ConfigOptionIntsTempl (std::vector< int > &&v)
 
ConfigOptionType type () const override
 
ConfigOptionclone () const override
 
ConfigOptionIntsTemploperator= (const ConfigOption *opt)
 
bool operator== (const ConfigOptionIntsTempl &rhs) const throw ()
 
bool operator< (const ConfigOptionIntsTempl &rhs) const throw ()
 
bool nullable () const override
 
bool is_nil () const override
 
bool is_nil (size_t idx) 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 int & get_at (size_t i) const
 
int & 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< int > &rhs) const throw ()
 
bool operator!= (const std::vector< int > &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 int getInt () const
 
virtual double getFloat () const
 
virtual bool getBool () const
 
virtual void setInt (int)
 
bool is_scalar () const
 
bool is_vector () const
 

Static Public Member Functions

static ConfigOptionType static_type ()
 
static int nil_value ()
 

Public Attributes

std::vector< int > values
 

Protected Member Functions

ConfigOptionType scalar_type () const
 

Private Member Functions

void serialize_single_value (std::ostringstream &ss, const int v) const
 
template<class Archive >
void serialize (Archive &ar)
 

Friends

class cereal::access
 

Detailed Description

template<bool NULLABLE>
class Slic3r::ConfigOptionIntsTempl< NULLABLE >

Constructor & Destructor Documentation

◆ ConfigOptionIntsTempl() [1/5]

template<bool NULLABLE>
Slic3r::ConfigOptionIntsTempl< NULLABLE >::ConfigOptionIntsTempl ( )
inline
763: ConfigOptionVector<int>() {}

Referenced by Slic3r::ConfigOptionIntsTempl< NULLABLE >::clone().

+ Here is the caller graph for this function:

◆ ConfigOptionIntsTempl() [2/5]

template<bool NULLABLE>
Slic3r::ConfigOptionIntsTempl< NULLABLE >::ConfigOptionIntsTempl ( size_t  n,
int  value 
)
inlineexplicit
764: ConfigOptionVector<int>(n, value) {}

◆ ConfigOptionIntsTempl() [3/5]

template<bool NULLABLE>
Slic3r::ConfigOptionIntsTempl< NULLABLE >::ConfigOptionIntsTempl ( std::initializer_list< int >  il)
inlineexplicit
765: ConfigOptionVector<int>(std::move(il)) {}

◆ ConfigOptionIntsTempl() [4/5]

template<bool NULLABLE>
Slic3r::ConfigOptionIntsTempl< NULLABLE >::ConfigOptionIntsTempl ( const std::vector< int > &  v)
inlineexplicit
766: ConfigOptionVector<int>(v) {}

◆ ConfigOptionIntsTempl() [5/5]

template<bool NULLABLE>
Slic3r::ConfigOptionIntsTempl< NULLABLE >::ConfigOptionIntsTempl ( std::vector< int > &&  v)
inlineexplicit
767: ConfigOptionVector<int>(std::move(v)) {}

Member Function Documentation

◆ apply_override()

bool Slic3r::ConfigOptionVector< int >::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
std::vector< int > values
Definition Config.hpp:382

◆ clear()

void Slic3r::ConfigOptionVector< int >::clear ( )
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

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

◆ clone()

template<bool NULLABLE>
ConfigOption * Slic3r::ConfigOptionIntsTempl< NULLABLE >::clone ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOption.

771{ return new ConfigOptionIntsTempl(*this); }
ConfigOptionIntsTempl()
Definition Config.hpp:763

References Slic3r::ConfigOptionIntsTempl< NULLABLE >::ConfigOptionIntsTempl().

+ Here is the call graph for this function:

◆ deserialize()

template<bool NULLABLE>
bool Slic3r::ConfigOptionIntsTempl< NULLABLE >::deserialize ( const std::string &  str,
bool  append = false 
)
inlineoverridevirtual

Implements Slic3r::ConfigOption.

807 {
808 if (! append)
809 this->values.clear();
810 std::istringstream is(str);
811 std::string item_str;
812 while (std::getline(is, item_str, ',')) {
813 boost::trim(item_str);
814 if (item_str == "nil") {
815 if (NULLABLE)
816 this->values.push_back(nil_value());
817 else
818 throw ConfigurationError("Deserializing nil into a non-nullable object");
819 } else {
820 std::istringstream iss(item_str);
821 int value;
822 iss >> value;
823 this->values.push_back(value);
824 }
825 }
826 return true;
827 }
static int nil_value()
Definition Config.hpp:778
void append(std::vector< T, Alloc > &dest, const std::vector< T, Alloc2 > &src)
Definition libslic3r.h:110

References Slic3r::append(), and Slic3r::ConfigOptionIntsTempl< NULLABLE >::nil_value().

+ Here is the call graph for this function:

◆ empty()

bool Slic3r::ConfigOptionVector< int >::empty ( ) const
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

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

◆ get_at() [1/2]

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

◆ get_at() [2/2]

const int & Slic3r::ConfigOptionVector< int >::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< int >::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]

template<bool NULLABLE>
bool Slic3r::ConfigOptionIntsTempl< NULLABLE >::is_nil ( ) const
inlineoverridevirtual

Reimplemented from Slic3r::ConfigOption.

780{ for (auto v : this->values) if (v != nil_value()) return false; return true; }
if(!(yy_init))
Definition lexer.c:1190

References Slic3r::ConfigOptionIntsTempl< NULLABLE >::nil_value(), and Slic3r::ConfigOptionVector< int >::values.

Referenced by Slic3r::OozePrevention::pre_toolchange().

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

◆ is_nil() [2/2]

template<bool NULLABLE>
bool Slic3r::ConfigOptionIntsTempl< NULLABLE >::is_nil ( size_t  idx) const
inlineoverridevirtual

Implements Slic3r::ConfigOptionVectorBase.

781{ return values[idx < this->values.size() ? idx : 0] == nil_value(); }

References Slic3r::ConfigOptionIntsTempl< NULLABLE >::nil_value(), and Slic3r::ConfigOptionVector< int >::values.

+ Here is the call graph for this function:

◆ 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()

◆ nil_value()

template<bool NULLABLE>
static int Slic3r::ConfigOptionIntsTempl< NULLABLE >::nil_value ( )
inlinestatic
778{ return std::numeric_limits<int>::max(); }

Referenced by Slic3r::GUI::SpinCtrl::BUILD(), Slic3r::ConfigOptionIntsTempl< NULLABLE >::deserialize(), Slic3r::PrintConfigDef::init_sla_params(), Slic3r::ConfigOptionIntsTempl< NULLABLE >::is_nil(), Slic3r::ConfigOptionIntsTempl< NULLABLE >::is_nil(), and Slic3r::ConfigOptionIntsTempl< NULLABLE >::serialize_single_value().

+ Here is the caller graph for this function:

◆ nullable()

template<bool NULLABLE>
bool Slic3r::ConfigOptionIntsTempl< NULLABLE >::nullable ( ) const
inlineoverridevirtual

Reimplemented from Slic3r::ConfigOption.

776{ return NULLABLE; }

◆ operator!=() [1/2]

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

◆ operator!=() [2/2]

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

◆ operator<()

template<bool NULLABLE>
bool Slic3r::ConfigOptionIntsTempl< NULLABLE >::operator< ( const ConfigOptionIntsTempl< NULLABLE > &  rhs) const
throw (
)
inline
774{ return this->values < rhs.values; }

◆ operator=()

template<bool NULLABLE>
ConfigOptionIntsTempl & Slic3r::ConfigOptionIntsTempl< NULLABLE >::operator= ( const ConfigOption opt)
inline
772{ this->set(opt); return *this; }
void set(const ConfigOption *rhs) override
Definition Config.hpp:384

References Slic3r::ConfigOptionVector< int >::set().

+ Here is the call graph for this function:

◆ operator==() [1/3]

bool Slic3r::ConfigOptionVector< int >::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]

template<bool NULLABLE>
bool Slic3r::ConfigOptionIntsTempl< NULLABLE >::operator== ( const ConfigOptionIntsTempl< NULLABLE > &  rhs) const
throw (
)
inline
773{ return this->values == rhs.values; }

◆ operator==() [3/3]

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

◆ overriden_by()

bool Slic3r::ConfigOptionVector< int >::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< int >::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]

template<bool NULLABLE>
std::string Slic3r::ConfigOptionIntsTempl< NULLABLE >::serialize ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOption.

784 {
785 std::ostringstream ss;
786 for (const int &v : this->values) {
787 if (&v != &this->values.front())
788 ss << ",";
790 }
791 return ss.str();
792 }
void serialize_single_value(std::ostringstream &ss, const int v) const
Definition Config.hpp:830

References Slic3r::ConfigOptionIntsTempl< NULLABLE >::serialize_single_value(), and Slic3r::ConfigOptionVector< int >::values.

+ Here is the call graph for this function:

◆ serialize() [2/2]

template<bool NULLABLE>
template<class Archive >
void Slic3r::ConfigOptionIntsTempl< NULLABLE >::serialize ( Archive &  ar)
inlineprivate
841{ ar(cereal::base_class<ConfigOptionVector<int>>(this)); }

◆ serialize_single_value()

template<bool NULLABLE>
void Slic3r::ConfigOptionIntsTempl< NULLABLE >::serialize_single_value ( std::ostringstream &  ss,
const int  v 
) const
inlineprivate
830 {
831 if (v == nil_value()) {
832 if (NULLABLE)
833 ss << "nil";
834 else
835 throw ConfigurationError("Serializing NaN");
836 } else
837 ss << v;
838 }

References Slic3r::ConfigOptionIntsTempl< NULLABLE >::nil_value().

Referenced by Slic3r::ConfigOptionIntsTempl< NULLABLE >::serialize(), and Slic3r::ConfigOptionIntsTempl< NULLABLE >::vserialize().

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

◆ set() [1/2]

void Slic3r::ConfigOptionVector< int >::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< int >::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< int >::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< int >::size ( ) const
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

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

◆ static_type()

template<bool NULLABLE>
static ConfigOptionType Slic3r::ConfigOptionIntsTempl< NULLABLE >::static_type ( )
inlinestatic
769{ return coInts; }
@ coInts
Definition Config.hpp:170

References Slic3r::coInts.

Referenced by Slic3r::ConfigOptionIntsTempl< NULLABLE >::type().

+ Here is the caller graph for this function:

◆ type()

template<bool NULLABLE>
ConfigOptionType Slic3r::ConfigOptionIntsTempl< NULLABLE >::type ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOption.

770{ return static_type(); }
static ConfigOptionType static_type()
Definition Config.hpp:769

References Slic3r::ConfigOptionIntsTempl< NULLABLE >::static_type().

+ Here is the call graph for this function:

◆ vserialize()

template<bool NULLABLE>
std::vector< std::string > Slic3r::ConfigOptionIntsTempl< NULLABLE >::vserialize ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOptionVectorBase.

795 {
796 std::vector<std::string> vv;
797 vv.reserve(this->values.size());
798 for (const int v : this->values) {
799 std::ostringstream ss;
801 vv.push_back(ss.str());
802 }
803 return vv;
804 }

References Slic3r::ConfigOptionIntsTempl< NULLABLE >::serialize_single_value(), and Slic3r::ConfigOptionVector< int >::values.

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ cereal::access

template<bool NULLABLE>
friend class cereal::access
friend

Member Data Documentation

◆ values

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

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