Skip to content
Snippets Groups Projects
Commit 0563fecf authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Jakub Klinkovský
Browse files

Fixed templated String constructor and added constructor from bool.

parent 39e39b13
No related branches found
No related tags found
1 merge request!10Periodic BC in distributed grid
...@@ -47,6 +47,13 @@ String::String( const String& str ) ...@@ -47,6 +47,13 @@ String::String( const String& str )
setString( str.getString() ); setString( str.getString() );
} }
String::String( const bool b )
: string( nullptr ), length( 0 )
{
if( b ) this->setString( "true" );
else this->setString( "false" );
}
String String::getType() String String::getType()
{ {
return String( "String" ); return String( "String" );
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
/// definition ( in operator << ). It leads to stack overflow and segmentation fault. /// definition ( in operator << ). It leads to stack overflow and segmentation fault.
template< typename T > template< typename T >
explicit explicit
String( T value ) String( const T& value )
: string( nullptr ), length( 0 ) : string( nullptr ), length( 0 )
{ {
std::stringstream str; std::stringstream str;
...@@ -67,6 +67,8 @@ public: ...@@ -67,6 +67,8 @@ public:
setString( str.str().data() ); setString( str.str().data() );
} }
String( const bool b );
//! Destructor //! Destructor
~String(); ~String();
......
...@@ -41,16 +41,17 @@ TYPED_TEST_CASE( ListTest, ListTypes ); ...@@ -41,16 +41,17 @@ TYPED_TEST_CASE( ListTest, ListTypes );
TYPED_TEST( ListTest, constructor ) TYPED_TEST( ListTest, constructor )
{ {
using ListType = typename TestFixture::ListType; using ListType = typename TestFixture::ListType;
using ValueType = typename ListType::ValueType;
ListType list; ListType list;
EXPECT_TRUE( list.isEmpty() ); EXPECT_TRUE( list.isEmpty() );
EXPECT_EQ( list.getSize(), 0 ); EXPECT_EQ( list.getSize(), 0 );
list.Append( 0 ); list.Append( ( ValueType ) 0 );
EXPECT_EQ( list.getSize(), 1 ); EXPECT_EQ( list.getSize(), 1 );
ListType copy( list ); ListType copy( list );
list.Append( 0 ); list.Append( ( ValueType ) 0 );
EXPECT_EQ( list.getSize(), 2 ); EXPECT_EQ( list.getSize(), 2 );
EXPECT_EQ( copy.getSize(), 1 ); EXPECT_EQ( copy.getSize(), 1 );
EXPECT_EQ( copy[ 0 ], list[ 0 ] ); EXPECT_EQ( copy[ 0 ], list[ 0 ] );
......
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