Skip to content

Commit

Permalink
Merge branch 'fix/placement-new' into 'develop'
Browse files Browse the repository at this point in the history
Fix/placement new

See merge request njoy/NDItk!2
  • Loading branch information
whaeck committed Oct 14, 2024
2 parents 16f4c85 + 317b051 commit 850d77e
Show file tree
Hide file tree
Showing 6 changed files with 570 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/NDItk/depletion/ReactionMultiplicities/src/ctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ ReactionMultiplicities( ReactionMultiplicities&& base ) :
*/
ReactionMultiplicities& operator=( const ReactionMultiplicities& base ) {

new (this) ReactionMultiplicities( base );
if ( this != &base ) {

base::IntegerListRecord::operator=( base );
this->reactions_ = base.reactions_;
this->generateBlocks();
}
return *this;
}

Expand All @@ -94,6 +99,11 @@ ReactionMultiplicities& operator=( const ReactionMultiplicities& base ) {
*/
ReactionMultiplicities& operator=( ReactionMultiplicities&& base ) {

new (this) ReactionMultiplicities( std::move( base ) );
if ( this != &base ) {

base::IntegerListRecord::operator=( std::move( base ) );
this->reactions_ = base.reactions_;
this->generateBlocks();
}
return *this;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void verifyChunk( const ReactionMultiplicities& );
std::string chunkWithMultiplicityType();
void verifyChunkWithMultiplicityType( const ReactionMultiplicities& );
std::string chunkWithInsufficientNumberReactions();
ReactionMultiplicities makeDummyRecord();

SCENARIO( "ReactionMultiplicities" ) {

Expand Down Expand Up @@ -75,6 +76,108 @@ SCENARIO( "ReactionMultiplicities" ) {
CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "using the copy constructor" ) {

auto iter = record.begin() + 5;
auto end = record.end();
ReactionMultiplicities chunk;
chunk.read( iter, end, 2 );

ReactionMultiplicities copy( chunk );

THEN( "a ReactionMultiplicities can be constructed and members can "
"be tested" ) {

verifyChunk( copy );
} // THEN

THEN( "the record can be printed" ) {

std::string buffer;
auto output = std::back_inserter( buffer );
copy.print( output );

CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "using the move constructor" ) {

auto iter = record.begin() + 5;
auto end = record.end();
ReactionMultiplicities chunk;
chunk.read( iter, end, 2 );

ReactionMultiplicities move( std::move( chunk ) );

THEN( "a ReactionMultiplicities can be constructed and members can "
"be tested" ) {

verifyChunk( move );
} // THEN

THEN( "the record can be printed" ) {

std::string buffer;
auto output = std::back_inserter( buffer );
move.print( output );

CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "using copy assignment" ) {

auto iter = record.begin() + 5;
auto end = record.end();
ReactionMultiplicities chunk;
chunk.read( iter, end, 2 );

ReactionMultiplicities copy = makeDummyRecord();
copy = chunk;

THEN( "an ReactionMultiplicities can be copy assigned and "
"members can be tested" ) {

verifyChunk( copy );
} // THEN

THEN( "the record can be printed" ) {

std::string buffer;
auto output = std::back_inserter( buffer );
copy.print( output );

CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "using move assignment" ) {

auto iter = record.begin() + 5;
auto end = record.end();
ReactionMultiplicities chunk;
chunk.read( iter, end, 2 );

ReactionMultiplicities move = makeDummyRecord();
move = std::move( chunk );

THEN( "an ReactionMultiplicities can be copy assigned and "
"members can be tested" ) {

verifyChunk( move );
} // THEN

THEN( "the record can be printed" ) {

std::string buffer;
auto output = std::back_inserter( buffer );
move.print( output );

CHECK( buffer == record );
} // THEN
} // WHEN
} // GIVEN

GIVEN( "valid data for a ReactionMultiplicities instance with a multiplicity type" ) {
Expand Down Expand Up @@ -131,6 +234,108 @@ SCENARIO( "ReactionMultiplicities" ) {
CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "using the copy constructor" ) {

auto iter = record.begin() + 9;
auto end = record.end();
ReactionMultiplicities chunk( ReactionMultiplicityType::All );
chunk.read( iter, end, 2 );

ReactionMultiplicities copy( chunk );

THEN( "a ReactionMultiplicities can be constructed and members can "
"be tested" ) {

verifyChunkWithMultiplicityType( copy );
} // THEN

THEN( "the record can be printed" ) {

std::string buffer;
auto output = std::back_inserter( buffer );
copy.print( output );

CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "using the move constructor" ) {

auto iter = record.begin() + 9;
auto end = record.end();
ReactionMultiplicities chunk( ReactionMultiplicityType::All );
chunk.read( iter, end, 2 );

ReactionMultiplicities move( std::move( chunk ) );

THEN( "a ReactionMultiplicities can be constructed and members can "
"be tested" ) {

verifyChunkWithMultiplicityType( move );
} // THEN

THEN( "the record can be printed" ) {

std::string buffer;
auto output = std::back_inserter( buffer );
move.print( output );

CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "using copy assignment" ) {

auto iter = record.begin() + 9;
auto end = record.end();
ReactionMultiplicities chunk( ReactionMultiplicityType::All );
chunk.read( iter, end, 2 );

ReactionMultiplicities copy = makeDummyRecord();
copy = chunk;

THEN( "an ReactionMultiplicities can be copy assigned and "
"members can be tested" ) {

verifyChunkWithMultiplicityType( copy );
} // THEN

THEN( "the record can be printed" ) {

std::string buffer;
auto output = std::back_inserter( buffer );
copy.print( output );

CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "using move assignment" ) {

auto iter = record.begin() + 9;
auto end = record.end();
ReactionMultiplicities chunk( ReactionMultiplicityType::All );
chunk.read( iter, end, 2 );

ReactionMultiplicities move = makeDummyRecord();
move = std::move( chunk );

THEN( "an ReactionMultiplicities can be copy assigned and "
"members can be tested" ) {

verifyChunkWithMultiplicityType( move );
} // THEN

THEN( "the record can be printed" ) {

std::string buffer;
auto output = std::back_inserter( buffer );
move.print( output );

CHECK( buffer == record );
} // THEN
} // WHEN
} // GIVEN

GIVEN( "invalid data for a ReactionMultiplicities instance" ) {
Expand Down Expand Up @@ -302,3 +507,8 @@ std::string chunkWithInsufficientNumberReactions() {

return "rprod\n";
}

ReactionMultiplicities makeDummyRecord() {

return ReactionMultiplicities( { { 102, { 1 }, { 1 } } } );
}
16 changes: 14 additions & 2 deletions src/NDItk/multigroup/ReactionCrossSections/src/ctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ ReactionCrossSections( ReactionCrossSections&& base ) :
*/
ReactionCrossSections& operator=( const ReactionCrossSections& base ) {

new (this) ReactionCrossSections( base );
if ( this != &base ) {

base::RealListRecord::operator=( base );
this->groups_ = base.groups_;
this->reactions_ = base.reactions_;
this->generateBlocks();
}
return *this;
}

Expand All @@ -59,6 +65,12 @@ ReactionCrossSections& operator=( const ReactionCrossSections& base ) {
*/
ReactionCrossSections& operator=( ReactionCrossSections&& base ) {

new (this) ReactionCrossSections( std::move( base ) );
if ( this != &base ) {

base::RealListRecord::operator=( std::move( base ) );
this->groups_ = base.groups_;
this->reactions_ = base.reactions_;
this->generateBlocks();
}
return *this;
}
Loading

0 comments on commit 850d77e

Please sign in to comment.