Skip to content

Commit 3b2d0ca

Browse files
committed
Added to_string and from_string functions for generic ACE table components
1 parent 1d15ca2 commit 3b2d0ca

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎python/src/Data.python.cpp‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,31 @@ void wrapData( python::module& module, python::module& ) {
128128
"Arguments:\n"
129129
" self the data arrays\n"
130130
" index the index (one-based)"
131+
)
132+
.def_static(
133+
134+
"from_string",
135+
[] ( const std::string& string ) -> Component {
136+
137+
njoy::ACEtk::State< decltype(string.begin()) > state{ 1, string.begin(), string.end() };
138+
return Component( state );
139+
},
140+
python::arg( "string" ),
141+
"Read the ACE data arrays from a string\n\n"
142+
"An exception is raised if something goes wrong while reading the\n"
143+
"data arrays\n\n"
144+
"Arguments:\n"
145+
" string the string representing the ACE data arrays"
146+
)
147+
.def(
148+
149+
"to_string",
150+
[] ( const Component& self ) {
151+
152+
std::ostringstream out;
153+
self.print( out );
154+
return out.str();
155+
},
156+
"Return the string representation of the ACE data arrays"
131157
);
132158
}

‎python/src/Table.python.cpp‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,33 @@ void wrapTable( python::module& module, python::module& ) {
7878
},
7979
"Write the ACE table to a file\n\n"
8080
"Arguments:\n"
81-
" self the tape\n"
81+
" self the table\n"
8282
" filename the file name and path"
83+
)
84+
.def_static(
85+
86+
"from_string",
87+
[] ( const std::string& string ) -> Component {
88+
89+
njoy::ACEtk::State< decltype(string.begin()) > state{ 1, string.begin(), string.end() };
90+
return Component( state );
91+
},
92+
python::arg( "string" ),
93+
"Read the ACE table from a string\n\n"
94+
"An exception is raised if something goes wrong while reading the\n"
95+
"table\n\n"
96+
"Arguments:\n"
97+
" string the string representing the ACE table"
98+
)
99+
.def(
100+
101+
"to_string",
102+
[] ( const Component& self ) {
103+
104+
std::ostringstream out;
105+
self.print< 1,0,0 >( out );
106+
return out.str();
107+
},
108+
"Return the string representation of the ACE table"
83109
);
84110
}

0 commit comments

Comments
 (0)