Added skiprelationship command

This commit is contained in:
Bartek Kryza
2021-07-29 17:23:03 +02:00
parent 0e941c90fb
commit 70f195bb8e
3 changed files with 52 additions and 10 deletions

View File

@@ -25,18 +25,27 @@
namespace clanguml { namespace clanguml {
namespace command_parser { namespace command_parser {
const std::string note::label = "note";
const std::string skip::label = "skip";
const std::string skip_relationship::label = "skiprelationship";
const std::string style::label = "style";
const std::string aggregation::label = "aggregation";
std::shared_ptr<command> command::from_string(std::string_view c) std::shared_ptr<command> command::from_string(std::string_view c)
{ {
if (c.find("note") == 0) { if (c.find(note::label) == 0) {
return note::from_string(c); return note::from_string(c);
} }
else if (c.find("skip") == 0) { else if (c.find(skip::label) == 0) {
return skip::from_string(c); return skip::from_string(c);
} }
else if (c.find("style") == 0) { else if (c.find(skip_relationship::label) == 0) {
return skip_relationship::from_string(c);
}
else if (c.find(style::label) == 0) {
return style::from_string(c); return style::from_string(c);
} }
else if (c.find("aggregation") == 0) { else if (c.find(aggregation::label) == 0) {
return aggregation::from_string(c); return aggregation::from_string(c);
} }
@@ -47,8 +56,7 @@ std::shared_ptr<command> note::from_string(std::string_view c)
{ {
auto res = std::make_shared<note>(); auto res = std::make_shared<note>();
auto it = c.begin(); auto it = c.begin();
// Skip 'note' std::advance(it, note::label.size());
std::advance(it, 4);
if (*it != '[') if (*it != '[')
return {}; return {};
@@ -75,13 +83,17 @@ std::shared_ptr<command> skip::from_string(std::string_view c)
return res; return res;
} }
std::shared_ptr<command> skip_relationship::from_string(std::string_view c)
{
auto res = std::make_shared<skip_relationship>();
return res;
}
std::shared_ptr<command> style::from_string(std::string_view c) std::shared_ptr<command> style::from_string(std::string_view c)
{ {
auto res = std::make_shared<style>(); auto res = std::make_shared<style>();
auto it = c.begin(); auto it = c.begin();
// Skip 'style' std::advance(it, style::label.size());
std::advance(it, 5);
if (*it != '[') if (*it != '[')
return {}; return {};
@@ -100,8 +112,7 @@ std::shared_ptr<command> aggregation::from_string(std::string_view c)
{ {
auto res = std::make_shared<aggregation>(); auto res = std::make_shared<aggregation>();
auto it = c.begin(); auto it = c.begin();
// Skip 'aggregation' std::advance(it, aggregation::label.size());
std::advance(it, 11);
if (*it != '[') if (*it != '[')
return {}; return {};

View File

@@ -32,6 +32,8 @@ struct command {
}; };
struct note : public command { struct note : public command {
static const std::string label;
std::string position; std::string position;
std::string text; std::string text;
@@ -39,15 +41,27 @@ struct note : public command {
}; };
struct skip : public command { struct skip : public command {
static const std::string label;
static std::shared_ptr<command> from_string(std::string_view c);
};
struct skip_relationship : public command {
static const std::string label;
static std::shared_ptr<command> from_string(std::string_view c); static std::shared_ptr<command> from_string(std::string_view c);
}; };
struct style : public command { struct style : public command {
static const std::string label;
std::string spec; std::string spec;
static std::shared_ptr<command> from_string(std::string_view c); static std::shared_ptr<command> from_string(std::string_view c);
}; };
struct aggregation : public command { struct aggregation : public command {
static const std::string label;
std::string multiplicity; std::string multiplicity;
static std::shared_ptr<command> from_string(std::string_view c); static std::shared_ptr<command> from_string(std::string_view c);
}; };

View File

@@ -128,3 +128,20 @@ TEST_CASE("Test command parser on skip", "[unit-test]")
CHECK(n1); CHECK(n1);
} }
TEST_CASE("Test command parser on skiprelationship", "[unit-test]")
{
std::string comment = R"(
\clanguml{skiprelationship}
)";
using namespace clanguml::command_parser;
auto commands = parse(comment);
CHECK(commands.size() == 1);
auto n1 = std::dynamic_pointer_cast<skip_relationship>(commands.at(0));
CHECK(n1);
}