OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::CommandProcessor Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/GCode/GCodeProcessor.hpp>

Collaboration diagram for Slic3r::CommandProcessor:

Classes

struct  TrieNode

Public Types

using command_handler_t = std::function<void(const GCodeReader::GCodeLine& line)>

Public Member Functions

 CommandProcessor ()
void register_command (const std::string &str, command_handler_t handler, bool early_quit=false)
bool process_comand (std::string_view cmd, const GCodeReader::GCodeLine &line)

Private Attributes

std::unique_ptr< TrieNode > root

Detailed Description


Class Documentation

◆ Slic3r::CommandProcessor::TrieNode

struct Slic3r::CommandProcessor::TrieNode
Collaboration diagram for Slic3r::CommandProcessor::TrieNode:
Class Members
unordered_map< char, unique_ptr< TrieNode > > children
bool early_quit { false }
command_handler_t handler { nullptr }

Member Typedef Documentation

◆ command_handler_t

using Slic3r::CommandProcessor::command_handler_t = std::function<void(const GCodeReader::GCodeLine& line)>

Constructor & Destructor Documentation

◆ CommandProcessor()

Slic3r::CommandProcessor::CommandProcessor ( )
265{
266 root = std::make_unique<TrieNode>();
267}
std::unique_ptr< TrieNode > root
Definition GCodeProcessor.hpp:567

References root.

Member Function Documentation

◆ process_comand()

bool Slic3r::CommandProcessor::process_comand ( std::string_view cmd,
const GCodeReader::GCodeLine & line )
292{
293 TrieNode* node = root.get();
294 for (char ch : cmd) {
295 if (node->early_quit && node->handler) {
296 node->handler(line);
297 return true;
298 }
299 auto iter = node->children.find(ch);
300 if (iter == node->children.end()) {
301 return false;
302 }
303 node = iter->second.get();
304 }
305 if (!node || !node->handler)
306 return false;
307 node->handler(line);
308 return true;
309}
Definition GCodeProcessor.hpp:557

References Slic3r::CommandProcessor::TrieNode::children, Slic3r::CommandProcessor::TrieNode::early_quit, Slic3r::CommandProcessor::TrieNode::handler, and root.

◆ register_command()

void Slic3r::CommandProcessor::register_command ( const std::string & str,
command_handler_t handler,
bool early_quit = false )
270{
271 TrieNode* node = root.get();
272 for (char ch : str) {
273 auto iter = node->children.find(ch);
274 if (iter == node->children.end()) {
275 std::unique_ptr<TrieNode> new_node = std::make_unique<TrieNode>();
276 auto raw_ptr = new_node.get();
277 node->children[ch] = std::move(new_node);
278 node = raw_ptr;
279 }
280 else {
281 node = iter->second.get();
282 }
283 }
284 if (node->handler != nullptr) {
285 assert(false);// duplicated command
286 }
287 node->handler = handler;
288 node->early_quit = early_quit;
289}

References Slic3r::CommandProcessor::TrieNode::children, Slic3r::CommandProcessor::TrieNode::early_quit, Slic3r::CommandProcessor::TrieNode::handler, and root.

Member Data Documentation

◆ root

std::unique_ptr<TrieNode> Slic3r::CommandProcessor::root
private

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