Skip to content

Commit

Permalink
Merge pull request #200 from njoy/feature/less-range-v3
Browse files Browse the repository at this point in the history
some cleanup in mf1
  • Loading branch information
whaeck authored Jun 10, 2024
2 parents 936a586 + 239f02f commit 374c991
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
3 changes: 1 addition & 2 deletions python/src/section/1/451.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ void wrapSection_1_451( python::module& module, python::module& viewmodule ) {
.def_property_readonly(

"description",
[] ( const Section& type ) -> std::string
{ return ranges::to< std::string >( type.description() ); },
&Section::description,
"The descriptive information"
)
.def_property_readonly(
Expand Down
6 changes: 1 addition & 5 deletions src/ENDFtk/section/1/451.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
#include "range/v3/iterator/operations.hpp"
#include "range/v3/range/conversion.hpp"
#include "range/v3/view/all.hpp"
#include "range/v3/view/concat.hpp"
#include "range/v3/view/join.hpp"
#include "range/v3/view/single.hpp"
#include "range/v3/view/split.hpp"
#include "range/v3/view/transform.hpp"
#include "ENDFtk/macros.hpp"
#include "ENDFtk/TextRecord.hpp"
#include "ENDFtk/HeadRecord.hpp"
Expand All @@ -31,7 +27,7 @@ namespace section {
* See ENDF102, section 1.1 for more information.
*/
template<>
class ENDFTK_PYTHON_EXPORT Type< 1, 451 > :
class ENDFTK_PYTHON_EXPORT Type< 1, 451 > :
protected BaseWithoutMT< Type< 1, 451 > > {

friend BaseWithoutMT< Type< 1, 451 > >;
Expand Down
15 changes: 7 additions & 8 deletions src/ENDFtk/section/1/451/src/description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
*/
auto description() const {

return
ranges::views::concat
( this->description_
| ranges::cpp20::views::transform
( []( const auto& textRecord )->decltype(auto)
{ return textRecord.text(); } )
| ranges::views::join( '\n' ),
ranges::cpp20::views::single( '\n' ) );
std::string description;
for ( auto&& record : this->description_ ) {

description += record.text();
description += '\n';
}
return description;
}
18 changes: 12 additions & 6 deletions src/ENDFtk/section/1/451/src/makeDescription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ static
std::vector< TextRecord >
makeDescription( const std::string& description ) {

return ranges::to< std::vector< TextRecord > >(
ranges::cpp20::views::split( description, '\n' )
| ranges::cpp20::views::transform(
[] ( const auto& line )
{ std::string string = ranges::to< std::string >( line );
return TextRecord( std::move( string ) ); } ) );
std::vector< TextRecord > result;
auto begin = description.begin();
auto iter = std::find_if( begin, description.end(),
[] ( auto&& character ) { return character == '\n'; } );
while ( begin != description.end() ) {

result.emplace_back( std::string( begin, iter ) );
begin = iter + 1;
iter = std::find_if( begin, description.end(),
[] ( auto&& character ) { return character == '\n'; } );
}
return result;
}

0 comments on commit 374c991

Please sign in to comment.