diff --git a/screenshots/diagram.png b/screenshots/diagram.png index 892c1d7..e90c077 100644 Binary files a/screenshots/diagram.png and b/screenshots/diagram.png differ diff --git a/src/Algorithms.cpp b/src/Algorithms.cpp new file mode 100644 index 0000000..1f8bbd8 --- /dev/null +++ b/src/Algorithms.cpp @@ -0,0 +1,21 @@ +#include "Algorithms.h" + +#include + +std::string doubleToString(const double value) +{ + std::string result = std::to_string(value); + + const std::regex integerRegex("^([0-9]+?)(?:\\.0+)$"); + const std::regex trailingSpacesRegex("^([0-9]+?\\.[0-9]*?[1-9])0*$"); + + std::smatch match; + + if (std::regex_match(result, match, integerRegex) + || std::regex_match(result, match, trailingSpacesRegex)) + { + result = match[1]; + } + + return result; +} diff --git a/src/Algorithms.h b/src/Algorithms.h new file mode 100644 index 0000000..f36c0af --- /dev/null +++ b/src/Algorithms.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +// Converts double to string and removes trailing floating zeroes if there are any. +std::string doubleToString(double value); diff --git a/src/DrawioElements/MxGeometryTag.cpp b/src/DrawioElements/MxGeometryTag.cpp index d9f4660..0db352f 100644 --- a/src/DrawioElements/MxGeometryTag.cpp +++ b/src/DrawioElements/MxGeometryTag.cpp @@ -1,5 +1,7 @@ #include "MxGeometryTag.h" +#include "Algorithms.h" + MxGeometryTag::MxGeometryTag() : MxGeometryTag(0, 0, 0, 0) { } @@ -14,10 +16,10 @@ MxGeometryTag::MxGeometryTag(const double x, , m_width(width) , m_height(height) { - setAttribute("x", std::to_string(x)); - setAttribute("y", std::to_string(y)); - setAttribute("width", std::to_string(width)); - setAttribute("height", std::to_string(height)); + setAttribute("x", doubleToString(x)); + setAttribute("y", doubleToString(y)); + setAttribute("width", doubleToString(width)); + setAttribute("height", doubleToString(height)); setAttribute("as", "geometry"); } @@ -46,22 +48,22 @@ double MxGeometryTag::getHeight() const return m_height; } -void MxGeometryTag::setX(double x) +void MxGeometryTag::setX(const double x) { m_x = x; } -void MxGeometryTag::setY(double y) +void MxGeometryTag::setY(const double y) { m_y = y; } -void MxGeometryTag::setWidth(double width) +void MxGeometryTag::setWidth(const double width) { m_width = width; } -void MxGeometryTag::setHeight(double height) +void MxGeometryTag::setHeight(const double height) { m_height = height; } diff --git a/src/File.cpp b/src/File.cpp index 7787dbf..8305afe 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -29,9 +29,10 @@ bool readLine(const std::string_view filePath, std::string& line) } } -std::string readFile(std::string_view filePath) +std::string readFile(const std::string_view filePath) { - std::string fileContent, line; + std::string fileContent; + std::string line; while (readLine(filePath, line)) { diff --git a/src/File.h b/src/File.h index adb4723..31f915b 100644 --- a/src/File.h +++ b/src/File.h @@ -9,7 +9,7 @@ bool readLine(std::string_view filePath, std::string& line); std::string readFile(std::string_view filePath); template -void writeToFile(std::string_view filePath, Collection collection) +void writeToFile(const std::string_view filePath, Collection collection) { std::ofstream outputFile(filePath.data()); diff --git a/src/Logging.h b/src/Logging.h index 16c1ae8..e3ca5dc 100644 --- a/src/Logging.h +++ b/src/Logging.h @@ -10,7 +10,7 @@ template void printList(BidirectionalIteratorT begin, BidirectionalIteratorT end, GetterT getItem, - std::string_view separator = ", ") + const std::string_view separator = ", ") { auto lastItem = end; --lastItem; diff --git a/src/Main.cpp b/src/Main.cpp index 8f90d3b..e75a540 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -13,7 +13,7 @@ int main(int argc, const char* argv[]) { - if (argc < 4) + if (argc != 4) { LOG_ERROR("Usage: SatisParsery path/to/data.json path/to/configuration.json " "path/to/output.drawio"); diff --git a/src/RecipeElements/XmlRecipe.cpp b/src/RecipeElements/XmlRecipe.cpp index cf667f7..7898462 100644 --- a/src/RecipeElements/XmlRecipe.cpp +++ b/src/RecipeElements/XmlRecipe.cpp @@ -3,6 +3,8 @@ #include "GroupItem.h" #include "Logging.h" +#include "Algorithms.h" + XmlRecipe::XmlRecipe(const std::string_view parentId, const size_t recipeIndex, const Items& ingredients, @@ -143,6 +145,8 @@ void XmlRecipe::generateItemElements(const Items& source, } } + name = doubleToString(source[i].count) + " " + name; + const auto itemElementPtr = new RecipeItem(m_groupElement->getId(), name, style, geometry); diff --git a/src/XmlElement.cpp b/src/XmlElement.cpp index 29f746f..bd6243c 100644 --- a/src/XmlElement.cpp +++ b/src/XmlElement.cpp @@ -3,7 +3,7 @@ #include #include -XmlElement::XmlElement(std::string_view type) +XmlElement::XmlElement(const std::string_view type) : m_type(type) { }