forked from Alepha/Alepha
Unified streamable support capability.
This commit is contained in:
@ -1,2 +1,3 @@
|
|||||||
add_subdirectory( IStreamable.test )
|
add_subdirectory( IStreamable.test )
|
||||||
add_subdirectory( OStreamable.test )
|
add_subdirectory( OStreamable.test )
|
||||||
|
add_subdirectory( Streamable.test )
|
||||||
|
|||||||
57
IOStreams/Streamable.test/0.cc
Normal file
57
IOStreams/Streamable.test/0.cc
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
static_assert( __cplusplus > 2020'00 );
|
||||||
|
|
||||||
|
#include "../streamable.h"
|
||||||
|
|
||||||
|
#include <Alepha/Testing/TableTest.h>
|
||||||
|
#include <Alepha/Testing/test.h>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <Alepha/auto_comparable.h>
|
||||||
|
|
||||||
|
#include <Alepha/IOStreams/OStreamable.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
template< typename= Alepha::Capabilities< Alepha::auto_comparable, Alepha::IOStreams::streamable > >
|
||||||
|
struct Agg_core
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int z;
|
||||||
|
};
|
||||||
|
|
||||||
|
using Agg= Agg_core<>;
|
||||||
|
static_assert( Alepha::Aggregate< Agg > );
|
||||||
|
static_assert( Alepha::Capability< Agg, Alepha::IOStreams::IStreamable > );
|
||||||
|
static_assert( Alepha::Capability< Agg, Alepha::IOStreams::OStreamable > );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string
|
||||||
|
roundTripString( const std::string text, const std::string delim )
|
||||||
|
{
|
||||||
|
using namespace Alepha::IOStreams::exports::delimiters;
|
||||||
|
std::istringstream iss{ text };
|
||||||
|
|
||||||
|
Agg agg;
|
||||||
|
iss >> setFieldDelimiter( delim ) >> agg;
|
||||||
|
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << setFieldDelimiter( delim ) << agg;
|
||||||
|
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
static auto init= Alepha::Utility::enroll <=[]
|
||||||
|
{
|
||||||
|
using namespace Alepha::Testing::exports;
|
||||||
|
using namespace Alepha::Testing::literals::test_literals;
|
||||||
|
|
||||||
|
"Simple IStream"_test <=TableTest< roundTripString >
|
||||||
|
::Cases
|
||||||
|
{
|
||||||
|
{ "smoke test", { "1\t2\t3", "\t" }, { "1\t2\t3" } },
|
||||||
|
{ "smoke test", { "1,2,3", "," }, { "1,2,3" } },
|
||||||
|
};
|
||||||
|
};
|
||||||
1
IOStreams/Streamable.test/CMakeLists.txt
Normal file
1
IOStreams/Streamable.test/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
unit_test( 0 )
|
||||||
21
IOStreams/streamable.h
Normal file
21
IOStreams/streamable.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
static_assert( __cplusplus > 2020'00 );
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Alepha/Alepha.h>
|
||||||
|
|
||||||
|
#include "IStreamable.h"
|
||||||
|
#include "OStreamable.h"
|
||||||
|
|
||||||
|
namespace Alepha::Hydrogen::IOStreams ::detail:: streamable_m
|
||||||
|
{
|
||||||
|
inline namespace exports
|
||||||
|
{
|
||||||
|
struct streamable : OStreamable, IStreamable {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Alepha::Hydrogen::IOStreams::inline exports::inline streamable_m
|
||||||
|
{
|
||||||
|
using namespace detail::streamable_m::exports;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user