PhoenixGenerator  2.0.4
Set of tools to generate code
Loading...
Searching...
No Matches
WrapperTraitDataStream Class Reference

Class generator for setter trait. More...

#include <WrapperTraitDataStream.h>

+ Inheritance diagram for WrapperTraitDataStream:
+ Collaboration diagram for WrapperTraitDataStream:

Public Member Functions

virtual void classMethodDeclaration (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Declaration of class method.
 
virtual void classMethodImplementation (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Implementation of class method.
 
virtual void headerExtraInclude (std::ofstream &fs, const GeneratorMode &mode) const
 Add extra include on the header.
 
virtual void registerClassGetterSetter (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Register class getter and setter.
 
virtual void registerClassMember (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 
virtual void registerClassMethod (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Register class method.
 
virtual void setupAddDependency (std::ofstream &fs, const GeneratorMode &mode) const
 Add dependency in the setup.py.
 
virtual void testCallFunction (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Call of the test function.
 
virtual void testFunction (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Implementation of test function.
 
 WrapperTraitDataStream ()
 Consctructor of WrapperTraitDataStream.
 
virtual ~WrapperTraitDataStream ()
 Desctructor of WrapperTraitDataStream.
 

Detailed Description

Class generator for setter trait.

Definition at line 16 of file WrapperTraitDataStream.h.

Constructor & Destructor Documentation

◆ WrapperTraitDataStream()

WrapperTraitDataStream::WrapperTraitDataStream ( )

Consctructor of WrapperTraitDataStream.

Definition at line 519 of file WrapperTraitDataStream.cpp.

References PAbstractWrapperTraitBackend::PAbstractWrapperTraitBackend().

+ Here is the call graph for this function:

◆ ~WrapperTraitDataStream()

WrapperTraitDataStream::~WrapperTraitDataStream ( )
virtual

Desctructor of WrapperTraitDataStream.

Definition at line 524 of file WrapperTraitDataStream.cpp.

524{}

Member Function Documentation

◆ classMethodDeclaration()

void WrapperTraitDataStream::classMethodDeclaration ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Declaration of class method.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractWrapperTraitBackend.

Definition at line 540 of file WrapperTraitDataStream.cpp.

540 {
541 if(!mode.enableDataStream){return;}
542 PString className(wrapper_getClassName(classConfig));
543 fs << "//Check function (used by data stream)\n";
544 fs << "bool "+className+"_check(std::string & error, const "+className+" & obj);\n";
545
546 fs << "//PhoenixDataStream interface\n";
547 fs << "PyObject * "+className+"_fromBytes(PyObject *self, PyObject *args);\n";
548 fs << "size_t "+className+"_fromMessage("+className+" & obj, DataStreamIter & iter);\n\n";
549
550 fs << "PyObject * "+className+"_toBytes(PyObject *self, PyObject *args);\n";
551 fs << "size_t "+className+"_toMessage("+className+" & obj, DataStreamIter & iter);\n\n";
552
553 fs << "PyObject * "+className+"_getSizeInByte(PyObject *self, PyObject *args);\n";
554 fs << "size_t "+className+"_getSize("+className+" & obj);\n\n";
555 if(!classConfig.getIsEnum()){
556 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
557 fs << "//PhoenixDataStream interface under the hood for all attributes\n";
558 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
559 fs << "//PhoenixDataStream interface under the hood for " + it->getName() + " attribute\n";
560 fs << "bool "+className+"_" + it->getName() + "_fromMessage("+className+" & self, DataStreamIter &iter);\n";
561 fs << "bool "+className+"_" + it->getName() + "_toMessage("+className+" & self, DataStreamIter &iter);\n";
562 fs << "size_t "+className+"_" + it->getName() + "_getSize("+className+" & self);\n\n";
563 }
564 }
565}
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.
bool enableDataStream
True to enable data stream interface generator.
PString wrapper_getClassName(const PClassConfig &classConfig)
Get the corresponding wrapper class name.

References GeneratorMode::enableDataStream, PClassConfig::getIsEnum(), PClassConfig::getListAttribute(), and wrapper_getClassName().

+ Here is the call graph for this function:

◆ classMethodImplementation()

void WrapperTraitDataStream::classMethodImplementation ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Implementation of class method.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractWrapperTraitBackend.

Definition at line 572 of file WrapperTraitDataStream.cpp.

572 {
573 if(!mode.enableDataStream){return;}
574 PString className(wrapper_getClassName(classConfig));
576 data_stream_trait_wrapper_classPythonFromBytes(fs, classConfig, className);
577 data_stream_trait_wrapper_classPythonToBytes(fs, classConfig, className);
578 data_stream_trait_wrapper_classPythonGetSizeInBytes(fs, classConfig, className);
579 if(!classConfig.getIsEnum()){
580 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
581 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
585 }
586 }
587}
void data_stream_trait_wrapper_classPythonGetSizeInBytes(std::ofstream &fs, const PClassConfig &classConfig, const PString &className)
Do the implementation of data stream method _getSizeInByte for one class.
void data_stream_trait_wrapper_classImplCheck(std::ofstream &fs, const PClassConfig &classConfig, const PString &moduleName)
Do the check implementation of class.
void data_stream_trait_wrapper_classPythonToBytes(std::ofstream &fs, const PClassConfig &classConfig, const PString &className)
Do the implementation of data stream method _toBytes for one class.
void data_stream_trait_wrapper_classAttributeFromMessage(std::ofstream &fs, const PString &className, const PClassAttribute &attr)
Do the implementation of from message of one attribute.
void data_stream_trait_wrapper_classPythonFromBytes(std::ofstream &fs, const PClassConfig &classConfig, const PString &className)
Do the implementation of data stream method _fromBytes for one class.
void data_stream_trait_wrapper_classAttributeToMessage(std::ofstream &fs, const PString &className, const PClassAttribute &attr)
Do the implementation of to message of one attribute.
void data_stream_trait_wrapper_classAttributeGetSize(std::ofstream &fs, const PString &className, const PClassAttribute &attr)
Do the implementation of get size of one attribute.
PString moduleName
Name of the wrapper python module.

References data_stream_trait_wrapper_classAttributeFromMessage(), data_stream_trait_wrapper_classAttributeGetSize(), data_stream_trait_wrapper_classAttributeToMessage(), data_stream_trait_wrapper_classImplCheck(), data_stream_trait_wrapper_classPythonFromBytes(), data_stream_trait_wrapper_classPythonGetSizeInBytes(), data_stream_trait_wrapper_classPythonToBytes(), GeneratorMode::enableDataStream, PClassConfig::getIsEnum(), PClassConfig::getListAttribute(), GeneratorMode::moduleName, and wrapper_getClassName().

+ Here is the call graph for this function:

◆ headerExtraInclude()

void WrapperTraitDataStream::headerExtraInclude ( std::ofstream & fs,
const GeneratorMode & mode ) const
virtual

Add extra include on the header.

Parameters
[out]fs: file to be completed
mode: mode of the generator

Reimplemented from PAbstractWrapperTraitBackend.

Definition at line 530 of file WrapperTraitDataStream.cpp.

530 {
531 if(!mode.enableDataStream){return;}
532 fs << "#include \"phoenix_data_stream.h\"" << std::endl;
533}

References GeneratorMode::enableDataStream.

◆ registerClassGetterSetter()

void WrapperTraitDataStream::registerClassGetterSetter ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Register class getter and setter.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractWrapperTraitBackend.

Definition at line 594 of file WrapperTraitDataStream.cpp.

594 {
595 if(!mode.enableDataStream){return;}
596
597}

References GeneratorMode::enableDataStream.

◆ registerClassMember()

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

Reimplemented in WrapperTraitEmpty, WrapperTraitGetterSetter, and WrapperTraitTypeStream.

Definition at line 53 of file PAbstractTraitBackend.h.

53{}

◆ registerClassMethod()

void WrapperTraitDataStream::registerClassMethod ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Register class method.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractWrapperTraitBackend.

Definition at line 604 of file WrapperTraitDataStream.cpp.

604 {
605 if(!mode.enableDataStream){return;}
606 PString className(wrapper_getClassName(classConfig));
607 fs << "\t{\"fromBytes\", (PyCFunction)"<<className<<"_fromBytes, METH_VARARGS, \"Doc : load a "<<className<<" from PyByteArray\"},\n";
608 fs << "\t{\"toBytes\", (PyCFunction)"<<className<<"_toBytes, METH_NOARGS, \"Doc : convert a "<<className<<" to PyByteArray\"},\n";
609 fs << "\t{\"getSize\", (PyCFunction)"<<className<<"_getSizeInByte, METH_NOARGS, \"Doc : Get the size of "<<className<<" in bytes\"},\n";
610}

References GeneratorMode::enableDataStream, and wrapper_getClassName().

+ Here is the call graph for this function:

◆ setupAddDependency()

void WrapperTraitDataStream::setupAddDependency ( std::ofstream & fs,
const GeneratorMode & mode ) const
virtual

Add dependency in the setup.py.

Parameters
[out]fs: file to be completed
mode: mode of the generator

Reimplemented from PAbstractWrapperTraitBackend.

Definition at line 654 of file WrapperTraitDataStream.cpp.

654 {
655 if(!mode.enableTypeStream){return;}
656 fs << "addWrapperDependency(listIncludeDir, listLibDir, listLib, \"phoenixdatastream-config\", [\"phoenix_data_stream\"])" << std::endl;
657}
bool enableTypeStream
True to enable type stream interface generator.

References GeneratorMode::enableTypeStream.

◆ testCallFunction()

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

Call of the test function.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractWrapperTraitBackend.

Definition at line 645 of file WrapperTraitDataStream.cpp.

645 {
646 if(!mode.enableDataStream){return;}
647
648}

References GeneratorMode::enableDataStream.

◆ testFunction()

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

Implementation of test function.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractWrapperTraitBackend.

Definition at line 617 of file WrapperTraitDataStream.cpp.

617 {
618 if(!mode.enableDataStream || classConfig.getIsEnum()){return;}
619 PString className(classConfig.getName()), moduleName(mode.moduleName);
620 fs << "#Unit Test of the " + className + "\n";
621 fs << "def test_datastream_"+className+"():\n";
622 fs << "\t#Let's test the stream now\n";
623 fs << "\tshadok = "+moduleName+"."+className+"()\n";
624 const std::vector<PClassAttribute> & vecAttr = classConfig.getListAttribute();
625 for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
626 fs << pythonDefaultTestValue("shadok", *it, moduleName, "\t", mode.mapClass);
627 }
628 fs << "\tstream = shadok.toBytes()\n";
629 fs << "\tassert len(stream) != 0\n";
630 fs << "\t\n";
631 fs << "\tother = "+moduleName+"."+className+"()\n";
632 fs << "\tother.fromBytes(stream)\n";
633 for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
634 fs << pythonAssertTestValue("other", *it, moduleName, "\t", mode.mapClass);
635 }
636 fs << "\t\n";
637 fs << "\t\n";
638}
PString pythonAssertTestValue(const PString &varName, const PClassAttribute &attr, const PString &moduleName, const PString &indentation, const std::map< std::string, PClassConfig > &mapClass)
Get the default set of given attribute for a test.
PString pythonDefaultTestValue(const PString &varName, const PClassAttribute &attr, const PString &moduleName, const PString &indentation, const std::map< std::string, PClassConfig > &mapClass)
Get the default set of given attribute for a test.
const PString & getName() const
Returns the class name.
std::map< std::string, PClassConfig > mapClass
Map of the generated class.

References GeneratorMode::enableDataStream, PClassConfig::getIsEnum(), PClassConfig::getListAttribute(), PClassConfig::getName(), GeneratorMode::mapClass, GeneratorMode::moduleName, pythonAssertTestValue(), and pythonDefaultTestValue().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: