diff --git a/alib2data/src/alphabet/NextSymbol.cpp b/alib2data/src/alphabet/NextSymbol.cpp index b4e58180ec4273323906fc65b9d464754cd36f71..6b371c4b876dab81d1f72ecbbcfcdc4090edc183 100644 --- a/alib2data/src/alphabet/NextSymbol.cpp +++ b/alib2data/src/alphabet/NextSymbol.cpp @@ -6,7 +6,6 @@ */ #include "NextSymbol.h" -#include "../label/NextLabel.h" #include "LabeledSymbol.h" #include "RankedSymbol.h" #include "SymbolPairSymbol.h" @@ -25,11 +24,11 @@ namespace alphabet { void NextSymbol::Visit(void* userData, const LabeledSymbol& symbol) const { Symbol* &out = *((Symbol**) userData); - out = new Symbol(LabeledSymbol(label::NextLabel::nextLabel(symbol.getLabel()))); + out = new Symbol(LabeledSymbol(symbol.getLabel().next())); } void NextSymbol::Visit(void*, LabeledSymbol& symbol) const { - label::NextLabel::nextLabel(symbol.getLabel()); + symbol.getLabel().inc(); } void NextSymbol::Visit(void* userData, const BlankSymbol& symbol) const { diff --git a/alib2data/src/automaton/Automaton.cpp b/alib2data/src/automaton/Automaton.cpp index 4485dc10a05b36ab6e2c55eefedc59de86f1a1cf..44c46338bac171d8bb295f07867aeaec6e787993 100644 --- a/alib2data/src/automaton/Automaton.cpp +++ b/alib2data/src/automaton/Automaton.cpp @@ -7,7 +7,6 @@ #include "Automaton.h" #include "common/State.h" -#include "../label/NextLabel.h" #include <climits> #include "AutomatonException.h" @@ -16,7 +15,7 @@ namespace automaton { State createUniqueState(State nextState, const std::set<State>& other) { int i = 0; do { - label::NextLabel::nextLabel(nextState.getName()); + nextState.getName().inc(); if(other.count(nextState) == 0) return std::move(nextState); } while(++i < INT_MAX); diff --git a/alib2data/src/common/wrapper.hpp b/alib2data/src/common/wrapper.hpp index 66ed1d4afef8dd04b62d4818cb6524c005830c30..a6874ac07e87541228dcb475c7417db1ce8be0ea 100644 --- a/alib2data/src/common/wrapper.hpp +++ b/alib2data/src/common/wrapper.hpp @@ -39,6 +39,10 @@ public: return *data; } + void setData(T* data) { + this->data = std::cow_shared_ptr<T>(data); + } + void setData(const T& data) { this->data = std::cow_shared_ptr<T>(data.clone()); } diff --git a/alib2data/src/label/HexavigesimalLabel.cpp b/alib2data/src/label/HexavigesimalLabel.cpp index c5f6c00e89bb4e5aec1fa367a6d2d4f4317e57f3..272fa1a7dfc0117abeba07c5c8858002fc447a44 100644 --- a/alib2data/src/label/HexavigesimalLabel.cpp +++ b/alib2data/src/label/HexavigesimalLabel.cpp @@ -60,6 +60,15 @@ void HexavigesimalLabel::compose(std::deque<sax::Token>& out) const { out.emplace_back(HexavigesimalLabel::XML_TAG_NAME, sax::Token::TokenType::END_ELEMENT); } +LabelBase* HexavigesimalLabel::next() const { + return new HexavigesimalLabel(hexavigesimal + 1); +} + +LabelBase* HexavigesimalLabel::inc() && { + hexavigesimal++; + return NULL; +} + } /* namespace label */ namespace alib { diff --git a/alib2data/src/label/HexavigesimalLabel.h b/alib2data/src/label/HexavigesimalLabel.h index b39da67ceb029fd449c54087ac96566f645494b2..097379a99a8c048d403dade80cbc6921bdfb6c82 100644 --- a/alib2data/src/label/HexavigesimalLabel.h +++ b/alib2data/src/label/HexavigesimalLabel.h @@ -58,6 +58,9 @@ public: static HexavigesimalLabel parse(std::deque<sax::Token>::iterator& input); void compose(std::deque<sax::Token>& out) const; + + virtual LabelBase* next() const; + virtual LabelBase* inc() &&; }; } /* namespace label */ diff --git a/alib2data/src/label/Label.cpp b/alib2data/src/label/Label.cpp index e1e82ab841ebda02b5cce9669522c84183153216..ca4688e80ef23ece0209078a8b1a53d6458c96ea 100644 --- a/alib2data/src/label/Label.cpp +++ b/alib2data/src/label/Label.cpp @@ -12,6 +12,16 @@ namespace label { +Label Label::next() const { + return Label(this->getData().next()); +} + +void Label::inc() { + LabelBase* res = std::move(this->getData()).inc(); + if(res == NULL) return; + this->setData(res); +} + label::Label labelFrom(int number) { return label::Label { label::PrimitiveLabel { primitive::primitiveFrom (number) } }; } diff --git a/alib2data/src/label/Label.h b/alib2data/src/label/Label.h index 0a9b7b66a275a3be17c8be3df2699d3f317534cb..4b0a0a61e134760875ce5f66282b256e2618e812 100644 --- a/alib2data/src/label/Label.h +++ b/alib2data/src/label/Label.h @@ -19,6 +19,10 @@ namespace label { */ class Label : public alib::wrapper<LabelBase>, public alib::WrapperBase { using alib::wrapper<LabelBase>::wrapper; + +public: + Label next() const; + void inc(); }; label::Label labelFrom(int number); diff --git a/alib2data/src/label/LabelBase.h b/alib2data/src/label/LabelBase.h index c5030f0fa5e6d5b96873baebecd2c761144aa876..0f06d2cec10a0fe34eacb84a61c4615f77ef6a08 100644 --- a/alib2data/src/label/LabelBase.h +++ b/alib2data/src/label/LabelBase.h @@ -41,6 +41,9 @@ public: virtual LabelBase* clone() const = 0; virtual LabelBase* plunder() && = 0; + + virtual LabelBase* next() const = 0; + virtual LabelBase* inc() && = 0; }; } /* namespace label */ diff --git a/alib2data/src/label/LabelPairLabel.cpp b/alib2data/src/label/LabelPairLabel.cpp index ef71bb9a58e2abbb7a1092acd0667b33126d394f..424cfd5beed7dba96d55d3df7059dc0a409564fb 100644 --- a/alib2data/src/label/LabelPairLabel.cpp +++ b/alib2data/src/label/LabelPairLabel.cpp @@ -11,6 +11,7 @@ #include "Label.h" #include "../object/Object.h" #include "../XmlApi.hpp" +#include "UniqueLabel.h" namespace label { @@ -70,6 +71,14 @@ void LabelPairLabel::compose(std::deque<sax::Token>& out) const { out.emplace_back(LabelPairLabel::XML_TAG_NAME, sax::Token::TokenType::END_ELEMENT); } +LabelBase* LabelPairLabel::next() const { + return new UniqueLabel(Label(*this), primitive::Integer(0)); +} + +LabelBase* LabelPairLabel::inc() && { + return new UniqueLabel(Label(std::move(*this)), primitive::Integer(0)); +} + } /* namespace label */ namespace alib { diff --git a/alib2data/src/label/LabelPairLabel.h b/alib2data/src/label/LabelPairLabel.h index e3e07477b381729f4032a63cba37a4ac40176900..e6bb8c3fad2c6f17193cbe378b3c43c34d2e41a9 100644 --- a/alib2data/src/label/LabelPairLabel.h +++ b/alib2data/src/label/LabelPairLabel.h @@ -55,6 +55,9 @@ public: static LabelPairLabel parse(std::deque<sax::Token>::iterator& input); void compose(std::deque<sax::Token>& out) const; + + virtual LabelBase* next() const; + virtual LabelBase* inc() &&; }; } /* namespace label */ diff --git a/alib2data/src/label/LabelSetLabel.cpp b/alib2data/src/label/LabelSetLabel.cpp index 3964755e62d9cafbb5cbb0ba3d8e246f3f638592..cdc5277786c8a403179add06172658ab331739aa 100644 --- a/alib2data/src/label/LabelSetLabel.cpp +++ b/alib2data/src/label/LabelSetLabel.cpp @@ -11,6 +11,7 @@ #include "Label.h" #include "../object/Object.h" #include "../XmlApi.hpp" +#include "UniqueLabel.h" namespace label { @@ -75,6 +76,14 @@ void LabelSetLabel::compose(std::deque<sax::Token>& out) const { out.emplace_back(LabelSetLabel::XML_TAG_NAME, sax::Token::TokenType::END_ELEMENT); } +LabelBase* LabelSetLabel::next() const { + return new UniqueLabel(Label(*this), primitive::Integer(0)); +} + +LabelBase* LabelSetLabel::inc() && { + return new UniqueLabel(Label(std::move(*this)), primitive::Integer(0)); +} + } /* namespace label */ namespace alib { diff --git a/alib2data/src/label/LabelSetLabel.h b/alib2data/src/label/LabelSetLabel.h index 11e047d51f644df94dc5f68932257ebe0686135b..55bf621eff60086bac9b16af909422b95df3092e 100644 --- a/alib2data/src/label/LabelSetLabel.h +++ b/alib2data/src/label/LabelSetLabel.h @@ -55,6 +55,9 @@ public: static LabelSetLabel parse(std::deque<sax::Token>::iterator& input); void compose(std::deque<sax::Token>& out) const; + + virtual LabelBase* next() const; + virtual LabelBase* inc() &&; }; } /* namespace label */ diff --git a/alib2data/src/label/NextLabel.cpp b/alib2data/src/label/NextLabel.cpp deleted file mode 100644 index 30fede9afc37460a16e89603e77e7961f3f156b6..0000000000000000000000000000000000000000 --- a/alib2data/src/label/NextLabel.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * NextLabel.cpp - * - * Created on: Nov 23, 2013 - * Author: Jan Travnicek - */ - -#include "NextLabel.h" -#include "PrimitiveLabel.h" -#include "HexavigesimalLabel.h" -#include "LabelSetLabel.h" -#include "ObjectLabel.h" -#include "LabelPairLabel.h" -#include "UniqueLabel.h" - -namespace label { - -void NextLabel::Visit(void* userData, const PrimitiveLabel& label) const { - Label* &out = *((Label**) userData); - - out = new Label(PrimitiveLabel(label.getData().next())); -} - -void NextLabel::Visit(void*, PrimitiveLabel& label) const { - label.getData().inc(); -} - -void NextLabel::Visit(void* userData, const HexavigesimalLabel& label) const { - Label* &out = *((Label**) userData); - - out = new Label(HexavigesimalLabel(label.getData() + 1)); -} - -void NextLabel::Visit(void*, HexavigesimalLabel& label) const { - label.setData(label.getData() + 1); -} - -void NextLabel::Visit(void* userData, const ObjectLabel& label) const { - Label* &out = *((Label**) userData); - - out = new Label(UniqueLabel(Label(label), primitive::Integer(0))); -} - -void NextLabel::Visit(void* userData, ObjectLabel&) const { - Label &out = *((Label*) userData); - - out = Label(UniqueLabel(std::move(out), primitive::Integer(0))); -} - -void NextLabel::Visit(void* userData, const LabelSetLabel& label) const { - Label* &out = *((Label**) userData); - - out = new Label(UniqueLabel(Label(label), primitive::Integer(0))); -} - -void NextLabel::Visit(void* userData, LabelSetLabel&) const { - Label &out = *((Label*) userData); - - out = Label(UniqueLabel(std::move(out), primitive::Integer(0))); -} - -void NextLabel::Visit(void* userData, const LabelPairLabel& label) const { - Label* &out = *((Label**) userData); - - out = new Label(UniqueLabel(Label(label), primitive::Integer(0))); -} - -void NextLabel::Visit(void* userData, LabelPairLabel&) const { - Label &out = *((Label*) userData); - - out = Label(UniqueLabel(std::move(out), primitive::Integer(0))); -} - -void NextLabel::Visit(void* userData, const UniqueLabel& label) const { - Label* &out = *((Label**) userData); - - out = new Label(UniqueLabel(label.getLabel(), primitive::Integer(label.getId().getData() + 1))); -} - -void NextLabel::Visit(void*, UniqueLabel& label) const { - label.getId().setData(label.getId().getData() + 1); -} - -Label NextLabel::nextLabel(const Label& label) { - Label* out; - label.getData().Accept((void*) &out, NextLabel::NEXT_LABEL); - - Label nextLabel(std::move(*out)); - delete out; - return std::move(nextLabel); -} - -void NextLabel::nextLabel(Label& label) { - label.getData().Accept((void*) &label, NextLabel::NEXT_LABEL); -} - -const NextLabel NextLabel::NEXT_LABEL; - -} /* namespace label */ diff --git a/alib2data/src/label/NextLabel.h b/alib2data/src/label/NextLabel.h deleted file mode 100644 index d72a33f8c7299ebe10d7c709faecb0022c5117c0..0000000000000000000000000000000000000000 --- a/alib2data/src/label/NextLabel.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * NextLabel.h - * - * Created on: Nov 23, 2013 - * Author: Jan Travnciek - */ - -#ifndef NEXT_LABEL_H_ -#define NEXT_LABEL_H_ - -#include "LabelFeatures.h" -#include "LabelBase.h" - -namespace label { - -/** - * This class contains methods to print XML representation of string to the output stream. - */ -class NextLabel : public VisitableLabelBase::const_visitor_type, public VisitableLabelBase::visitor_type { - void Visit(void*, const PrimitiveLabel& label) const; - void Visit(void*, PrimitiveLabel& label) const; - - void Visit(void*, const HexavigesimalLabel& label) const; - void Visit(void*, HexavigesimalLabel& label) const; - - void Visit(void*, const ObjectLabel& label) const; - void Visit(void*, ObjectLabel& label) const; - - void Visit(void*, const LabelSetLabel& label) const; - void Visit(void*, LabelSetLabel& label) const; - - void Visit(void*, const LabelPairLabel& label) const; - void Visit(void*, LabelPairLabel& label) const; - - void Visit(void*, const UniqueLabel& label) const; - void Visit(void*, UniqueLabel& label) const; - -public: - NextLabel() {} - - /** - * Prints XML representation of String to the output stream. - * @param string String to print - * @param out output stream to which print the String - */ - static Label nextLabel(const Label& label); - - static void nextLabel(Label& label); - - static const NextLabel NEXT_LABEL; -}; - -} /* namespace label */ - -#endif /* NEXT_LABEL_H_ */ diff --git a/alib2data/src/label/ObjectLabel.cpp b/alib2data/src/label/ObjectLabel.cpp index 5419423141da3399135dcbcf4d3418f9a48b4524..5d40ef75a46702266e0166519b68235c82005e92 100644 --- a/alib2data/src/label/ObjectLabel.cpp +++ b/alib2data/src/label/ObjectLabel.cpp @@ -10,6 +10,7 @@ #include "Label.h" #include "../object/Object.h" #include "../XmlApi.hpp" +#include "UniqueLabel.h" namespace label { @@ -56,6 +57,14 @@ void ObjectLabel::compose(std::deque<sax::Token>& out) const { out.emplace_back(ObjectLabel::XML_TAG_NAME, sax::Token::TokenType::END_ELEMENT); } +LabelBase* ObjectLabel::next() const { + return new UniqueLabel(Label(*this), primitive::Integer(0)); +} + +LabelBase* ObjectLabel::inc() && { + return new UniqueLabel(Label(std::move(*this)), primitive::Integer(0)); +} + } /* namespace label */ namespace alib { diff --git a/alib2data/src/label/ObjectLabel.h b/alib2data/src/label/ObjectLabel.h index 769004aec953cf088f2453dc24aae192b9f1603e..7dd0711c8f9d6c17971790442b07db18c15f46a3 100644 --- a/alib2data/src/label/ObjectLabel.h +++ b/alib2data/src/label/ObjectLabel.h @@ -56,6 +56,9 @@ public: static ObjectLabel parse(std::deque<sax::Token>::iterator& input); void compose(std::deque<sax::Token>& out) const; + + virtual LabelBase* next() const; + virtual LabelBase* inc() &&; }; } /* namespace label */ diff --git a/alib2data/src/label/PrimitiveLabel.cpp b/alib2data/src/label/PrimitiveLabel.cpp index 1133ea0b79f402bbecb07c0aec86bc124c521282..a895a07b842ec32863088450b9c7f28081d17ec9 100644 --- a/alib2data/src/label/PrimitiveLabel.cpp +++ b/alib2data/src/label/PrimitiveLabel.cpp @@ -10,6 +10,7 @@ #include "Label.h" #include "../object/Object.h" #include "../XmlApi.hpp" +#include "UniqueLabel.h" namespace label { @@ -60,6 +61,15 @@ void PrimitiveLabel::compose(std::deque<sax::Token>& out) const { out.emplace_back(PrimitiveLabel::XML_TAG_NAME, sax::Token::TokenType::END_ELEMENT); } +LabelBase* PrimitiveLabel::next() const { + return new PrimitiveLabel(primitive.next()); +} + +LabelBase* PrimitiveLabel::inc() && { + primitive.inc(); + return NULL; +} + } /* namespace label */ namespace alib { diff --git a/alib2data/src/label/PrimitiveLabel.h b/alib2data/src/label/PrimitiveLabel.h index 0207928a77db9f36b8b21a7beed34b4d9d5e4904..c1eda1b881aa384b3e9a648063a5651ac90dbe01 100644 --- a/alib2data/src/label/PrimitiveLabel.h +++ b/alib2data/src/label/PrimitiveLabel.h @@ -58,6 +58,9 @@ public: static PrimitiveLabel parse(std::deque<sax::Token>::iterator& input); void compose(std::deque<sax::Token>& out) const; + + virtual LabelBase* next() const; + virtual LabelBase* inc() &&; }; } /* namespace label */ diff --git a/alib2data/src/label/UniqueLabel.cpp b/alib2data/src/label/UniqueLabel.cpp index 39130c8b1749f2c3676badbb4c630d173011706c..eb5c4e378a194f6333b7a1209424cc6116cc123b 100644 --- a/alib2data/src/label/UniqueLabel.cpp +++ b/alib2data/src/label/UniqueLabel.cpp @@ -78,6 +78,15 @@ void UniqueLabel::compose(std::deque<sax::Token>& out) const { out.emplace_back(UniqueLabel::XML_TAG_NAME, sax::Token::TokenType::END_ELEMENT); } +LabelBase* UniqueLabel::next() const { + return new UniqueLabel(label, id.next()); +} + +LabelBase* UniqueLabel::inc() && { + id.inc(); + return NULL; +} + } /* namespace label */ namespace alib { diff --git a/alib2data/src/label/UniqueLabel.h b/alib2data/src/label/UniqueLabel.h index 87e196a0492137a9b60b075928684b16dadd1b91..4ac916e929099f74ea28eeacbb85dff5a7a380cd 100644 --- a/alib2data/src/label/UniqueLabel.h +++ b/alib2data/src/label/UniqueLabel.h @@ -60,6 +60,9 @@ public: static UniqueLabel parse(std::deque<sax::Token>::iterator& input); void compose(std::deque<sax::Token>& out) const; + + virtual LabelBase* next() const; + virtual LabelBase* inc() &&; }; } /* namespace label */