Rework of Add random function for gcode macros. #5219 after merge:

The thread local storage variables for the random number generator
were replaced by an external context variable.
Thread local storage is a scarce resource.
This commit is contained in:
Vojtech Bubnik 2020-12-09 09:19:46 +01:00
parent 1e190affcf
commit 7353d8c6e9
4 changed files with 48 additions and 23 deletions

View file

@ -3,6 +3,7 @@
#include "libslic3r.h"
#include <map>
#include <random>
#include <string>
#include <vector>
#include "PrintConfig.hpp"
@ -11,7 +12,16 @@ namespace Slic3r {
class PlaceholderParser
{
public:
public:
// Context to be shared during multiple executions of the PlaceholderParser.
// The context is kept external to the PlaceholderParser, so that the same PlaceholderParser
// may be called safely from multiple threads.
// In the future, the context may hold variables created and modified by the PlaceholderParser
// and shared between the PlaceholderParser::process() invocations.
struct ContextData {
std::mt19937 rng;
};
PlaceholderParser(const DynamicConfig *external_config = nullptr);
// Return a list of keys, which should be changed in m_config from rhs.
@ -41,7 +51,7 @@ public:
// Fill in the template using a macro processing language.
// Throws Slic3r::PlaceholderParserError on syntax or runtime error.
std::string process(const std::string &templ, unsigned int current_extruder_id = 0, const DynamicConfig *config_override = nullptr) const;
std::string process(const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override, ContextData *context = nullptr) const;
// Evaluate a boolean expression using the full expressive power of the PlaceholderParser boolean expression syntax.
// Throws Slic3r::PlaceholderParserError on syntax or runtime error.