diff --git a/alib2str/src/container/string/ObjectsVariant.h b/alib2str/src/container/string/ObjectsVariant.h index 4ded70bfb8f23b681878f66d4dc6f46f5216f604..448696768cd7af27e588fd3243e294d8f2744caa 100644 --- a/alib2str/src/container/string/ObjectsVariant.h +++ b/alib2str/src/container/string/ObjectsVariant.h @@ -11,8 +11,6 @@ #include <alib/variant> #include <core/stringApi.hpp> -#include <container/ContainerFromStringLexer.h> - namespace core { template < class ... Types > @@ -38,16 +36,29 @@ private: m_out << "void"; } }; + + template < class T, class R, class ... Ts > + static ext::variant < Types ... > parse ( std::istream & input ) { + if ( stringApi < T >::first ( input ) ) + return ext::variant < Types ... > ( stringApi < T >::parse ( input ) ); + else + return parse < R, Ts ... > ( input ); + } + + template < class T > + static ext::variant < Types ... > parse ( std::istream & input ) { + return ext::variant < Types ... > ( stringApi < T >::parse ( input ) ); + } }; template < class ... Types > -ext::variant < Types ... > stringApi < ext::variant < Types ... > >::parse ( std::istream & /* input */ ) { - throw exception::CommonException("parsing BarSymbol from string not implemented"); +ext::variant < Types ... > stringApi < ext::variant < Types ... > >::parse ( std::istream & input ) { + return parse < Types ... > ( input ); } template < class ... Types > -bool stringApi < ext::variant < Types ... > >::first ( std::istream & /* input */ ) { - return false; +bool stringApi < ext::variant < Types ... > >::first ( std::istream & input ) { + return ext::andAll ( stringApi < Types >::first ( input ) ... ); } template < class ... Types > diff --git a/alib2str/test-src/container/ContainerTest.cpp b/alib2str/test-src/container/ContainerTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9bc68697c1af533847ca681a91302dd8e8eb07f4 --- /dev/null +++ b/alib2str/test-src/container/ContainerTest.cpp @@ -0,0 +1,37 @@ +#include "ContainerTest.h" + +#include "factory/StringDataFactory.hpp" + +#include <container/string/ObjectsVariant.h> +#include <primitive/string/Integer.h> +#include <primitive/string/String.h> + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ContainerTest, "automaton" ); +CPPUNIT_TEST_SUITE_REGISTRATION( ContainerTest ); + +void ContainerTest::setUp() { +} + +void ContainerTest::tearDown() { +} + +void ContainerTest::VariantTest() { + std::string input1 = "1"; + ext::variant < int, std::string > variant1 = factory::StringDataFactory::fromString ( input1 ); + + std::string output1 = factory::StringDataFactory::toString ( variant1 ); + + std::cout << "\"" << input1 << "\"" << std::endl << std::endl << "\"" << output1 << "\"" << std::endl; + CPPUNIT_ASSERT( input1 == output1 ); + + ext::variant < int, std::string > variant2 = factory::StringDataFactory::fromString ( output1 ); + + CPPUNIT_ASSERT( variant1 == variant2 ); + CPPUNIT_ASSERT ( variant2.template get < int > ( ) == 1 ); + + std::string input2 = "aa"; + ext::variant < int, std::string > variant3 = factory::StringDataFactory::fromString ( input2 ); + + CPPUNIT_ASSERT ( variant3.template get < std::string > ( ) == "aa" ); +} + diff --git a/alib2str/test-src/container/ContainerTest.h b/alib2str/test-src/container/ContainerTest.h new file mode 100644 index 0000000000000000000000000000000000000000..29e32e1ba52242444d2ef37abb32714c40cb5104 --- /dev/null +++ b/alib2str/test-src/container/ContainerTest.h @@ -0,0 +1,19 @@ +#ifndef CONTAINER_TEST_H_ +#define CONTAINER_TEST_H_ + +#include <cppunit/extensions/HelperMacros.h> + +class ContainerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( ContainerTest ); + CPPUNIT_TEST( VariantTest ); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp(); + void tearDown(); + + void VariantTest(); +}; + +#endif // CONTAINER_TEST_H_