This commit is contained in:
enricoturri1966 2020-04-01 09:58:48 +02:00
commit 8a03d5642d
10 changed files with 364 additions and 240 deletions

View file

@ -64,6 +64,7 @@ add_library(libslic3r STATIC
Fill/FillRectilinear3.hpp
Flow.cpp
Flow.hpp
format.hpp
Format/3mf.cpp
Format/3mf.hpp
Format/AMF.cpp

View file

@ -1,4 +1,5 @@
#include "Config.hpp"
#include "format.hpp"
#include "Utils.hpp"
#include <assert.h>
#include <fstream>
@ -464,7 +465,7 @@ bool ConfigBase::set_deserialize_nothrow(const t_config_option_key &opt_key_src,
void ConfigBase::set_deserialize(const t_config_option_key &opt_key_src, const std::string &value_src, bool append)
{
if (! this->set_deserialize_nothrow(opt_key_src, value_src, append))
throw BadOptionTypeException((boost::format("ConfigBase::set_deserialize() failed for parameter \"%1%\", value \"%2%\"") % opt_key_src % value_src).str());
throw BadOptionTypeException(format("ConfigBase::set_deserialize() failed for parameter \"%1%\", value \"%2%\"", opt_key_src, value_src));
}
void ConfigBase::set_deserialize(std::initializer_list<SetDeserializeItem> items)
@ -620,7 +621,7 @@ void ConfigBase::load_from_gcode_file(const std::string &file)
size_t key_value_pairs = load_from_gcode_string(data.data());
if (key_value_pairs < 80)
throw std::runtime_error((boost::format("Suspiciously low number of configuration values extracted from %1%: %2%") % file % key_value_pairs).str());
throw std::runtime_error(format("Suspiciously low number of configuration values extracted from %1%: %2%", file, key_value_pairs));
}
// Load the config keys from the given string.

57
src/libslic3r/format.hpp Normal file
View file

@ -0,0 +1,57 @@
#ifndef slic3r_format_hpp_
#define slic3r_format_hpp_
// Functional wrapper around boost::format.
// One day we may replace this wrapper with C++20 format
// https://en.cppreference.com/w/cpp/utility/format/format
// though C++20 format uses a different template pattern for position independent parameters.
//
// Boost::format works around the missing variadic templates by an ugly % chaining operator. The usage of boost::format looks like this:
// (boost::format("template") % arg1 %arg2).str()
// This wrapper allows for a nicer syntax:
// Slic3r::format("template", arg1, arg2)
// One can also override Slic3r::internal::format::cook() function to convert a Slic3r::format() argument to something that
// boost::format may convert to string, see slic3r/GUI/I18N.hpp for a "cook" function to convert wxString to UTF8.
#include <boost/format.hpp>
namespace Slic3r {
// https://gist.github.com/gchudnov/6a90d51af004d97337ec
namespace internal {
namespace format {
// Default "cook" function - just forward.
template<typename T>
inline T&& cook(T&& arg) {
return std::forward<T>(arg);
}
// End of the recursive chain.
inline std::string format_recursive(boost::format& message) {
return message.str();
}
template<typename TValue, typename... TArgs>
std::string format_recursive(boost::format& message, TValue&& arg, TArgs&&... args) {
// Format, possibly convert the argument by the "cook" function.
message % cook(std::forward<TValue>(arg));
return format_recursive(message, std::forward<TArgs>(args)...);
}
}
};
template<typename... TArgs>
inline std::string format(const char* fmt, TArgs&&... args) {
boost::format message(fmt);
return internal::format::format_recursive(message, std::forward<TArgs>(args)...);
}
template<typename... TArgs>
inline std::string format(const std::string& fmt, TArgs&&... args) {
boost::format message(fmt);
return internal::format::format_recursive(message, std::forward<TArgs>(args)...);
}
} // namespace Slic3r
#endif // slic3r_format_hpp_

View file

@ -111,6 +111,7 @@
#include "BoundingBox.hpp"
#include "ClipperUtils.hpp"
#include "Config.hpp"
#include "format.hpp"
#include "I18N.hpp"
#include "MultiPoint.hpp"
#include "Point.hpp"