Repository navigation
Expand file tree
/
Copy pathdefinitions.hpp
More file actions
149 lines (126 loc) · 3.61 KB
/
Copy pathdefinitions.hpp
File metadata and controls
149 lines (126 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef NJOY_ACETK_PYTHON_DEFINITIONS
#define NJOY_ACETK_PYTHON_DEFINITIONS
// system includes
#include <complex>
// other includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "ACEtk/fromFile.hpp"
#include "tools/views/views-python.hpp"
namespace python = pybind11;
/**
* @brief Add standard lock definitions
*
* This adds the following standard properties:
* xss_array
*
* @param[in] table the table to which the definitions have to be added
*/
template < typename Table, typename PythonClass >
void addStandardTableDefinitions( PythonClass& table ) {
table
.def_property_readonly(
"header",
[] ( const Table& self ) { return self.header(); },
"The header information"
)
.def_property_readonly(
"data",
[] ( const Table& self ) { return self.data(); },
"The data arrays"
)
.def_static(
"from_file",
[] ( const std::string& filename ) -> Table {
return Table( njoy::ACEtk::fromFile( filename ) );
},
"Read an ACE table from a file\n\n"
"An exception is raised if something goes wrong while reading the\n"
"table\n\n"
"Arguments:\n"
" filename the file name and path"
)
.def_static(
"from_concatenated_file",
[] ( const std::string& filename ) -> std::vector< Table > {
std::vector< Table > tables;
auto content = njoy::ACEtk::fromConcatenatedFile( filename );
for ( auto&& table : content ) {
tables.emplace_back( std::move( table ) );
}
return tables;
},
"Read ACE tables from a concatenated file\n\n"
"An exception is raised if something goes wrong while reading the\n"
"table\n\n"
"Arguments:\n"
" filename the file name and path"
)
.def(
"to_file",
[] ( const Table& self, const std::string& filename ) {
std::ofstream out( filename );
self.print( out );
out.close();
},
"Write the ACE table to a file\n\n"
"Arguments:\n"
" self the table\n"
" filename the file name and path"
);
}
/**
* @brief Add standard block definitions
*
* This adds the following standard properties:
* name, length, xss_array
*
* @param[in] block the block to which the definitions have to be added
*/
template < typename Block, typename PythonClass >
void addStandardBlockDefinitions( PythonClass& block ) {
block
.def_property_readonly(
"name",
[] ( const Block& self ) { return self.name(); },
"The name of the block"
)
.def_property_readonly(
"length",
[] ( const Block& self ) { return self.length(); },
"The length of the the xss array of the block"
)
.def_property_readonly(
"empty",
[] ( const Block& self ) { return self.empty(); },
"Whether or not the block is empty"
)
.def_property_readonly(
"xss_array",
[] ( const Block& self ) -> DoubleRange
{ return self.XSS(); },
"The xss array of the block"
)
.def(
"xss",
[] ( const Block& self, std::size_t index )
{ return self.XSS( index ); },
python::arg( "index" ),
"Return a value from the xss array of the block\n\n"
"Arguments:\n"
" self the data block\n"
" index the index (one-based)"
)
.def(
"xss",
[] ( const Block& self, std::size_t index, std::size_t length ) -> DoubleRange
{ return self.XSS( index, length ); },
python::arg( "index" ), python::arg( "length" ),
"Return a subrange of a given length from the xss array of the block\n\n"
"Arguments:\n"
" self the data block\n"
" index the index (one-based)\n"
" length the length of the subrange"
);
}
#endif