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

Class generator for Nanobind property trait. More...

#include <NanobindTraitDataStream.h>

Inheritance diagram for NanobindTraitDataStream:
Collaboration diagram for NanobindTraitDataStream:

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
 NanobindTraitDataStream ()
 Constructor of NanobindTraitDataStream.
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 ~NanobindTraitDataStream ()
 Destructor of NanobindTraitDataStream.

Detailed Description

Class generator for Nanobind property trait.

Definition at line 15 of file NanobindTraitDataStream.h.

Constructor & Destructor Documentation

◆ NanobindTraitDataStream()

NanobindTraitDataStream::NanobindTraitDataStream ( )

Constructor of NanobindTraitDataStream.

Definition at line 10 of file NanobindTraitDataStream.cpp.

References PAbstractNanobindTraitBackend::PAbstractNanobindTraitBackend().

Here is the call graph for this function:

◆ ~NanobindTraitDataStream()

NanobindTraitDataStream::~NanobindTraitDataStream ( )
virtual

Destructor of NanobindTraitDataStream.

Definition at line 15 of file NanobindTraitDataStream.cpp.

15{}

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()

void NanobindTraitDataStream::registerMethod ( 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 86 of file NanobindTraitDataStream.cpp.

86 {
87 if(!mode.enableDataStream){return;}
88 PString name(classConfig.getName());
89
90 registerSerializationMethods(fs, classConfig, mode);
91 registerDeserializationMethods(fs, classConfig, mode);
92 registerSizeMethod(fs, classConfig, mode);
93}
void registerSizeMethod(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode)
registration of size method
void registerSerializationMethods(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode)
registration of serialization methods
void registerDeserializationMethods(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode)
registration of serialization methods
const PString & getName() const
Returns the class name.
bool enableDataStream
True to enable data stream interface generator.

References GeneratorMode::enableDataStream, PClassConfig::getName(), registerDeserializationMethods(), registerSerializationMethods(), and registerSizeMethod().

Here is the call graph for this function:

◆ 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()

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

Reimplemented in NanobindTraitCheckStream, and NanobindTraitTypeStream.

Definition at line 74 of file PAbstractTraitBackend.h.

74{}

◆ testCallFunction()

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

Generation of unit test call function

Parameters
fsstream to write to
classConfigconfig of the class
modegenerator mode

Reimplemented from PAbstractNanobindTraitBackend.

Definition at line 184 of file NanobindTraitDataStream.cpp.

184 {
185 if(!mode.enableDataStream){return;}
186 PString name(classConfig.getName());
187 fs << "\ttest_data_stream_conversion()" << std::endl;
188 fs << "\ttest_serialization_type_errors()" << std::endl;
189}

References GeneratorMode::enableDataStream, and PClassConfig::getName().

Here is the call graph for this function:

◆ testFunction()

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

Generation of unit test function

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

Test base serialization/deserialization

Test edge cases for serialization/deserialization

Reimplemented from PAbstractNanobindTraitBackend.

Definition at line 118 of file NanobindTraitDataStream.cpp.

118 {
119 if(!mode.enableDataStream){return;}
120 PString name(classConfig.getName());
121 PString moduleName = baseFileName.toLower();
123 fs << "def test_data_stream_conversion():" << std::endl;
124 fs << "\t\"\"\"Test data stream conversion\"\"\"" << std::endl;
125
126 const PVecClassAttribute & listAttr(classConfig.getListAttribute());
127 if(classConfig.getIsEnum()){
128 if(listAttr.size() != 0lu){
129 fs << "\ttest_value1 = " << moduleName << "." << name << "." << listAttr.front().getName() << std::endl;
130 }
131 fs << "\tdata_stream = test_value1.to_bytes()" << std::endl;
132 fs << "\tassert data_stream == bytearray(b'\\x00\\x00\\x00\\x00')" << std::endl;
133 fs << "\ttest_value2 = " << moduleName << "." << name << ".from_bytes(data_stream)" << std::endl;
134 fs << std::endl;
135 fs << "\tassert test_value1.get_size() == 4" << std::endl;
136 fs << "\tassert test_value1 == test_value2" << std::endl;
137 fs << std::endl;
138 }else{
139 fs << "\t" << name.toLower() << " = " << moduleName << "." << name << "()" << std::endl;
140 fs << "\t# Set some example values" << std::endl;
141 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
142 PString defaultValue = getTestDefaultValueTypeInPython(it->getType());
143 if(defaultValue != ""){
144 fs << "\t" << name.toLower() << "." << it->getName() << " = " << defaultValue << std::endl;
145 }
146 }
147 fs << std::endl;
148 fs << "\tdata_stream = " << name.toLower() << ".to_bytes()" << std::endl;
149 fs << std::endl;
150 fs << "\tnew_" << name.toLower() << " = " << moduleName << "." << name << "()" << std::endl;
151 fs << "\tnew_" << name.toLower() << " = " << moduleName << "." << name << ".from_bytes(data_stream)" << std::endl;
152 fs << std::endl;
153 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
154 PString defaultValue = getTestDefaultValueTypeInPython(it->getType());
155 if(defaultValue != ""){
156 fs << "\tassert new_" << name.toLower() << "." << it->getName() << " == " << defaultValue << std::endl;
157 }
158 }
160 fs << std::endl;
161 fs << "def test_serialization_type_errors():" << std::endl;
162 fs << "\t\"\"\"Test erro types for from_bytes\"\"\"" << std::endl;
163 fs << std::endl;
164 fs << "\t" << name.toLower() << " = " << moduleName << "." << name << "()" << std::endl;
165 fs << "\twith pytest.raises(TypeError, match=\".*from_bytes\\(\\): incompatible function arguments.*\"):" << std::endl;
166 fs << "\t\tresult = " << name.toLower() << ".from_bytes(\"A string is not a bytearray !!!\") # deserialize string instead of bytearray" << std::endl;
167 fs << std::endl;
168 fs << "\twith pytest.raises(TypeError, match=\".*from_bytes\\(\\): incompatible function arguments.*\"):" << std::endl;
169 fs << "\t\tresult = " << name.toLower() << ".from_bytes(42) # deserialize instead of bytearray" << std::endl;
170 fs << std::endl;
171 fs << "\twith pytest.raises(TypeError, match=\".*from_bytes\\(\\): incompatible function arguments.*\"):" << std::endl;
172 fs << "\t\tresult = " << name.toLower() << ".from_bytes([1, 2, 3, 4]) # deserialize list instead of bytearray" << std::endl;
173 fs << std::endl;
174 }
175 if(classConfig.getIsEnum()){
176 failed_enum_deserialization(fs, classConfig, mode, baseFileName);
177 }
178}
void failed_enum_deserialization(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode, const PString &baseFileName)
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.
bool getIsEnum() const
Say if the current PClassConfig is an enum.
PString getTestDefaultValueTypeInPython(const PString &type)
Get default test value for a given type in Python.

References GeneratorMode::enableDataStream, failed_enum_deserialization(), 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/NanobindTraitDataStream/NanobindTraitDataStream.h
  • /builds/CTA-LAPP/PHOENIX_LIBS2/code-generator/PhoenixGenerator/src/TraitBackEnd/Nanobind/NanobindTraitDataStream/NanobindTraitDataStream.cpp