Skip to content

Commit

Permalink
Merge pull request #182 from njoy/feature/remove-dependency
Browse files Browse the repository at this point in the history
Removing header-utilities code and removing the dependency
  • Loading branch information
whaeck authored Nov 27, 2023
2 parents 8f7eb3c + 93b1884 commit 5beeb26
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 99 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ target_link_libraries( ENDFtk
INTERFACE
Log
disco
header-utilities
range-v3
)

Expand Down
7 changes: 0 additions & 7 deletions cmake/develop_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ FetchContent_Declare( disco
GIT_SHALLOW TRUE
)

FetchContent_Declare( header-utilities
GIT_REPOSITORY https://github.com/njoy/header-utilities
GIT_TAG origin/master
GIT_SHALLOW TRUE
)

FetchContent_Declare( range-v3
GIT_REPOSITORY https://github.com/ericniebler/range-v3
GIT_TAG 0.11.0
Expand All @@ -46,6 +40,5 @@ FetchContent_Declare( pybind11
FetchContent_MakeAvailable(
Log
disco
header-utilities
range-v3
)
6 changes: 0 additions & 6 deletions cmake/release_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ FetchContent_Declare( disco
GIT_TAG 2606933a854bb0269c4ec37143e1236797e27838
)

FetchContent_Declare( header-utilities
GIT_REPOSITORY https://github.com/njoy/header-utilities
GIT_TAG cc2610fee15e255c151e8e22aca1e8b3d1a96b39
)

FetchContent_Declare( Log
GIT_REPOSITORY https://github.com/njoy/Log
GIT_TAG 52962b7796afe37ef1d8f7edb4bf9ecb1b868d15
Expand Down Expand Up @@ -47,7 +42,6 @@ set( SPDLOG_BUILD_TESTING CACHE BOOL OFF )

FetchContent_MakeAvailable(
disco
header-utilities
Log
range-v3
spdlog
Expand Down
11 changes: 2 additions & 9 deletions src/ENDFtk/InterpolationRecord/test/InterpolationRecord.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@

// other includes
#include "range/v3/range/operations.hpp"
#include "header-utilities/copy.hpp"

// convenience typedefs
using namespace njoy::ENDFtk;

std::function< InterpolationRecord() > makeTAB2 = [](){
auto metadata = std::make_tuple( 1.0, 2.0, 3ul, 4ul );
auto regionPairs = std::make_tuple( std::vector< long >{ 4, 5, 6 },
std::vector< long >{ 1, 2, 3 } );
std::function< InterpolationRecord() > makeTAB2 = [] () {

return InterpolationRecord
( std::get< 0 >( metadata ), std::get< 1 >( metadata ),
std::get< 2 >( metadata ), std::get< 3 >( metadata ),
njoy::utility::copy( regionPairs ) );
return InterpolationRecord( 1., 2., 3, 4, { 4, 5, 6 }, { 1, 2, 3 } );
};

#include "ENDFtk/InterpolationRecord/test/ctor.test.hpp"
Expand Down
14 changes: 6 additions & 8 deletions src/ENDFtk/ListRecord/test/ListRecord.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#include "ENDFtk/ListRecord.hpp"

// other includes
#include "header-utilities/copy.hpp"

// convenience typedefs
using namespace njoy::ENDFtk;

SCENARIO( "ListRecord Tests", "[ENDFtk], [ListRecord]" ){
SCENARIO( "ListRecord Tests", "[ENDFtk], [ListRecord]" ) {

auto values = std::make_tuple( 1.001000E+3, 9.991673E-1, 0, 0, 10, 5 );
std::vector< double > list{0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};

Expand All @@ -20,9 +20,8 @@ SCENARIO( "ListRecord Tests", "[ENDFtk], [ListRecord]" ){

GIVEN( "value construction, the ctor works"){
REQUIRE_NOTHROW(
ListRecord( std::get< 0 >(values), std::get< 1 >(values),
std::get< 2 >(values), std::get< 3 >(values),
std::get< 5 >(values), njoy::utility::copy(list) ) );
ListRecord( 1.001000E+3, 9.991673E-1, 0, 0, 5,
{0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0} ) );
}

GIVEN( "iterators and a line number"){
Expand Down Expand Up @@ -105,9 +104,8 @@ SCENARIO( "ListRecord Tests", "[ENDFtk], [ListRecord]" ){
auto listRecord0 = ListRecord( it, end, lineNumber, 125, 1, 451 );
const auto& constListRecord0 = listRecord0;
auto listRecord1 =
ListRecord( std::get< 0 >(values), std::get< 1 >(values),
std::get< 2 >(values), std::get< 3 >(values),
std::get< 5 >(values), njoy::utility::copy(list) );
ListRecord( 1.001000E+3, 9.991673E-1, 0, 0, 5,
{0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0} );

const auto& constListRecord1 = listRecord1;
THEN( "the getter will work" ){
Expand Down
95 changes: 64 additions & 31 deletions src/ENDFtk/StructureDivision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

// other includes
#include "Log.hpp"
#include "header-utilities/echoErroneousLine.hpp"
#include "ENDFtk/record.hpp"

namespace njoy {
namespace ENDFtk {

class StructureDivision {

public:

/* convenience typedefs */
using Base =
record::Base< record::Real, record::Real,
Expand All @@ -32,96 +33,119 @@ namespace ENDFtk {

template< typename Iterator >
StructureDivision( Iterator& it, const Iterator& end, long& lineNumber ) :
StructureDivision( it, it, end, lineNumber ){}
StructureDivision( it, it, end, lineNumber ) {}

template< typename Iterator >
StructureDivision
( Iterator begin, Iterator& it, const Iterator& end, long& lineNumber )
try: base( it, end ), tail( it, end, lineNumber ) {
auto fieldPosition = std::next( begin, 66 );
if (tail.material() < -1){
try : base( it, end ), tail( it, end, lineNumber ) {

if (tail.material() < -1) {

Log::error( "Illegal material number (MAT) encountered" );
utility::echoErroneousLine( begin, fieldPosition, end, lineNumber - 1 );
Log::info( "Error parsing line {}: \"{}\"",
lineNumber - 1,
std::string( begin, std::find( begin, end, '\n' ) ) );
Log::info( "Material numbers are greater than or equal to -1" );
Log::info( "Material number: {}", this->tail.material() );
throw std::exception();
}
if (tail.file() < 0){
std::advance( fieldPosition, 4 );
if (tail.file() < 0) {

Log::error( "Illegal file number (MF) encountered" );
utility::echoErroneousLine( begin, fieldPosition, end, lineNumber - 1 );
Log::info( "Error parsing line {}: \"{}\"",
lineNumber - 1,
std::string( begin, std::find( begin, end, '\n' ) ) );
Log::info( "File numbers are greater than or equal to 0" );
Log::info( "File number: {}", this->tail.file() );
throw std::exception();
}
if (tail.section() < 0){
std::advance( fieldPosition, 6 );
if (tail.section() < 0) {

Log::error( "Illegal section number (MT) encountered" );
utility::echoErroneousLine( begin, fieldPosition, end, lineNumber - 1 );
Log::info( "Error parsing line {}: \"{}\"",
lineNumber - 1,
std::string( begin, std::find( begin, end, '\n' ) ) );
Log::info( "Section numbers are greater than or equal to 0" );
Log::info( "Section number: {}", this->tail.section() );
throw std::exception();
}
} catch ( int fieldNumber ){
auto fieldPosition = std::next( begin, 66 );
}
catch ( int fieldNumber ) {

switch (fieldNumber) {
case 6 :

Log::error( "Illegal material number (MAT) encountered" );
utility::echoErroneousLine( begin, fieldPosition, end, lineNumber );
Log::info( "Error while parsing line {}:", lineNumber - 1 );
Log::info( "Line {}:", std::string( begin, std::find( begin, end, '\n' ) ) );
break;
case 7 :
std::advance( fieldPosition, 4 );

Log::error( "Illegal file number (MF) encountered" );
utility::echoErroneousLine( begin, fieldPosition, end, lineNumber );
Log::info( "Error while parsing line {}:", lineNumber - 1 );
Log::info( "Line {}:", std::string( begin, std::find( begin, end, '\n' ) ) );
break;
case 8 :
std::advance( fieldPosition, 6 );

Log::error( "Illegal section number (MT) encountered" );
utility::echoErroneousLine( begin, fieldPosition, end, lineNumber );
Log::info( "Error while parsing line {}:", lineNumber - 1 );
Log::info( "Line {}:", std::string( begin, std::find( begin, end, '\n' ) ) );
break;
default:
break;
}
throw std::exception();
} catch ( std::exception& e ){
}
catch ( std::exception& e ) {

Log::info( "Error encountered while constructing structure division" );
throw e;
}

bool isHead() const {

return this->tail.section() and this->tail.file() and this->tail.material();
}

bool isSendPermissive() const {

const static Base empty(0.0, 0.0, 0, 0, 0, 0);
return ( this->base == empty ) and ( this->tail.section() == 0 );
};

bool isSend() const {

return this->isSendPermissive()
and this->tail.file()
and ( this->tail.material() > 0 );
}

bool isFendPermissive() const {

return this->isSendPermissive() and ( this->tail.file() == 0 );
}

bool isFend() const {

return this->isFendPermissive() and ( this->tail.material() > 0 );
}

bool isMend() const {

return this->isFendPermissive() and ( this->tail.material() == 0 );
}

bool isTend() const {

return this->isFendPermissive() and ( this->tail.material() == -1 );
}

template< typename OutputIterator >
void print( OutputIterator& it ) const {

if ( this->isHead() ) {

using Format = disco::Record< disco::ENDF, disco::ENDF,
disco::Integer< 11 >, disco::Integer< 11 >,
disco::Integer< 11 >, disco::Integer< 11 >,
Expand All @@ -137,6 +161,7 @@ namespace ENDFtk {
this->tail.MAT(), this->tail.MF(), this->tail.MT() );
}
else {

using Format = disco::Record< disco::Integer< 70 >,
disco::Integer< 2 >,
disco::Integer< 3 >,
Expand All @@ -146,14 +171,17 @@ namespace ENDFtk {
}
};

inline StructureDivision sectionEndRecord( int MAT, int MF ){
if ( MAT < 1 ){
inline StructureDivision sectionEndRecord( int MAT, int MF ) {

if ( MAT < 1 ) {

Log::error( "Illegal material number (MAT) specified in SEND record" );
Log::info( "SEND records require a material number greater than 0" );
Log::info( "Specified material number: {}", MAT );
throw std::exception();
}
if ( MF < 1 ){
if ( MF < 1 ) {

Log::error( "Illegal file number (MF) specified in SEND record" );
Log::info( "SEND records require a file number greater than 0" );
Log::info( "Specified file number: {}", MF );
Expand All @@ -162,12 +190,15 @@ namespace ENDFtk {
return StructureDivision( 0.0, 0.0, 0, 0, 0, 0, MAT, MF, 0 );
}

inline StructureDivision SEND( int MAT, int MF ){
inline StructureDivision SEND( int MAT, int MF ) {

return sectionEndRecord( MAT, MF );
}

inline StructureDivision fileEndRecord( int MAT ){
if ( MAT < 1 ){
inline StructureDivision fileEndRecord( int MAT ) {

if ( MAT < 1 ) {

Log::error( "Illegal material number (MAT) specified in FEND record" );
Log::info( "FEND records require a material number greater than 0" );
Log::info( "Specified material number: {}", MAT );
Expand All @@ -176,19 +207,21 @@ namespace ENDFtk {
return StructureDivision( 0.0, 0.0, 0, 0, 0, 0, MAT, 0, 0 );
}

inline StructureDivision FEND( int MAT ){ return fileEndRecord( MAT ); }
inline StructureDivision FEND( int MAT ) { return fileEndRecord( MAT ); }

inline StructureDivision materialEndRecord() {

inline StructureDivision materialEndRecord(){
return StructureDivision( 0.0, 0.0, 0, 0, 0, 0, 0, 0, 0 );
}

inline StructureDivision MEND(){ return materialEndRecord(); }
inline StructureDivision MEND() { return materialEndRecord(); }

inline StructureDivision tapeEndRecord() {

inline StructureDivision tapeEndRecord(){
return StructureDivision( 0.0, 0.0, 0, 0, 0, 0, -1, 0, 0 );
}

inline StructureDivision TEND(){ return tapeEndRecord(); }
inline StructureDivision TEND() { return tapeEndRecord(); }

} // ENDFtk namespace
} // njoy namespace
Expand Down
17 changes: 5 additions & 12 deletions src/ENDFtk/TabulationRecord/test/TabulationRecord.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@
// other includes
#include "range/v3/algorithm/equal.hpp"
#include "range/v3/range/operations.hpp"
#include "header-utilities/copy.hpp"

// convenience typedefs
using namespace njoy::ENDFtk;

std::function< TabulationRecord() > makeTAB1 = [](){
auto metadata = std::make_tuple( 1.0, 2.0, 3ul, 4ul );
auto regionPairs = std::make_tuple( std::vector< long >{ 4, 5, 6 },
std::vector< long >{ 1, 2, 3 } );
auto orderedPairs =
std::make_tuple( std::vector< double >{ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 },
std::vector< double >{ 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 } );
std::function< TabulationRecord() > makeTAB1 = [] () {

return TabulationRecord
( std::get< 0 >( metadata ), std::get< 1 >( metadata ),
std::get< 2 >( metadata ), std::get< 3 >( metadata ),
njoy::utility::copy( regionPairs ), njoy::utility::copy( orderedPairs ) );
return TabulationRecord ( 1., 2., 3, 4,
{ 4, 5, 6 }, { 1, 2, 3 },
{ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 },
{ 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 } );
};

#include "ENDFtk/TabulationRecord/test/ctor.test.hpp"
Expand Down
5 changes: 2 additions & 3 deletions src/ENDFtk/TextRecord/test/TextRecord.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "ENDFtk/TextRecord.hpp"

// other includes
#include "header-utilities/copy.hpp"

// convenience typedefs
using namespace njoy::ENDFtk;
Expand All @@ -17,7 +16,7 @@ SCENARIO( "TextRecord Tests", "[ENDFtk], [TextRecord]" ){
"The new R-matrix analysis of the N-N system on which the ENDF/B- ";

GIVEN( "a string ravlue, the ctor works"){
REQUIRE_NOTHROW( TextRecord( njoy::utility::copy(text) ) );
REQUIRE_NOTHROW( TextRecord( std::string(text) ) );
}

GIVEN( "iterators and a line number"){
Expand Down Expand Up @@ -69,7 +68,7 @@ SCENARIO( "TextRecord Tests", "[ENDFtk], [TextRecord]" ){
auto lineNumber = 0l;
auto textRecord0 = TextRecord( it, end, lineNumber, 125, 1, 451 );
const auto& constTextRecord0 = textRecord0;
auto textRecord1 = TextRecord( njoy::utility::copy( text ) );
auto textRecord1 = TextRecord( std::string( text ) );
const auto& constTextRecord1 = textRecord1;

THEN( "the getter will work" ){
Expand Down
Loading

0 comments on commit 5beeb26

Please sign in to comment.