PhoenixGenerator  2.8.0
Set of tools to generate code
Loading...
Searching...
No Matches
NanobindTraitCheckStream Class Reference

Class generator for Nanobind property trait. More...

#include <NanobindTraitCheckStream.h>

Inheritance diagram for NanobindTraitCheckStream:
Collaboration diagram for NanobindTraitCheckStream:

Public Member Functions

virtual void headerExtraInclude (std::set< std::string > &includes, const PClassConfig &classConfig, const GeneratorMode &mode) const
virtual void headerTestInclude (std::ofstream &fs, const GeneratorMode &mode, const PString &baseFileName) const
 NanobindTraitCheckStream ()
 Constructor of NanobindTraitCheckStream.
virtual void registerConstructor (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
virtual void registerMethod (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
virtual void registerProperty (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
virtual void registerStaticMethod (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
virtual void testCallFunction (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
virtual void testFunction (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode, const PString &baseFileName) const
virtual ~NanobindTraitCheckStream ()
 Destructor of NanobindTraitCheckStream.

Detailed Description

Class generator for Nanobind property trait.

Definition at line 15 of file NanobindTraitCheckStream.h.

Constructor & Destructor Documentation

◆ NanobindTraitCheckStream()

NanobindTraitCheckStream::NanobindTraitCheckStream ( )

Constructor of NanobindTraitCheckStream.

Definition at line 11 of file NanobindTraitCheckStream.cpp.

References PAbstractNanobindTraitBackend::PAbstractNanobindTraitBackend().

Here is the call graph for this function:

◆ ~NanobindTraitCheckStream()

NanobindTraitCheckStream::~NanobindTraitCheckStream ( )
virtual

Destructor of NanobindTraitCheckStream.

Definition at line 16 of file NanobindTraitCheckStream.cpp.

16{}

Member Function Documentation

◆ headerExtraInclude()

virtual void PAbstractNanobindTraitBackend::headerExtraInclude ( std::set< std::string > & includes,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
inlinevirtualinherited

Reimplemented in NanobindTraitInclude.

Definition at line 70 of file PAbstractTraitBackend.h.

70{}

◆ headerTestInclude()

virtual void PAbstractNanobindTraitBackend::headerTestInclude ( std::ofstream & fs,
const GeneratorMode & mode,
const PString & baseFileName ) const
inlinevirtualinherited

Reimplemented in NanobindTraitTestSetup.

Definition at line 71 of file PAbstractTraitBackend.h.

71{}

◆ registerConstructor()

virtual void PAbstractNanobindTraitBackend::registerConstructor ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
inlinevirtualinherited

Reimplemented in NanobindTraitMethod.

Definition at line 76 of file PAbstractTraitBackend.h.

76{}

◆ registerMethod()

virtual void PAbstractNanobindTraitBackend::registerMethod ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
inlinevirtualinherited

Reimplemented in NanobindTraitDataStream.

Definition at line 75 of file PAbstractTraitBackend.h.

75{}

◆ registerProperty()

virtual void PAbstractNanobindTraitBackend::registerProperty ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
inlinevirtualinherited

Reimplemented in NanobindTraitProperty.

Definition at line 73 of file PAbstractTraitBackend.h.

73{}

◆ registerStaticMethod()

void NanobindTraitCheckStream::registerStaticMethod ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Registration of static method

Parameters
fsstream to write to
classConfigconfig of the class
modegenerator mode

Reimplemented from PAbstractNanobindTraitBackend.

Definition at line 22 of file NanobindTraitCheckStream.cpp.

22 {
23 if(!mode.enableCheckStream){return;}
24 PString name(classConfig.getName());
25 if(classConfig.getIsEnum()){
26 name = name + "::" + name;
27 }
28 fs << std::endl << std::endl << "\t\t///Check stream method to compare two " << name << " objects";
29 fs << std::endl << "\t\t.def_static(\"check_stream\", [](const std::string & fieldDescription, const " << name << " & data, const " << name << " & reference) -> bool {";
30 fs << std::endl << "\t\t\tstd::stringstream out;";
31 fs << std::endl << "\t\t\tif(!CheckStream<" << name << ">::check_stream(fieldDescription, data, reference, out)){";
32 fs << std::endl << "\t\t\t\tthrow nb::value_error(out.str().c_str());";
33 fs << std::endl << "\t\t\t}";
34 fs << std::endl << "\t\t\treturn true;";
35 fs << std::endl << "\t\t}, ";
36 fs << std::endl << "\t\tnb::arg(\"fieldDescription\"), nb::arg(\"data\"), nb::arg(\"reference\"),";
37 fs << std::endl << "\t\t\"Check stream for " << name << " (equivalent to CheckStream<" << name << ">::check_stream)\")";
38}
const PString & getName() const
Returns the class name.
bool getIsEnum() const
Say if the current PClassConfig is an enum.
bool enableCheckStream
True to enable check stream interface generator.

References GeneratorMode::enableCheckStream, PClassConfig::getIsEnum(), and PClassConfig::getName().

Here is the call graph for this function:

◆ testCallFunction()

void NanobindTraitCheckStream::testCallFunction ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Generate test call to check stream function

Parameters
fsstream to write to
classConfigconfig of the class
modegenerator mode

Reimplemented from PAbstractNanobindTraitBackend.

Definition at line 92 of file NanobindTraitCheckStream.cpp.

92 {
93 if(!mode.enableUnitTest || !mode.enableCheckStream){return;}
94 PString name(classConfig.getName());
95 fs << "test_check_stream()" << std::endl;
96}
bool enableUnitTest
True to enable the unit tests.

References GeneratorMode::enableCheckStream, GeneratorMode::enableUnitTest, and PClassConfig::getName().

Here is the call graph for this function:

◆ testFunction()

void NanobindTraitCheckStream::testFunction ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode,
const PString & baseFileName ) const
virtual

Generate test function for check stream

Parameters
fsstream to write to
classConfigconfig of the class
modegenerator mode
baseFileName: base name of the configuration

Reimplemented from PAbstractNanobindTraitBackend.

Definition at line 45 of file NanobindTraitCheckStream.cpp.

45 {
46 if(!mode.enableUnitTest || !mode.enableCheckStream){return;}
47 PString name(classConfig.getName());
48 PString moduleName = baseFileName.toLower();
49
50 fs << "def test_check_stream():" << std::endl;
51 fs << "\t\"\"\"Test CheckStream functionality\"\"\"" << std::endl;
52 fs << std::endl;
53 fs << "\t# Create two identical " << name << std::endl;
54 const PVecClassAttribute & listAttr(classConfig.getListAttribute());
55 if(classConfig.getIsEnum()){
56 if(listAttr.size() != 0lu){
57 fs << "\ttest_value1 = " << moduleName << "." << name << "." << listAttr.front().getName() << std::endl;
58 fs << "\ttest_value2 = " << moduleName << "." << name << "." << listAttr.front().getName() << std::endl;
59 }
60 fs << "\t# Test identical " << name << " - should return True" << std::endl;
61 fs << "\tresult_identical = " << moduleName << "." << name << ".check_stream(\"Test identical\", test_value1, test_value2)" << std::endl;
62 fs << "\tassert result_identical == True, \"CheckStream should return True for identical " << name << "\"" << std::endl;
63 }else{
64 fs << "\ttest_value1 = " << moduleName << "." << name << "()" << std::endl;
65
66 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
67 PString defaultValue = getTestDefaultValueTypeInPython(it->getType());
68 if(defaultValue != ""){
69 fs << "\ttest_value1." << it->getName() << " = " << defaultValue << std::endl;
70 }
71 }
72 fs << std::endl;
73 fs << "\ttest_value2 = " << moduleName << "." << name << "()" << std::endl;
74 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
75 PString defaultValue = getTestDefaultValueTypeInPython(it->getType());
76 if(defaultValue != ""){
77 fs << "\ttest_value2." << it->getName() << " = " << defaultValue << std::endl;
78 }
79 }
80 fs << std::endl;
81 fs << "\t# Test identical " << name << " - should return True" << std::endl;
82 fs << "\tresult_identical = " << moduleName << "." << name << ".check_stream(\"Test identical\", test_value1, test_value2)" << std::endl;
83 fs << "\tassert result_identical == True, \"CheckStream should return True for identical " << name << "\"" << std::endl;
84 fs << std::endl;
85 }
86}
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.
PString getTestDefaultValueTypeInPython(const PString &type)
Get default test value for a given type in Python.

References GeneratorMode::enableCheckStream, GeneratorMode::enableUnitTest, PClassConfig::getIsEnum(), PClassConfig::getListAttribute(), PClassConfig::getName(), and getTestDefaultValueTypeInPython().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
  • /builds/CTA-LAPP/PHOENIX_LIBS2/code-generator/PhoenixGenerator/src/TraitBackEnd/Nanobind/NanobindTraitCheckStream/NanobindTraitCheckStream.h
  • /builds/CTA-LAPP/PHOENIX_LIBS2/code-generator/PhoenixGenerator/src/TraitBackEnd/Nanobind/NanobindTraitCheckStream/NanobindTraitCheckStream.cpp