Skip to content

Commit

Permalink
Added items rate near the names and minor code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
andev0 committed Aug 22, 2023
1 parent 41c4cb2 commit 59ccb6a
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 14 deletions.
Binary file modified screenshots/diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/Algorithms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "Algorithms.h"

#include <regex>

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;
}
6 changes: 6 additions & 0 deletions src/Algorithms.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <string>

// Converts double to string and removes trailing floating zeroes if there are any.
std::string doubleToString(double value);
18 changes: 10 additions & 8 deletions src/DrawioElements/MxGeometryTag.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "MxGeometryTag.h"

#include "Algorithms.h"

MxGeometryTag::MxGeometryTag()
: MxGeometryTag(0, 0, 0, 0)
{ }
Expand All @@ -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");
}
Expand Down Expand Up @@ -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;
}
5 changes: 3 additions & 2 deletions src/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bool readLine(std::string_view filePath, std::string& line);
std::string readFile(std::string_view filePath);

template<class Collection>
void writeToFile(std::string_view filePath, Collection collection)
void writeToFile(const std::string_view filePath, Collection collection)
{
std::ofstream outputFile(filePath.data());

Expand Down
2 changes: 1 addition & 1 deletion src/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ template<class BidirectionalIteratorT, class GetterT>
void printList(BidirectionalIteratorT begin,
BidirectionalIteratorT end,
GetterT getItem,
std::string_view separator = ", ")
const std::string_view separator = ", ")
{
auto lastItem = end;
--lastItem;
Expand Down
2 changes: 1 addition & 1 deletion src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions src/RecipeElements/XmlRecipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/XmlElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cassert>
#include <fstream>

XmlElement::XmlElement(std::string_view type)
XmlElement::XmlElement(const std::string_view type)
: m_type(type)
{ }

Expand Down

0 comments on commit 59ccb6a

Please sign in to comment.