PhoenixGenerator  2.2.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 72 of file NanobindTraitDataStream.cpp.

72 {
73 if(!mode.enableDataStream){return;}
74 PString name(classConfig.getName());
75
76 registerSerializationMethods(fs, classConfig, mode);
77 registerDeserializationMethods(fs, classConfig, mode);
78 registerSizeMethod(fs, classConfig, mode);
79}
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 140 of file NanobindTraitDataStream.cpp.

140 {
141 if(!mode.enableDataStream){return;}
142 PString name(classConfig.getName());
143 fs << "\ttest_data_stream_conversion()" << std::endl;
144 fs << "\ttest_serialization_type_errors()" << std::endl;
145}

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 86 of file NanobindTraitDataStream.cpp.

86 {
87 if(!mode.enableDataStream){return;}
88 PString name(classConfig.getName());
89 PString moduleName = baseFileName.toLower() + "_module";
91 fs << "def test_data_stream_conversion():" << std::endl;
92 fs << "\t\"\"\"Test data stream conversion\"\"\"" << std::endl;
93 fs << "\t" << name.toLower() << " = " << moduleName << "." << name << "()" << std::endl;
94 fs << "\t# Set some example values" << std::endl;
95 const PVecClassAttribute & listAttr(classConfig.getListAttribute());
96 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
97 PString defaultValue = getTestDefaultValueTypeInPython(it->getType());
98 fs << "\t" << name.toLower() << "." << it->getName() << " = " << defaultValue << std::endl;
99 }
100 fs << std::endl;
101 fs << "\tdata_stream = " << name.toLower() << ".to_bytes()" << std::endl;
102 fs << std::endl;
103 fs << "\tnew_" << name.toLower() << " = " << moduleName << "." << name << "()" << std::endl;
104 fs << "\tsuccess = new_" << name.toLower() << ".from_bytes(data_stream)" << std::endl;
105 fs << std::endl;
106 fs << "\tassert success" << std::endl;
107 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
108 PString defaultValue = getTestDefaultValueTypeInPython(it->getType());
109 fs << "\tassert new_" << name.toLower() << "." << it->getName() << " == " << defaultValue << std::endl;
110 }
112 fs << std::endl;
113 fs << "def test_serialization_type_errors():" << std::endl;
114 fs << "\t\"\"\"Test erro types for from_bytes\"\"\"" << std::endl;
115 fs << std::endl;
116 fs << "\t" << name.toLower() << " = " << moduleName << "." << name << "()" << std::endl;
117 fs << "\ttry:" << std::endl;
118 fs << "\t\tresult = " << name.toLower() << ".from_bytes(\"A string is not a bytearray !!!\") # deserialize string instead of bytearray" << std::endl;
119 fs << "\t\tassert False" << std::endl;
120 fs << "\texcept TypeError:" << std::endl;
121 fs << "\t\tpass" << std::endl;
122 fs << std::endl;
123 fs << "\ttry:" << std::endl;
124 fs << "\t\tresult = " << name.toLower() << ".from_bytes(42) # deserialize instead of bytearray" << std::endl;
125 fs << "\t\tassert False" << std::endl;
126 fs << "\texcept TypeError:" << std::endl;
127 fs << "\t\tpass" << std::endl;
128 fs << std::endl;
129 fs << "\ttry:" << std::endl;
130 fs << "\t\tresult = " << name.toLower() << ".from_bytes([1, 2, 3, 4]) # deserialize list instead of bytearray" << std::endl;
131 fs << "\t\tassert False" << std::endl;
132 fs << "\texcept TypeError:" << std::endl;
133 fs << "\t\tpass" << std::endl << std::endl;
134}
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::enableDataStream, 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: