From 52920a76b69c229735172d411d1949c138ed2498 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 12 Aug 2014 09:22:35 +0200 Subject: [PATCH] templated wrapper of label --- alib2data/src/common/wrapper.hpp | 4 + alib2data/src/label/Label.cpp | 86 ------------------- alib2data/src/label/Label.h | 30 +------ alib2data/src/label/LabelToStringComposer.cpp | 2 +- alib2data/src/label/LabelToXMLComposer.cpp | 2 +- alib2data/src/label/NextLabel.cpp | 2 +- 6 files changed, 9 insertions(+), 117 deletions(-) delete mode 100644 alib2data/src/label/Label.cpp diff --git a/alib2data/src/common/wrapper.hpp b/alib2data/src/common/wrapper.hpp index f1ba7aff7f..3b674f9bb2 100644 --- a/alib2data/src/common/wrapper.hpp +++ b/alib2data/src/common/wrapper.hpp @@ -82,6 +82,10 @@ public: os << *(instance.data); return os; } + + operator std::string () const { + return (std::string) *data; + } }; } /* namespace alib */ diff --git a/alib2data/src/label/Label.cpp b/alib2data/src/label/Label.cpp deleted file mode 100644 index c54a821e43..0000000000 --- a/alib2data/src/label/Label.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Label.cpp - * - * Created on: Apr 16, 2013 - * Author: Jan Travnicek - */ - -#include "Label.h" - -namespace label { - -Label::Label(const LabelBase& label) : label(label.clone()) { - -} - -Label::Label(LabelBase&& label) : label(std::move(label).plunder()) { - -} - -Label::Label(const Label& other) : label(other.getLabel().clone()) { - -} - -Label::Label(Label&& other) noexcept : label(other.label) { - other.label = NULL; -} - -Label& Label::operator=(const Label& other) { - if(this == &other) return *this; - - delete label; - label = other.getLabel().clone(); - - return *this; -} - -Label& Label::operator=(Label&& other) noexcept { - std::swap(this->label, other.label); - return *this; -} - -Label::~Label() { - delete label; -} - -const LabelBase& Label::getLabel() const { - return *label; -} - -LabelBase& Label::getLabel() { - return *label; -} - -void Label::setLabel(const LabelBase& label) { - delete this->label; - this->label = label.clone(); -} - -void Label::setLabel(LabelBase&& label) { - delete this->label; - this->label = std::move(label).plunder(); -} - -bool Label::operator!=(const Label& other) const { - return !(*this == other); -} - -bool Label::operator<(const Label& other) const { - return *label < *other.label; -} - -bool Label::operator==(const Label& other) const { - return *label == *other.label; -} - -std::ostream& operator<<(std::ostream& os, const Label& label) { - os << label.getLabel(); - return os; -} - -Label::operator std::string () const { - return (std::string) *label; -} - -} /* namespace label */ - diff --git a/alib2data/src/label/Label.h b/alib2data/src/label/Label.h index 608c440433..7ed6d1e12e 100644 --- a/alib2data/src/label/Label.h +++ b/alib2data/src/label/Label.h @@ -9,6 +9,7 @@ #define LABEL_H_ #include "../std/visitor.hpp" +#include "../common/wrapper.hpp" #include "LabelBase.h" namespace label { @@ -16,34 +17,7 @@ namespace label { /** * Wrapper around automata. */ -class Label { -protected: - LabelBase* label; -public: - explicit Label(const LabelBase& label); - explicit Label(LabelBase&& label); - Label(const Label& other); - Label(Label&&) noexcept; - Label& operator=(const Label& other); - Label& operator=(Label&& other) noexcept; - virtual ~Label() noexcept; - - const LabelBase& getLabel() const; - LabelBase& getLabel(); - - void setLabel(const LabelBase& label); - void setLabel(LabelBase&& label); - - bool operator<(const Label& other) const; - - bool operator!=(const Label& other) const; - - bool operator==(const Label& other) const; - - friend std::ostream& operator<<(std::ostream& os, const Label& label); - - operator std::string () const; -}; +typedef alib::wrapper<LabelBase> Label; } /* namespace label */ diff --git a/alib2data/src/label/LabelToStringComposer.cpp b/alib2data/src/label/LabelToStringComposer.cpp index 0480d50a2f..722bf0a182 100644 --- a/alib2data/src/label/LabelToStringComposer.cpp +++ b/alib2data/src/label/LabelToStringComposer.cpp @@ -42,7 +42,7 @@ void LabelToStringComposer::Visit(void* userData, const IntegerLabel& symbol) { } void LabelToStringComposer::Visit(void* userData, const Label& symbol) { - symbol.getLabel().Accept(userData, *this); + symbol.getData().Accept(userData, *this); } diff --git a/alib2data/src/label/LabelToXMLComposer.cpp b/alib2data/src/label/LabelToXMLComposer.cpp index f87828ea66..74d5efc2ec 100644 --- a/alib2data/src/label/LabelToXMLComposer.cpp +++ b/alib2data/src/label/LabelToXMLComposer.cpp @@ -38,7 +38,7 @@ void LabelToXMLComposer::Visit(void* userData, const StringLabel& label) const { } void LabelToXMLComposer::Visit(void* userData, const Label& label) const { - label.getLabel().Accept(userData, *this); + label.getData().Accept(userData, *this); } diff --git a/alib2data/src/label/NextLabel.cpp b/alib2data/src/label/NextLabel.cpp index c08ae9ff5f..51e60c3363 100644 --- a/alib2data/src/label/NextLabel.cpp +++ b/alib2data/src/label/NextLabel.cpp @@ -32,7 +32,7 @@ void NextLabel::Visit(void* userData, const StringLabel& label) { } void NextLabel::Visit(void* userData, const Label& label) { - label.getLabel().Accept(userData, *this); + label.getData().Accept(userData, *this); } -- GitLab