BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
PyFmt.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Py/PyFmt.h
6 //! @brief Defines namespace pyfmt.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_BASE_PY_PYFMT_H
21 #define BORNAGAIN_BASE_PY_PYFMT_H
22 
23 #include <heinz/Vectors3D.h>
24 #include <string>
25 #include <variant>
26 #include <vector>
27 
28 //! Utility functions for writing Python code snippets.
29 
30 namespace Py::Fmt {
31 
32 std::string printImportedSymbols(const std::string& code);
33 
34 std::string printInt(int value);
35 std::string printBool(double value);
36 std::string printDouble(double input);
37 std::string printLightDouble(double input);
38 std::string printNm(double input);
39 std::string printNm2(double input);
40 std::string printScientificDouble(double input);
41 std::string printDegrees(double input);
42 std::string printValue(double value, const std::string& units = "");
43 std::string printValue(std::variant<double, int> value, const std::string& units = "");
44 std::string printString(const std::string& value);
45 
46 //! Takes pairs of value/unit and concatenates them for an argument list.
47 //! Each pair's content will be processed by printValue(), so the meaning
48 //! of the content is the same as in printValue().
49 std::string printArguments(const std::vector<std::pair<double, std::string>>& arguments);
50 
51 //! Convenience overload for printing arguments containing a mixture of int and double
52 std::string
53 printArguments(const std::vector<std::pair<std::variant<double, int>, std::string>>& arguments);
54 
55 //! Print a function in the form "<name>(<arguments>)".
56 //! arguments will be processed by printArguments(), see there for details.
57 std::string printFunction(const std::string& name,
58  const std::vector<std::pair<double, std::string>>& arguments);
59 
60 //! Convenience overload for printing a function with one argument.
61 std::string printFunction(const std::string& name, double value, const std::string& unit);
62 
63 //! Convenience overload for printing a function with two arguments.
64 std::string printFunction(const std::string& name, double value1, const std::string& unit1,
65  double value2, const std::string& unit2);
66 
67 bool isSquare(double length1, double length2, double angle);
68 bool isHexagonal(double length1, double length2, double angle);
69 std::string printKvector(R3 value);
70 
71 //! Returns a string of blanks with given width. By default
72 //! the width equals standard offset in python files.
73 std::string indent(size_t width = 4u);
74 
75 } // namespace Py::Fmt
76 
77 #endif // BORNAGAIN_BASE_PY_PYFMT_H
78 #endif // USER_API
Utility functions for writing Python code snippets.
Definition: PyFmt.cpp:22
std::string printDegrees(double input)
Definition: PyFmt.cpp:116
std::string printDouble(double input)
Definition: PyFmt.cpp:46
std::string printLightDouble(double input)
prints double as an integer, if possible within standard accuracy
Definition: PyFmt.cpp:61
std::string printString(const std::string &value)
Definition: PyFmt.cpp:144
std::string printKvector(const R3 value)
Definition: PyFmt.cpp:195
std::string printScientificDouble(double input)
Definition: PyFmt.cpp:96
std::string printNm(double input)
Definition: PyFmt.cpp:79
bool isHexagonal(double length1, double length2, double angle)
Definition: PyFmt.cpp:190
std::string printBool(double value)
Definition: PyFmt.cpp:41
std::string indent(size_t width)
Returns a string of blanks with given width. By default the width equals standard offset in python fi...
Definition: PyFmt.cpp:203
std::string printNm2(double input)
Definition: PyFmt.cpp:87
std::string printFunction(const std::string &name, const std::vector< std::pair< double, std::string >> &arguments)
Print a function in the form "<name>(<arguments>)". arguments will be processed by printArguments(),...
Definition: PyFmt.cpp:168
std::string printArguments(const std::vector< std::pair< double, std::string >> &arguments)
Takes pairs of value/unit and concatenates them for an argument list. Each pair's content will be pro...
Definition: PyFmt.cpp:151
std::string printValue(double value, const std::string &units)
Definition: PyFmt.cpp:123
bool isSquare(double length1, double length2, double angle)
Definition: PyFmt.cpp:185
std::string printImportedSymbols(const std::string &code)
Definition: PyFmt.cpp:24
std::string printInt(int value)
Definition: PyFmt.cpp:36