Skip to content

Commit

Permalink
Added some customisation to ReactionSuite and Reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Apr 2, 2021
1 parent e252073 commit 594fdba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/GNDStk/v1.9/transport/ReactionSuite/src/custom.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const transport::Reaction& reaction( const std::string& label ) const {

return this->reactions().reaction( label );
}
17 changes: 17 additions & 0 deletions src/GNDStk/v1.9/transport/Reactions/src/custom.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const transport::Reaction& reaction( const std::string& label ) const {

This comment has been minimized.

Copy link
@staleyLANL

staleyLANL Apr 7, 2021

Contributor

This looks incomplete.


auto getLabel = [] ( const auto& variant )

This comment has been minimized.

Copy link
@staleyLANL

staleyLANL Apr 7, 2021

Contributor

getLabel is not used.

{ return variant.get().label().value(); };

auto iter std::find_if( this->content.reaction.begin(), this->content.reaction.end(),

This comment has been minimized.

Copy link
@staleyLANL

staleyLANL Apr 7, 2021

Contributor

iter = ... of course. :-)

[&] ( const transport::Reaction& element )
{ return element.label() == label; } );

if ( iter != this->children_.end() ) {

log::error( "No cross section style \"{}\" can be found", style );
throw std::exception();
}

return *iter;
}

1 comment on commit 594fdba

@staleyLANL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, the core interface already provides for queries such as node(reactions,reaction,"label"), given a node that contains a reactions child. (Or if you're in reactions already, just write node(reaction,"label")). The issue here is that we don't have a node, because we're working directly with our "high-level" classes. Each high-level class that's derived from Component - as they all in fact are - automatically gets a conversion to a Node. Through that, a query like this would be short - but computationally intensive, because I'd be making an entire Node on-the-fly each time, just to pull out the one value with a particular label. I'll think about things I might be able to do that would remove the need to write functions like this all over the place throughout the high-level interface. For common activities such as finding something by-level in a sub-node, I could almost certainly write some generic utility function that would do almost all of the work, so that things like this could become one-liners.

Please sign in to comment.