Skip to content
Snippets Groups Projects
Commit 52920a76 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

templated wrapper of label

parent 99fa2f18
No related branches found
No related tags found
No related merge requests found
......@@ -82,6 +82,10 @@ public:
os << *(instance.data);
return os;
}
operator std::string () const {
return (std::string) *data;
}
};
 
} /* namespace alib */
......
/*
* 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 */
......@@ -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 */
 
......
......@@ -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);
 
}
 
......
......@@ -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);
 
}
 
......
......@@ -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);
 
}
 
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment