diff --git a/alib2data/src/alphabet/Symbol.cpp b/alib2data/src/alphabet/Symbol.cpp index 293c0a609ef2d8289518696173df134111a48ea1..91fa969ef9ff4502b880712a2cee32de6390ebff 100644 --- a/alib2data/src/alphabet/Symbol.cpp +++ b/alib2data/src/alphabet/Symbol.cpp @@ -14,42 +14,57 @@ namespace alphabet { const std::string Symbol::XML_TAG_NAME_REF = "SymbolRef"; -Symbol Symbol::next() const { - return Symbol(this->getData().next()); +Symbol Symbol::next ( ) const { + return Symbol ( this->getData ( ).next ( ) ); } -void Symbol::inc() { - SymbolBase* res = std::move(this->getData()).inc(); - if(res == NULL) return; - this->setData(res); +void Symbol::inc ( ) { + SymbolBase * res = std::move ( this->getData ( ) ).inc ( ); + + if ( res == NULL ) return; + + this->setData ( res ); } -alphabet::Symbol createUniqueSymbol(alphabet::Symbol attempt, const std::set<alphabet::Symbol>& terminalAlphabet, const std::set<alphabet::Symbol>& nonterminalAlphabet) { +alphabet::Symbol createUniqueSymbol ( alphabet::Symbol attempt, const std::set < alphabet::Symbol > & terminalAlphabet, const std::set < alphabet::Symbol > & nonterminalAlphabet ) { int i = 0; + do { - attempt.inc(); - if(terminalAlphabet.count(attempt) == 0 && nonterminalAlphabet.count(attempt) == 0) + attempt.inc ( ); + + if ( ( terminalAlphabet.count ( attempt ) == 0 ) && ( nonterminalAlphabet.count ( attempt ) == 0 ) ) return attempt; - } while(++i < INT_MAX); + } while ( ++i < INT_MAX ); - throw exception::AlibException("Could not create unique symbol." ); + throw exception::AlibException ( "Could not create unique symbol." ); } -alphabet::Symbol symbolFrom( int number ) { - return alphabet::Symbol { alphabet::LabeledSymbol { label::labelFrom ( number ) } }; +alphabet::Symbol symbolFrom ( int number ) { + return alphabet::Symbol { + alphabet::LabeledSymbol { + label::labelFrom ( number ) + } + }; } -alphabet::Symbol symbolFrom( char character ) { - return alphabet::Symbol { alphabet::LabeledSymbol { label::labelFrom ( character ) } }; +alphabet::Symbol symbolFrom ( char character ) { + return alphabet::Symbol { + alphabet::LabeledSymbol { + label::labelFrom ( character ) + } + }; } -alphabet::Symbol symbolFrom( std::string string ) { - return alphabet::Symbol { alphabet::LabeledSymbol { label::labelFrom ( std::move( string ) ) } }; +alphabet::Symbol symbolFrom ( std::string string ) { + return alphabet::Symbol { + alphabet::LabeledSymbol { + label::labelFrom ( std::move ( string ) ) + } + }; } -alphabet::Symbol symbolFrom( const char* string ) { - return symbolFrom( (std::string) string ); +alphabet::Symbol symbolFrom ( const char * string ) { + return symbolFrom ( ( std::string ) string ); } } /* namespace alphabet */ - diff --git a/alib2data/src/alphabet/Symbol.h b/alib2data/src/alphabet/Symbol.h index 9ad6b71df662d44111ca013040e46ed81e56a931..9b7a5e8e3b35e87999e18c6e46aaf5ec86591934 100644 --- a/alib2data/src/alphabet/Symbol.h +++ b/alib2data/src/alphabet/Symbol.h @@ -20,12 +20,12 @@ namespace alphabet { /** * Wrapper around automata. */ -class Symbol : public alib::wrapper<SymbolBase>, public alib::WrapperBase { - using alib::wrapper<SymbolBase>::wrapper; +class Symbol : public alib::wrapper < SymbolBase >, public alib::WrapperBase { + using alib::wrapper < SymbolBase >::wrapper; public: - Symbol next() const; - void inc(); + Symbol next ( ) const; + void inc ( ); const static std::string XML_TAG_NAME_REF; }; @@ -37,25 +37,25 @@ public: * @throws AutomatonException if symbol could not be created * @return created symbol */ -alphabet::Symbol createUniqueSymbol(alphabet::Symbol base, const std::set<alphabet::Symbol>& terminals, const std::set<alphabet::Symbol>& nonterminals); +alphabet::Symbol createUniqueSymbol ( alphabet::Symbol base, const std::set < alphabet::Symbol > & terminals, const std::set < alphabet::Symbol > & nonterminals ); -alphabet::Symbol symbolFrom(int number); -alphabet::Symbol symbolFrom(char character); -alphabet::Symbol symbolFrom(std::string string); -alphabet::Symbol symbolFrom(const char* string); +alphabet::Symbol symbolFrom ( int number ); +alphabet::Symbol symbolFrom ( char character ); +alphabet::Symbol symbolFrom ( std::string string ); +alphabet::Symbol symbolFrom ( const char * string ); } /* namespace alphabet */ namespace std { -template<> -struct compare<alphabet::Symbol> { - int operator()(const alphabet::Symbol& first, const alphabet::Symbol& second) const { - return first.getData().compare(second.getData()); +template < > +struct compare < alphabet::Symbol > { + int operator ()( const alphabet::Symbol & first, const alphabet::Symbol & second ) const { + return first.getData ( ).compare ( second.getData ( ) ); } + }; } /* namespace std */ #endif /* SYMBOL_H_ */ - diff --git a/alib2data/src/automaton/Automaton.cpp b/alib2data/src/automaton/Automaton.cpp index 6091c46695ecaedf77386ce917f294e8c33e3c79..6ce1e8e61d73afcfcf7bbeba57f28f377ee31da4 100644 --- a/alib2data/src/automaton/Automaton.cpp +++ b/alib2data/src/automaton/Automaton.cpp @@ -14,16 +14,17 @@ namespace automaton { const std::string Automaton::XML_TAG_NAME_REF = "AutomatonRef"; -State createUniqueState(State nextState, const std::set<State>& other) { +State createUniqueState ( State nextState, const std::set < State > & other ) { int i = 0; + do { - nextState.getName().inc(); - if(other.count(nextState) == 0) + nextState.getName ( ).inc ( ); + + if ( other.count ( nextState ) == 0 ) return nextState; - } while(++i < INT_MAX); + } while ( ++i < INT_MAX ); - throw AutomatonException("Could not create unique state." ); + throw AutomatonException ( "Could not create unique state." ); } } /* namespace automaton */ - diff --git a/alib2data/src/automaton/Automaton.h b/alib2data/src/automaton/Automaton.h index 37808cafc2cf247541a9698338a136ae3bdc6fe0..c56bce939aa77f8cf769907dbffcd487bd038856 100644 --- a/alib2data/src/automaton/Automaton.h +++ b/alib2data/src/automaton/Automaton.h @@ -20,27 +20,27 @@ namespace automaton { /** * Wrapper around automata. */ -class Automaton : public alib::wrapper<AutomatonBase>, public alib::WrapperBase { - using alib::wrapper<AutomatonBase>::wrapper; +class Automaton : public alib::wrapper < AutomatonBase >, public alib::WrapperBase { + using alib::wrapper < AutomatonBase >::wrapper; public: const static std::string XML_TAG_NAME_REF; }; -State createUniqueState(State base, const std::set<State>& other); +State createUniqueState ( State base, const std::set < State > & other ); } /* namespace automaton */ namespace std { -template<> -struct compare<automaton::Automaton> { - int operator()(const automaton::Automaton& first, const automaton::Automaton& second) const { - return first.getData().compare(second.getData()); +template < > +struct compare < automaton::Automaton > { + int operator ()( const automaton::Automaton & first, const automaton::Automaton & second ) const { + return first.getData ( ).compare ( second.getData ( ) ); } + }; } /* namespace std */ #endif /* AUTOMATON_H_ */ - diff --git a/alib2data/src/container/Container.h b/alib2data/src/container/Container.h index 5e2bf1205e6faefbc42cb5a3152e93b1db227c29..1a91cbe22e0b885da73205ecc58373003a64293d 100644 --- a/alib2data/src/container/Container.h +++ b/alib2data/src/container/Container.h @@ -17,8 +17,8 @@ namespace container { /** * Wrapper around containers. */ -class Container : public alib::wrapper<ContainerBase>, public alib::WrapperBase { - using alib::wrapper<ContainerBase>::wrapper; +class Container : public alib::wrapper < ContainerBase >, public alib::WrapperBase { + using alib::wrapper < ContainerBase >::wrapper; public: const static std::string XML_TAG_NAME_REF; @@ -28,14 +28,14 @@ public: namespace std { -template<> -struct compare<container::Container> { - int operator()(const container::Container& first, const container::Container& second) const { - return first.getData().compare(second.getData()); +template < > +struct compare < container::Container > { + int operator ()( const container::Container & first, const container::Container & second ) const { + return first.getData ( ).compare ( second.getData ( ) ); } + }; } /* namespace std */ #endif /* CONTAINER_H_ */ - diff --git a/alib2data/src/factory/XmlDataFactory.hpp b/alib2data/src/factory/XmlDataFactory.hpp index f79c1707922fa007502bcefcec16963534ecd1cf..da8513923d99858b27eb7cf39a61fd933a750007 100644 --- a/alib2data/src/factory/XmlDataFactory.hpp +++ b/alib2data/src/factory/XmlDataFactory.hpp @@ -30,11 +30,12 @@ public: * @param filename path to the file * @return String */ - template<class T> - static T fromFile(const std::string& filename) { - std::deque<sax::Token> tokens; - sax::SaxParseInterface::parseFile(filename, tokens); - return fromTokens<T>(tokens); + template < class T > + static T fromFile ( const std::string & filename ) { + std::deque < sax::Token > tokens; + sax::SaxParseInterface::parseFile ( filename, tokens ); + + return fromTokens < T > ( tokens ); } /** @@ -42,33 +43,36 @@ public: * @param str string containing the XML * @return String */ - template<class T> - static T fromString(const std::string& str) { - std::deque<sax::Token> tokens; - sax::SaxParseInterface::parseMemory(str, tokens); - return fromTokens<T>(tokens); + template < class T > + static T fromString ( const std::string & str ) { + std::deque < sax::Token > tokens; + sax::SaxParseInterface::parseMemory ( str, tokens ); + + return fromTokens < T > ( tokens ); } - + /** * Parses the XML from stdin and returns the String. * @return String */ - template<class T> - static T fromStdin() { - std::deque<sax::Token> tokens; - sax::SaxParseInterface::parseStdin(tokens); - return fromTokens<T>(tokens); + template < class T > + static T fromStdin ( ) { + std::deque < sax::Token > tokens; + sax::SaxParseInterface::parseStdin ( tokens ); + + return fromTokens < T > ( tokens ); } - + /** * Parses the XML from stream and returns the String. * @return String */ - template<class T> - static T fromStream(std::istream& in) { - std::deque<sax::Token> tokens; - sax::SaxParseInterface::parseStream(in, tokens); - return fromTokens<T>(tokens); + template < class T > + static T fromStream ( std::istream & in ) { + std::deque < sax::Token > tokens; + sax::SaxParseInterface::parseStream ( in, tokens ); + + return fromTokens < T > ( tokens ); } /** @@ -76,20 +80,22 @@ public: * @param tokens XML represented as list of tokens * @return parsed String */ - template<class T> - static T fromTokens(std::deque<sax::Token>& tokens) { - alib::xmlApiContext::clearContexts(); + template < class T > + static T fromTokens ( std::deque < sax::Token > & tokens ) { + alib::xmlApiContext::clearContexts ( ); + + std::deque < sax::Token >::iterator iter = tokens.begin ( ); + + if ( iter == tokens.end ( ) ) throw exception::AlibException ( "Empty tokens list" ); - std::deque<sax::Token>::iterator iter = tokens.begin(); + if ( alib::xmlApi < exception::AlibException >::first ( iter ) ) throw alib::xmlApi < exception::AlibException >::parse ( iter ); - if(iter == tokens.end()) throw exception::AlibException("Empty tokens list"); + std::chrono::measurements::start ( "XML Parser", std::chrono::measurements::Type::INIT ); + T res = alib::xmlApi < T >::parse ( iter ); + std::chrono::measurements::end ( ); - if(alib::xmlApi<exception::AlibException>::first(iter)) throw alib::xmlApi<exception::AlibException>::parse(iter); + if ( iter != tokens.end ( ) ) throw exception::AlibException ( "Unexpeted tokens at the end of the xml" ); - std::chrono::measurements::start("XML Parser", std::chrono::measurements::Type::INIT); - T res = alib::xmlApi<T>::parse(iter); - std::chrono::measurements::end(); - if(iter != tokens.end()) throw exception::AlibException("Unexpeted tokens at the end of the xml"); return res; } @@ -98,9 +104,9 @@ public: * @param tokens * @return bool */ - template<class T> - static bool first(const std::deque<sax::Token>& tokens) { - return alib::xmlApi<exception::AlibException>::first(tokens.begin()) || alib::xmlApi<T>::first(tokens.begin()); + template < class T > + static bool first ( const std::deque < sax::Token > & tokens ) { + return alib::xmlApi < exception::AlibException >::first ( tokens.begin ( ) ) || alib::xmlApi < T >::first ( tokens.begin ( ) ); } /** @@ -108,10 +114,10 @@ public: * @param filename path to the file * @return String */ - template<class T> - static void toFile(const T& data, const std::string& filename) { - std::deque<sax::Token> tokens = toTokens<T>(data); - sax::SaxComposeInterface::printFile(filename, tokens); + template < class T > + static void toFile ( const T & data, const std::string & filename ) { + std::deque < sax::Token > tokens = toTokens < T > ( data ); + sax::SaxComposeInterface::printFile ( filename, tokens ); } /** @@ -119,32 +125,33 @@ public: * @param str string containing the XML * @return String */ - template<class T> - static std::string toString(const T& data) { - std::deque<sax::Token> tokens = toTokens<T>(data); + template < class T > + static std::string toString ( const T & data ) { + std::deque < sax::Token > tokens = toTokens < T > ( data ); std::string str; - sax::SaxComposeInterface::printMemory(str, tokens); + sax::SaxComposeInterface::printMemory ( str, tokens ); + return str; } - + /** * Parses the XML from stdin and returns the String. * @return String */ - template<class T> - static void toStdout(const T& data) { - std::deque<sax::Token> tokens = toTokens<T>(data); - sax::SaxComposeInterface::printStdout(tokens); + template < class T > + static void toStdout ( const T & data ) { + std::deque < sax::Token > tokens = toTokens < T > ( data ); + sax::SaxComposeInterface::printStdout ( tokens ); } - + /** * Parses the XML from stream and returns the String. * @return String */ - template<class T> - static void toStream(const T& data, std::ostream& out) { - std::deque<sax::Token> tokens = toTokens<T>(data); - sax::SaxComposeInterface::printStream(out, tokens); + template < class T > + static void toStream ( const T & data, std::ostream & out ) { + std::deque < sax::Token > tokens = toTokens < T > ( data ); + sax::SaxComposeInterface::printStream ( out, tokens ); } /** @@ -152,32 +159,35 @@ public: * @param tokens XML represented as list of tokens * @return parsed String */ - template<class T> - static std::deque<sax::Token> toTokens(const T& data) { - alib::xmlApiContext::clearContexts(); - - std::deque<sax::Token> res; - std::chrono::measurements::start("XML Composer", std::chrono::measurements::Type::FINALIZE); - alib::xmlApi<T>::compose(res, data); - std::chrono::measurements::end(); + template < class T > + static std::deque < sax::Token > toTokens ( const T & data ) { + alib::xmlApiContext::clearContexts ( ); + + std::deque < sax::Token > res; + std::chrono::measurements::start ( "XML Composer", std::chrono::measurements::Type::FINALIZE ); + alib::xmlApi < T >::compose ( res, data ); + std::chrono::measurements::end ( ); + return res; } }; -template<> -inline bool XmlDataFactory::first<exception::AlibException>(const std::deque<sax::Token>& tokens) { - return alib::xmlApi<exception::AlibException>::first(tokens.begin()); +template < > +inline bool XmlDataFactory::first < exception::AlibException > ( const std::deque < sax::Token > & tokens ) { + return alib::xmlApi < exception::AlibException >::first ( tokens.begin ( ) ); } -template<> -inline exception::AlibException XmlDataFactory::fromTokens<exception::AlibException>(std::deque<sax::Token>& tokens) { - std::deque<sax::Token>::iterator iter = tokens.begin(); +template < > +inline exception::AlibException XmlDataFactory::fromTokens < exception::AlibException > ( std::deque < sax::Token > & tokens ) { + std::deque < sax::Token >::iterator iter = tokens.begin ( ); + + if ( iter == tokens.end ( ) ) throw exception::AlibException ( "Empty tokens list" ); + + exception::AlibException res = alib::xmlApi < exception::AlibException >::parse ( iter ); - if(iter == tokens.end()) throw exception::AlibException("Empty tokens list"); + if ( iter != tokens.end ( ) ) throw exception::AlibException ( "Unexpeted tokens at the end of the xml" ); - exception::AlibException res = alib::xmlApi<exception::AlibException>::parse(iter); - if(iter != tokens.end()) throw exception::AlibException("Unexpeted tokens at the end of the xml"); return res; } diff --git a/alib2data/src/grammar/Grammar.h b/alib2data/src/grammar/Grammar.h index 0b2eafcbd1e29b8d9a9d13eed6f9949a3a6dbac8..ccb469d52c82436542f07919b9000a55d21276ca 100644 --- a/alib2data/src/grammar/Grammar.h +++ b/alib2data/src/grammar/Grammar.h @@ -17,8 +17,8 @@ namespace grammar { /** * Wrapper around grammars. */ -class Grammar : public alib::wrapper<GrammarBase>, public alib::WrapperBase { - using alib::wrapper<GrammarBase>::wrapper; +class Grammar : public alib::wrapper < GrammarBase >, public alib::WrapperBase { + using alib::wrapper < GrammarBase >::wrapper; public: const static std::string XML_TAG_NAME_REF; @@ -28,14 +28,14 @@ public: namespace std { -template<> -struct compare<grammar::Grammar> { - int operator()(const grammar::Grammar& first, const grammar::Grammar& second) const { - return first.getData().compare(second.getData()); +template < > +struct compare < grammar::Grammar > { + int operator ()( const grammar::Grammar & first, const grammar::Grammar & second ) const { + return first.getData ( ).compare ( second.getData ( ) ); } + }; } /* namespace std */ #endif /* GRAMMAR_H_ */ - diff --git a/alib2data/src/graph/Graph.h b/alib2data/src/graph/Graph.h index 6250f2445851d76d0cfd4fcec81db1ec889cc9f5..ad6ffbe63661399062870b39a3592a5a24a3ddc4 100644 --- a/alib2data/src/graph/Graph.h +++ b/alib2data/src/graph/Graph.h @@ -14,9 +14,9 @@ namespace graph { -// Wrapper around graphs. -class Graph : public alib::wrapper<GraphBase>, public alib::WrapperBase { - using alib::wrapper<GraphBase>::wrapper; + // Wrapper around graphs. +class Graph : public alib::wrapper < GraphBase >, public alib::WrapperBase { + using alib::wrapper < GraphBase >::wrapper; public: const static std::string XML_TAG_NAME_REF; @@ -26,13 +26,12 @@ public: namespace std { -template<> -struct compare<graph::Graph> -{ - int operator()(const graph::Graph &first, const graph::Graph &second) const - { - return first.getData().compare(second.getData()); +template < > +struct compare < graph::Graph > { + int operator ()( const graph::Graph & first, const graph::Graph & second ) const { + return first.getData ( ).compare ( second.getData ( ) ); } + }; } // namespace diff --git a/alib2data/src/label/Label.cpp b/alib2data/src/label/Label.cpp index 42a950a4aa1b3d0a484576588ea296538ffb0ffc..3c2b20994b60334e9551512938526face13c3451 100644 --- a/alib2data/src/label/Label.cpp +++ b/alib2data/src/label/Label.cpp @@ -14,35 +14,54 @@ namespace label { const std::string Label::XML_TAG_NAME_REF = "LabelRef"; -Label Label::next() const { - return Label(this->getData().next()); +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); +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) } }; +label::Label labelFrom ( int number ) { + return label::Label { + label::PrimitiveLabel { + primitive::primitiveFrom ( number ) + } + }; } -label::Label labelFrom(int number1, int number2) { - return label::Label { label::LabelPairLabel { std::make_pair ( label::Label { label::PrimitiveLabel { primitive::primitiveFrom ( number1 ) } }, label::Label { label::PrimitiveLabel { primitive::primitiveFrom ( number2 ) } } ) } }; +label::Label labelFrom ( int number1, int number2 ) { + return label::Label { + label::LabelPairLabel { + std::make_pair ( label::Label { label::PrimitiveLabel { primitive::primitiveFrom ( number1 ) } }, + label::Label { label::PrimitiveLabel { primitive::primitiveFrom ( number2 ) } } + ) + } + }; } -label::Label labelFrom(char character) { - return label::Label { label::PrimitiveLabel { primitive::primitiveFrom ( character ) } }; +label::Label labelFrom ( char character ) { + return label::Label { + label::PrimitiveLabel { + primitive::primitiveFrom ( character ) + } + }; } -label::Label labelFrom(std::string string) { - return label::Label { label::PrimitiveLabel { primitive::primitiveFrom ( std::move ( string ) ) } }; +label::Label labelFrom ( std::string string ) { + return label::Label { + label::PrimitiveLabel { + primitive::primitiveFrom ( std::move ( string ) ) + } + }; } -label::Label labelFrom(const char* string) { - return labelFrom((std::string) string); +label::Label labelFrom ( const char * string ) { + return labelFrom ( ( std::string ) string ); } } /* namespace label */ - diff --git a/alib2data/src/label/Label.h b/alib2data/src/label/Label.h index 03968c32d0e4480ef5121d78f65e8ef834d46988..5a53fd2c69bf55f71c9602a0e15bfc40bbd9ce8d 100644 --- a/alib2data/src/label/Label.h +++ b/alib2data/src/label/Label.h @@ -17,34 +17,34 @@ namespace label { /** * Wrapper around automata. */ -class Label : public alib::wrapper<LabelBase>, public alib::WrapperBase { - using alib::wrapper<LabelBase>::wrapper; +class Label : public alib::wrapper < LabelBase >, public alib::WrapperBase { + using alib::wrapper < LabelBase >::wrapper; public: - Label next() const; - void inc(); + Label next ( ) const; + void inc ( ); const static std::string XML_TAG_NAME_REF; }; -label::Label labelFrom(int number); -label::Label labelFrom(int number1, int number2); -label::Label labelFrom(char character); -label::Label labelFrom(std::string string); -label::Label labelFrom(const char* string); +label::Label labelFrom ( int number ); +label::Label labelFrom ( int number1, int number2 ); +label::Label labelFrom ( char character ); +label::Label labelFrom ( std::string string ); +label::Label labelFrom ( const char * string ); } /* namespace label */ namespace std { -template<> -struct compare<label::Label> { - int operator()(const label::Label& first, const label::Label& second) const { - return first.getData().compare(second.getData()); +template < > +struct compare < label::Label > { + int operator ()( const label::Label & first, const label::Label & second ) const { + return first.getData ( ).compare ( second.getData ( ) ); } + }; } /* namespace std */ #endif /* LABEL_H_ */ - diff --git a/alib2data/src/object/Object.h b/alib2data/src/object/Object.h index 30bc97201302f83b1778e2ad2971869f45697069..19b4f0937a7ef25b8738b466cffc97db6e90765c 100644 --- a/alib2data/src/object/Object.h +++ b/alib2data/src/object/Object.h @@ -17,8 +17,8 @@ namespace alib { /** * Wrapper around object. */ -class Object : public alib::wrapper<ObjectBase>, public alib::WrapperBase { - using alib::wrapper<ObjectBase>::wrapper; +class Object : public alib::wrapper < ObjectBase >, public alib::WrapperBase { + using alib::wrapper < ObjectBase >::wrapper; public: const static std::string XML_TAG_NAME_REF; @@ -28,14 +28,14 @@ public: namespace std { -template<> -struct compare<alib::Object> { - int operator()(const alib::Object& first, const alib::Object& second) const { - return first.getData().compare(second.getData()); +template < > +struct compare < alib::Object > { + int operator ()( const alib::Object & first, const alib::Object & second ) const { + return first.getData ( ).compare ( second.getData ( ) ); } + }; } /* namespace std */ #endif /* OBJECT_H_ */ - diff --git a/alib2data/src/primitive/Primitive.cpp b/alib2data/src/primitive/Primitive.cpp index d72a538fb1e8b0e25162073baa3d20dd71ea778e..0fc059fa7fc0c2acdfadcd521747c0d5986c0b55 100644 --- a/alib2data/src/primitive/Primitive.cpp +++ b/alib2data/src/primitive/Primitive.cpp @@ -16,39 +16,59 @@ namespace primitive { const std::string Primitive::XML_TAG_NAME_REF = "PrimitiveRef"; -Primitive Primitive::next() const { - Primitive res = *this; - res.inc(); +Primitive Primitive::next ( ) const { + Primitive res = * this; + + res.inc ( ); return res; } -void Primitive::inc() { - this->getData().inc(); +void Primitive::inc ( ) { + this->getData ( ).inc ( ); } -Primitive primitiveFrom(int number) { - return Primitive { Integer { number } }; +Primitive primitiveFrom ( int number ) { + return Primitive { + Integer { + number + } + }; } -Primitive primitiveFrom(char character) { - return Primitive { Character { character } }; +Primitive primitiveFrom ( char character ) { + return Primitive { + Character { + character + } + }; } -Primitive primitiveFrom(const char* string) { - return primitiveFrom((std::string) string); +Primitive primitiveFrom ( const char * string ) { + return primitiveFrom ( ( std::string ) string ); } -Primitive primitiveFrom(std::string string) { - return Primitive { String { std::move ( string ) } }; +Primitive primitiveFrom ( std::string string ) { + return Primitive { + String { + std::move ( string ) + } + }; } -Primitive primitiveFrom(unsigned number) { - return Primitive { Unsigned { number } }; +Primitive primitiveFrom ( unsigned number ) { + return Primitive { + Unsigned { + number + } + }; } -Primitive primitiveFrom(bool value) { - return Primitive { Bool { value } }; +Primitive primitiveFrom ( bool value ) { + return Primitive { + Bool { + value + } + }; } } /* namespace primitive */ - diff --git a/alib2data/src/primitive/Primitive.h b/alib2data/src/primitive/Primitive.h index a926697a292acfe5d7cf06a1ed4f8b9089991d46..a9cff07fb6497dc39fd53c83ac52d0820af80f79 100644 --- a/alib2data/src/primitive/Primitive.h +++ b/alib2data/src/primitive/Primitive.h @@ -17,35 +17,35 @@ namespace primitive { /** * Wrapper around primitive data types. */ -class Primitive : public alib::wrapper<PrimitiveBase>, public alib::WrapperBase { - using alib::wrapper<PrimitiveBase>::wrapper; +class Primitive : public alib::wrapper < PrimitiveBase >, public alib::WrapperBase { + using alib::wrapper < PrimitiveBase >::wrapper; public: - Primitive next() const; - void inc(); + Primitive next ( ) const; + void inc ( ); const static std::string XML_TAG_NAME_REF; }; -Primitive primitiveFrom(int number); -Primitive primitiveFrom(char character); -Primitive primitiveFrom(std::string string); -Primitive primitiveFrom(const char* string); -Primitive primitiveFrom(unsigned number); -Primitive primitiveFrom(bool value); +Primitive primitiveFrom ( int number ); +Primitive primitiveFrom ( char character ); +Primitive primitiveFrom ( std::string string ); +Primitive primitiveFrom ( const char * string ); +Primitive primitiveFrom ( unsigned number ); +Primitive primitiveFrom ( bool value ); } /* namespace primitive */ namespace std { -template<> -struct compare<primitive::Primitive> { - int operator()(const primitive::Primitive& first, const primitive::Primitive& second) const { - return first.getData().compare(second.getData()); +template < > +struct compare < primitive::Primitive > { + int operator ()( const primitive::Primitive & first, const primitive::Primitive & second ) const { + return first.getData ( ).compare ( second.getData ( ) ); } + }; } /* namespace std */ #endif /* PRIMITIVE_H_ */ - diff --git a/alib2data/src/regexp/RegExp.cpp b/alib2data/src/regexp/RegExp.cpp index 3dbd9cf6674f571fe175189b581203125a0f10f2..f291ed6ebad5a2b4a138240f3c2759bcca4feaca 100644 --- a/alib2data/src/regexp/RegExp.cpp +++ b/alib2data/src/regexp/RegExp.cpp @@ -18,37 +18,46 @@ namespace regexp { const std::string RegExp::XML_TAG_NAME_REF = "RegExpRef"; -const std::set<alphabet::Symbol>& RegExp::getAlphabet() const { - return this->getData().getAlphabet(); +const std::set < alphabet::Symbol > & RegExp::getAlphabet ( ) const { + return this->getData ( ).getAlphabet ( ); } -regexp::RegExp regexpFrom( const std::string & string ) { +regexp::RegExp regexpFrom ( const std::string & string ) { regexp::UnboundedRegExpConcatenation con; - for(const char& symbol : string) { - con.appendElement( regexp::UnboundedRegExpSymbol( alphabet::symbolFrom( symbol ) ) ); - } - return regexp::RegExp { regexp::UnboundedRegExp ( std::move ( con ) ) }; + + for ( const char & symbol : string ) + con.appendElement ( regexp::UnboundedRegExpSymbol ( alphabet::symbolFrom ( symbol ) ) ); + + return regexp::RegExp { + regexp::UnboundedRegExp ( std::move ( con ) ) + }; } -regexp::RegExp regexpFrom( const char* string ) { - return regexpFrom( (std::string) string ); +regexp::RegExp regexpFrom ( const char * string ) { + return regexpFrom ( ( std::string ) string ); } -regexp::RegExp regexpFrom( string::LinearString string ) { +regexp::RegExp regexpFrom ( string::LinearString string ) { regexp::UnboundedRegExpConcatenation con; - for(auto& symbol : string.getContent()) { - con.appendElement( regexp::UnboundedRegExpSymbol( std::move ( symbol ) ) ); - } - return regexp::RegExp { regexp::UnboundedRegExp ( std::move( con ) ) }; + + for ( auto & symbol : string.getContent ( ) ) + con.appendElement ( regexp::UnboundedRegExpSymbol ( std::move ( symbol ) ) ); + + return regexp::RegExp { + regexp::UnboundedRegExp ( std::move ( con ) ) + }; } -regexp::RegExp regexpFrom( alphabet::Symbol symbol ) { - return regexp::RegExp { regexp::UnboundedRegExp( regexp::UnboundedRegExpSymbol( std::move ( symbol ) ) ) }; +regexp::RegExp regexpFrom ( alphabet::Symbol symbol ) { + return regexp::RegExp { + regexp::UnboundedRegExp ( regexp::UnboundedRegExpSymbol ( std::move ( symbol ) ) ) + }; } -regexp::RegExp regexpFrom( ) { - return regexp::RegExp { regexp::UnboundedRegExp( regexp::UnboundedRegExpEmpty { } ) }; +regexp::RegExp regexpFrom ( ) { + return regexp::RegExp { + regexp::UnboundedRegExp ( regexp::UnboundedRegExpEmpty { } ) + }; } } /* namespace regexp */ - diff --git a/alib2data/src/regexp/RegExp.h b/alib2data/src/regexp/RegExp.h index ef6b99404ddd440e034c100545138c58a9ac52e5..e9c12f8a0d9a2af8a74477af21e4f3bd2c5ce67b 100644 --- a/alib2data/src/regexp/RegExp.h +++ b/alib2data/src/regexp/RegExp.h @@ -22,36 +22,37 @@ namespace regexp { /** * Wrapper around automata. */ -class RegExp : public alib::wrapper<RegExpBase>, public alib::WrapperBase { - using alib::wrapper<RegExpBase>::wrapper; +class RegExp : public alib::wrapper < RegExpBase >, public alib::WrapperBase { + using alib::wrapper < RegExpBase >::wrapper; + public: - const std::set<alphabet::Symbol>& getAlphabet() const; + const std::set < alphabet::Symbol > & getAlphabet ( ) const; const static std::string XML_TAG_NAME_REF; }; -regexp::RegExp regexpFrom( const std::string& string ); +regexp::RegExp regexpFrom ( const std::string & string ); -regexp::RegExp regexpFrom( const char* string ); +regexp::RegExp regexpFrom ( const char * string ); -regexp::RegExp regexpFrom( string::LinearString string ); +regexp::RegExp regexpFrom ( string::LinearString string ); -regexp::RegExp regexpFrom( alphabet::Symbol symbol ); +regexp::RegExp regexpFrom ( alphabet::Symbol symbol ); -regexp::RegExp regexpFrom( ); +regexp::RegExp regexpFrom ( ); } /* namespace regexp */ namespace std { -template<> -struct compare<regexp::RegExp> { - int operator()(const regexp::RegExp& first, const regexp::RegExp& second) const { - return first.getData().compare(second.getData()); +template < > +struct compare < regexp::RegExp > { + int operator ()( const regexp::RegExp & first, const regexp::RegExp & second ) const { + return first.getData ( ).compare ( second.getData ( ) ); } + }; } /* namespace std */ #endif /* REG_EXP_H_ */ - diff --git a/alib2data/src/string/String.cpp b/alib2data/src/string/String.cpp index b9d99228e6ab9e1d70887fdad8baa34452e1bd85..9cd136cc5f03d57b5da58c6b2f27d9ae8b2f0886 100644 --- a/alib2data/src/string/String.cpp +++ b/alib2data/src/string/String.cpp @@ -14,8 +14,8 @@ namespace string { const std::string String::XML_TAG_NAME_REF = "StringRef"; -const std::set<alphabet::Symbol>& String::getAlphabet() const { - return this->getData().getAlphabet(); +const std::set < alphabet::Symbol > & String::getAlphabet ( ) const { + return this->getData ( ).getAlphabet ( ); } void String::extendAlphabet ( const std::set < alphabet::Symbol > & symbols ) { diff --git a/alib2data/src/string/String.h b/alib2data/src/string/String.h index 1f8943c50ba4018a7752d3376fa3f65bea537cc1..e7ac5e165a941a58a8d4333712c93f4f76c82450 100644 --- a/alib2data/src/string/String.h +++ b/alib2data/src/string/String.h @@ -23,7 +23,7 @@ class String : public alib::wrapper < StringBase >, public alib::WrapperBase { using alib::wrapper < StringBase >::wrapper; public: - const std::set<alphabet::Symbol>& getAlphabet() const; + const std::set < alphabet::Symbol > & getAlphabet ( ) const; const static std::string XML_TAG_NAME_REF; }; diff --git a/alib2data/src/tree/Tree.h b/alib2data/src/tree/Tree.h index a7c6a9d2a067f70d07dc8537fd6c1363a3b82e4c..d56577859f86dbaa95d14f2c8741a0c20db3f604 100644 --- a/alib2data/src/tree/Tree.h +++ b/alib2data/src/tree/Tree.h @@ -17,8 +17,8 @@ namespace tree { /** * Wrapper around tree. */ -class Tree : public alib::wrapper<TreeBase>, public alib::WrapperBase { - using alib::wrapper<TreeBase>::wrapper; +class Tree : public alib::wrapper < TreeBase >, public alib::WrapperBase { + using alib::wrapper < TreeBase >::wrapper; public: const static std::string XML_TAG_NAME_REF; diff --git a/alib2data/test-src/sax/SaxTest.cpp b/alib2data/test-src/sax/SaxTest.cpp index 8a89afa0d6a2ca8f04f0e7962b5ce75e609d2986..d5d5ffcf83317365729dfe2a4a288685bd85eae3 100644 --- a/alib2data/test-src/sax/SaxTest.cpp +++ b/alib2data/test-src/sax/SaxTest.cpp @@ -5,32 +5,32 @@ #include "sax/SaxParseInterface.h" #include "sax/SaxComposeInterface.h" -#define CPPUNIT_EXCLUSIVE_OR(x, y) CPPUNIT_ASSERT((!(x) && (y)) || ((x) && !(y))) +#define CPPUNIT_EXCLUSIVE_OR( x, y ) CPPUNIT_ASSERT ( ( !( x ) && ( y ) ) || ( ( x ) && !( y ) ) ) -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SaxTest, "sax" ); -CPPUNIT_TEST_SUITE_REGISTRATION( SaxTest ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( SaxTest, "sax" ); +CPPUNIT_TEST_SUITE_REGISTRATION ( SaxTest ); -void SaxTest::setUp() { +void SaxTest::setUp ( ) { } -void SaxTest::tearDown() { +void SaxTest::tearDown ( ) { } -void SaxTest::testSax() { +void SaxTest::testSax ( ) { std::string tmp = "<?xml version=\"1.0\"?>\n<aa bb=\"cc\"><xx/>dd<ee ff=\"gg\"/></aa>\n"; - std::deque<sax::Token> tokens; - sax::SaxParseInterface::parseMemory(tmp, tokens); + std::deque < sax::Token > tokens; + sax::SaxParseInterface::parseMemory ( tmp, tokens ); std::cout << tokens << std::endl; std::string tmp2; - sax::SaxComposeInterface::printMemory(tmp2, tokens); + sax::SaxComposeInterface::printMemory ( tmp2, tokens ); - CPPUNIT_ASSERT( tmp == tmp2 ); + CPPUNIT_ASSERT ( tmp == tmp2 ); - std::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp2, tokens2); + std::deque < sax::Token > tokens2; + sax::SaxParseInterface::parseMemory ( tmp2, tokens2 ); - CPPUNIT_ASSERT( tokens == tokens2 ); + CPPUNIT_ASSERT ( tokens == tokens2 ); } diff --git a/alib2data/test-src/string/StringTest.cpp b/alib2data/test-src/string/StringTest.cpp index eb7170c95500b0d3b75e4d5311c0f2f8d5117490..a4bc23fa0ac91d6c6b5c8b1070ffc3864fea76cd 100644 --- a/alib2data/test-src/string/StringTest.cpp +++ b/alib2data/test-src/string/StringTest.cpp @@ -16,76 +16,86 @@ #include "alphabet/LabeledSymbol.h" #include "alphabet/BlankSymbol.h" -#define CPPUNIT_IMPLY(x, y) CPPUNIT_ASSERT(!(x) || (y)) +#define CPPUNIT_IMPLY( x, y ) CPPUNIT_ASSERT ( !( x ) || ( y ) ) -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTest, "string" ); -CPPUNIT_TEST_SUITE_REGISTRATION( StringTest ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( StringTest, "string" ); +CPPUNIT_TEST_SUITE_REGISTRATION ( StringTest ); -void StringTest::setUp() { +void StringTest::setUp ( ) { } -void StringTest::tearDown() { +void StringTest::tearDown ( ) { } -void StringTest::testCopyConstruct() { +void StringTest::testCopyConstruct ( ) { string::LinearString linearString; - linearString.setAlphabet({alphabet::symbolFrom("1"), alphabet::symbolFrom("2"), alphabet::symbolFrom("3")}); - linearString.setContent({alphabet::symbolFrom("1"), alphabet::symbolFrom("2"), alphabet::symbolFrom("1")}); - string::String string(linearString); - string::String string2(string); - CPPUNIT_ASSERT( string == string2 ); + linearString.setAlphabet ( { alphabet::symbolFrom ( "1" ), alphabet::symbolFrom ( "2" ), alphabet::symbolFrom ( "3" ) } ); + linearString.setContent ( { alphabet::symbolFrom ( "1" ), alphabet::symbolFrom ( "2" ), alphabet::symbolFrom ( "1" ) } ); + string::String string ( linearString ); + string::String string2 ( string ); - string::String string3(std::move(string)); + CPPUNIT_ASSERT ( string == string2 ); - CPPUNIT_ASSERT( string2 == string3 ); + string::String string3 ( std::move ( string ) ); + + CPPUNIT_ASSERT ( string2 == string3 ); } -void StringTest::testXMLParser() { +void StringTest::testXMLParser ( ) { string::LinearString linearString; - linearString.setAlphabet({alphabet::symbolFrom("1"), alphabet::symbolFrom("2"), alphabet::symbolFrom("3")}); - linearString.setContent({alphabet::symbolFrom("1"), alphabet::symbolFrom("2"), alphabet::symbolFrom("1")}); - string::String string(linearString); + linearString.setAlphabet ( { alphabet::symbolFrom ( "1" ), alphabet::symbolFrom ( "2" ), alphabet::symbolFrom ( "3" ) } ); + linearString.setContent ( { alphabet::symbolFrom ( "1" ), alphabet::symbolFrom ( "2" ), alphabet::symbolFrom ( "1" ) } ); + + string::String string ( linearString ); { - std::deque<sax::Token> tokens = alib::XmlDataFactory::toTokens(string); + std::deque < sax::Token > tokens = alib::XmlDataFactory::toTokens ( string ); std::string tmp; - sax::SaxComposeInterface::printMemory(tmp, tokens); + sax::SaxComposeInterface::printMemory ( tmp, tokens ); std::cout << tmp << std::endl; - std::deque<sax::Token> tokens2; - sax::SaxParseInterface::parseMemory(tmp, tokens2); - string::String string2 = alib::XmlDataFactory::fromTokens<string::String>(tokens2); + std::deque < sax::Token > tokens2; + sax::SaxParseInterface::parseMemory ( tmp, tokens2 ); + string::String string2 = alib::XmlDataFactory::fromTokens < string::String > ( tokens2 ); - CPPUNIT_ASSERT( string == string2 ); + CPPUNIT_ASSERT ( string == string2 ); } { - std::string tmp = alib::XmlDataFactory::toString(string); + std::string tmp = alib::XmlDataFactory::toString ( string ); std::cout << tmp << std::endl; - string::String string2 = alib::XmlDataFactory::fromString<string::String>(tmp); + string::String string2 = alib::XmlDataFactory::fromString < string::String > ( tmp ); - CPPUNIT_ASSERT( string == string2 ); + CPPUNIT_ASSERT ( string == string2 ); } } -void StringTest::testStringInMap() { - std::map<std::variant<string::Epsilon, int>, int> testMap; - std::variant<string::Epsilon, int> epsVar { string::Epsilon { } }; - CPPUNIT_ASSERT( string::Epsilon::EPSILON == epsVar.get<string::Epsilon>() ); - CPPUNIT_ASSERT( epsVar.get<string::Epsilon>() == string::Epsilon::EPSILON ); - - std::pair<std::variant<string::Epsilon, int>, int> epsVarPair = std::make_pair(epsVar, 10 ); - CPPUNIT_ASSERT( string::Epsilon::EPSILON == epsVarPair.first.get<string::Epsilon>() ); - CPPUNIT_ASSERT( epsVarPair.first.get<string::Epsilon>() == string::Epsilon::EPSILON ); - - testMap.insert(std::make_pair(std::variant<string::Epsilon, int> { string::Epsilon { } }, 10)); - CPPUNIT_ASSERT( testMap.find(std::variant<string::Epsilon, int> { string::Epsilon { } } ) != testMap.end() ); - for( const auto & entry : testMap) { - CPPUNIT_ASSERT( entry.first.is<string::Epsilon>()); - if(entry.first.is<string::Epsilon>()) - CPPUNIT_ASSERT( string::Epsilon::EPSILON == entry.first.get<string::Epsilon>() ); - CPPUNIT_ASSERT( entry.first.get<string::Epsilon>() == string::Epsilon::EPSILON ); +void StringTest::testStringInMap ( ) { + std::map < std::variant < string::Epsilon, int >, int > testMap; + std::variant < string::Epsilon, int > epsVar { + string::Epsilon { } + }; + + CPPUNIT_ASSERT ( string::Epsilon::EPSILON == epsVar.get < string::Epsilon > ( ) ); + CPPUNIT_ASSERT ( epsVar.get < string::Epsilon > ( ) == string::Epsilon::EPSILON ); + + std::pair < std::variant < string::Epsilon, int >, int > epsVarPair = std::make_pair ( epsVar, 10 ); + CPPUNIT_ASSERT ( string::Epsilon::EPSILON == epsVarPair.first.get < string::Epsilon > ( ) ); + CPPUNIT_ASSERT ( epsVarPair.first.get < string::Epsilon > ( ) == string::Epsilon::EPSILON ); + + testMap.insert ( std::make_pair ( std::variant < string::Epsilon, int > { string::Epsilon { } + }, 10 ) ); + CPPUNIT_ASSERT ( testMap.find ( std::variant < string::Epsilon, int > { string::Epsilon { } + } ) != testMap.end ( ) ); + + for ( const auto & entry : testMap ) { + CPPUNIT_ASSERT ( entry.first.is < string::Epsilon > ( ) ); + + if ( entry.first.is < string::Epsilon > ( ) ) + CPPUNIT_ASSERT ( string::Epsilon::EPSILON == entry.first.get < string::Epsilon > ( ) ); + + CPPUNIT_ASSERT ( entry.first.get < string::Epsilon > ( ) == string::Epsilon::EPSILON ); } }