From 004fa309d6ede28ec8ab195647a2cbee490e104f Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sat, 25 Nov 2017 20:02:46 +0100 Subject: First commit --- .cproject | 124 ++++++++++++++++++++++++++++++++++++++++ .project | 27 +++++++++ .settings/language.settings.xml | 25 ++++++++ src/diagram/Statement.cpp | 12 ++++ src/diagram/Statement.hpp | 60 +++++++++++++++++++ src/diagram/Structogram.cpp | 27 +++++++++ src/diagram/Structogram.hpp | 32 +++++++++++ src/main.cpp | 16 ++++++ src/ui/AsciiRenderer.cpp | 97 +++++++++++++++++++++++++++++++ src/ui/AsciiRenderer.h | 33 +++++++++++ 10 files changed, 453 insertions(+) create mode 100644 .cproject create mode 100644 .project create mode 100644 .settings/language.settings.xml create mode 100644 src/diagram/Statement.cpp create mode 100644 src/diagram/Statement.hpp create mode 100644 src/diagram/Structogram.cpp create mode 100644 src/diagram/Structogram.hpp create mode 100644 src/main.cpp create mode 100644 src/ui/AsciiRenderer.cpp create mode 100644 src/ui/AsciiRenderer.h diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..46b958f --- /dev/null +++ b/.cproject @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..9763d1b --- /dev/null +++ b/.project @@ -0,0 +1,27 @@ + + + TitaniumLadybug + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml new file mode 100644 index 0000000..e8985aa --- /dev/null +++ b/.settings/language.settings.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/diagram/Statement.cpp b/src/diagram/Statement.cpp new file mode 100644 index 0000000..75770db --- /dev/null +++ b/src/diagram/Statement.cpp @@ -0,0 +1,12 @@ +/* + * Statement.cpp + * + * Created on: Nov 23, 2017 + * Author: naopross + */ + +#include "../diagram/Statement.h" + +namespace samb { + +} /* namespace samb */ diff --git a/src/diagram/Statement.hpp b/src/diagram/Statement.hpp new file mode 100644 index 0000000..a90e88d --- /dev/null +++ b/src/diagram/Statement.hpp @@ -0,0 +1,60 @@ +/* + * Statement.h + * + * Created on: Nov 23, 2017 + * Author: naopross + */ + +#ifndef SRC_STATEMENT_H_ +#define SRC_STATEMENT_H_ + +#include + +namespace samb { + + +/* Possible types of statement, according to the NS diagram paper + * + * PROCESS, + * DECISION, + * SWITCH, + * WHILE, + * UNTIL, + * SCOPE, + * PARALLEL, + */ + +/* this class should behave like a std::list, or a std::map storing the data + * with a tree structure, BUT it is not a tree because allows 2 notes to point + * at a single node + * + * Normal Tree: Statements: + * A - B - C - D A - B - C - D - G + * \ \ / + * E - F E - F + * + * Because a statement contains branching elmeents. (if / switch) + */ +class Statement { +private: + Statement *next; + Statement *prev; + +public: + const enum Type { + PROCESS, + DECISION, + SWITCH, + WHILE, + UNTIL, + SCOPE, + PARALLEL, + } m_type; + + Statement(Type type, Statement *prev): m_type(type), m_prev(prev); + virtual ~Statement(); +}; + +} /* namespace samb */ + +#endif /* SRC_STATEMENT_H_ */ diff --git a/src/diagram/Structogram.cpp b/src/diagram/Structogram.cpp new file mode 100644 index 0000000..dae9028 --- /dev/null +++ b/src/diagram/Structogram.cpp @@ -0,0 +1,27 @@ +/* + * Structogram.cpp + * + * Created on: Nov 14, 2017 + * Author: naopross + */ + +#include "../diagram/Structogram.h" +#include + + +namespace samb { + +Structogram::Structogram(std::string title): m_title(title) { + +} + +Structogram::~Structogram() { + +} + +const std::list& Structogram::getStatements() const { + return m_statements; +} + + +} /* namespace structograms */ diff --git a/src/diagram/Structogram.hpp b/src/diagram/Structogram.hpp new file mode 100644 index 0000000..2234142 --- /dev/null +++ b/src/diagram/Structogram.hpp @@ -0,0 +1,32 @@ +/* + * Structogram.h + * + * Created on: Nov 14, 2017 + * Author: naopross + */ + +#ifndef STRUCTOGRAM_H_ +#define STRUCTOGRAM_H_ + +#include +#include +#include "../diagram/Statement.h" + +namespace samb { + +/* object that holds statements */ +class Structogram { +private: + std::list m_statements; + std::string m_title; + +public: + Structogram(std::string title); + virtual ~Structogram(); + + const std::list& getStatements() const; +}; + +} /* namespace structograms */ + +#endif /* STRUCTOGRAM_H_ */ diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..5ea2172 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,16 @@ +#include "diagram/Structogram.h" +#include +#include "ui/AsciiRenderer.h" + +int main(int argc, char *argv[]) { + samb::Structogram st("Demo"); + samb::AsciiRenderer renderer(st, 60); + + renderer.render(); + + return 0; +} + + + + diff --git a/src/ui/AsciiRenderer.cpp b/src/ui/AsciiRenderer.cpp new file mode 100644 index 0000000..0f17d85 --- /dev/null +++ b/src/ui/AsciiRenderer.cpp @@ -0,0 +1,97 @@ +/* + * Renderer.cpp + * + * Created on: Nov 23, 2017 + * Author: naopross + */ + +#include "AsciiRenderer.h" + +#include + +namespace samb { + +AsciiRenderer::AsciiRenderer(Structogram& structogram, unsigned int width): + m_structogram(structogram), m_width(width) {} + +AsciiRenderer::~AsciiRenderer() {} + +void AsciiRenderer::drawPadding(unsigned int amt) { + while (amt--) { + std::cout << " "; + } +} + +void AsciiRenderer::drawLine() const { + for (unsigned int i = 0; i < m_width; i++) { + std::cout << "-"; + } + + std::cout << std::endl; +} + +void AsciiRenderer::drawText(std::string text, unsigned int width, std::string before, std::string after) const { + + if (width == 0) { + width = m_width; + } + + unsigned int textWidth = width - before.length() - after.length(); + + + std::cout << before; + for (unsigned int i = 0; i < text.length(); i++) { + if (i % textWidth == 0) { + std::cout << after << "\n" << before; + } + + std::cout << text[i]; + } + + std::cout << std::endl; +} + +void AsciiRenderer::drawDecision(std::string condition, std::string trueText, std::string falseText, unsigned int width) const { + if (width == 0) { + width = m_width -2; + } + + std::cout << "|"; + +// drawPadding(width - condition.length()); +} + +void AsciiRenderer::render() { + const std::list& statements = m_structogram.getStatements(); + + for (std::list::const_iterator it = statements.begin(); it != statements.end(); it++) { + Statement st = *it; + switch (st.type) { + case Statement::Type::PROCESS: + drawLine(); + drawText(st.text); + break; + + case Statement::Type::DECISION: + drawLine(); + break; + + case Statement::Type::SWITCH: + break; + + case Statement::Type::SCOPE: + break; + + case Statement::Type::WHILE: + break; + + case Statement::Type::UNTIL: + break; + + case Statement::Type::PARALLEL: + break; + } + } +} + +} /* namespace samb */ diff --git a/src/ui/AsciiRenderer.h b/src/ui/AsciiRenderer.h new file mode 100644 index 0000000..4f9020a --- /dev/null +++ b/src/ui/AsciiRenderer.h @@ -0,0 +1,33 @@ +/* + * Renderer.h + * + * Created on: Nov 23, 2017 + * Author: naopross + */ + +#ifndef SRC_UI_ASCIIRENDERER_H_ +#define SRC_UI_ASCIIRENDERER_H_ + +#include "../diagram/Structogram.h" + +namespace samb { + +class AsciiRenderer { +private: + Structogram m_structogram; + const unsigned int m_width; + + void drawPadding(unsigned int amt); + void drawLine() const; + void drawText(std::string text, unsigned int width = 0, std::string before = "|", std::string after = "|") const; + void drawDecision(std::string condition, std::string trueText, std::string falseText, unsigned int width = 0) const; +public: + AsciiRenderer(Structogram& structogram, unsigned int width); + ~AsciiRenderer(); + + void render(); +}; + +} /* namespace samb */ + +#endif /* SRC_UI_ASCIIRENDERER_H_ */ -- cgit v1.2.1