OOFEM 3.0
Loading...
Searching...
No Matches
GCodeCommand.h
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <fstream>
5#include <sstream>
6#include <string>
7#include <vector>
8#include <map>
9#include <variant>
10#include <optional>
11
16{
17public:
21 GCodeCommand() = default;
22
27 GCodeCommand(const std::string &cmd) : code(cmd) {}
28
34 void addParameter(char letter, const std::string &value)
35 {
36 parameters[letter] = value;
37 }
38
43 void setCode(const std::string code) { this->code = code; }
44
49 std::string getCode() const { return code; }
50
55 std::map<char, std::string> getParameters() const { return parameters; }
56
62 std::optional<std::string> param_string(char paramLetter) const
63 {
64 auto it = parameters.find(paramLetter);
65 if (it != parameters.end())
66 {
67 return it->second;
68 }
69 return std::nullopt;
70 }
71
77 std::optional<int> param_int(char paramLetter) const
78 {
79 auto strValue = param_string(paramLetter);
80 if (strValue)
81 {
82 try
83 {
84 return std::stoi(*strValue);
85 }
86 catch (...)
87 {
88 return std::nullopt; // Conversion failed
89 }
90 }
91 return std::nullopt; // Parameter not found
92 }
93
99 std::optional<double> param_double(char paramLetter) const
100 {
101 auto strValue = param_string(paramLetter);
102 if (strValue)
103 {
104 try
105 {
106 return std::stod(*strValue);
107 }
108 catch (...)
109 {
110 return std::nullopt; // Conversion failed
111 }
112 }
113 return std::nullopt; // Parameter not found
114 }
115
116private:
117 std::string code; // The G-code command
118 std::map<char, std::string> parameters; // The parameters associated with the G-code command
119};
std::optional< std::string > param_string(char paramLetter) const
Get the value of a parameter as a string.
std::optional< int > param_int(char paramLetter) const
Get the value of a parameter as an integer.
void setCode(const std::string code)
Set the G-code command.
std::map< char, std::string > parameters
GCodeCommand()=default
Default constructor for the GCodeCommand class.
std::map< char, std::string > getParameters() const
Get the parameters associated with the G-code command.
GCodeCommand(const std::string &cmd)
Constructor for the GCodeCommand class.
std::string code
void addParameter(char letter, const std::string &value)
Method to add a parameter to the G-code command.
std::optional< double > param_double(char paramLetter) const
Get the value of a parameter as a double.
std::string getCode() const
Get the G-code command.

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011