#8250 AppFwk : Introduce variadic macros

Use variadic macros to to support optional parameters in initialization macros
This commit is contained in:
Magne Sjaastad 2021-11-14 14:13:01 +01:00
parent 6a7e729886
commit ff0b09d1c2
12 changed files with 130 additions and 73 deletions

View File

@ -59,9 +59,9 @@ public:
"CmdSelectionChangeExecData tooltip", "CmdSelectionChangeExecData tooltip",
"CmdSelectionChangeExecData whatsthis" ); "CmdSelectionChangeExecData whatsthis" );
CAF_PDM_InitFieldNoDefault( &m_selectionLevel, "selectionLevel", "selectionLevel", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_selectionLevel, "selectionLevel", "selectionLevel" );
CAF_PDM_InitField( &m_previousSelection, "previousSelection", std::vector<QString>(), "previousSelection", "", "", "" ); CAF_PDM_InitField( &m_previousSelection, "previousSelection", std::vector<QString>(), "previousSelection" );
CAF_PDM_InitField( &m_newSelection, "newSelection", std::vector<QString>(), "newSelection", "", "", "" ); CAF_PDM_InitField( &m_newSelection, "newSelection", std::vector<QString>(), "newSelection" );
} }
PdmField<int> m_selectionLevel; PdmField<int> m_selectionLevel;

View File

@ -50,7 +50,16 @@
#include <type_traits> #include <type_traits>
#define CAF_PDM_InitScriptableField( field, keyword, default, uiName, iconResourceName, toolTip, whatsThis ) \ #define CAF_PDM_InitScriptableField( field, keyword, default, uiName, ... ) \
{ \
std::vector<QString> arguments = { __VA_ARGS__ }; \
QString iconResourceName; \
QString toolTip; \
QString whatsThis; \
if ( arguments.size() > 0 ) iconResourceName = arguments[0]; \
if ( arguments.size() > 1 ) toolTip = arguments[1]; \
if ( arguments.size() > 2 ) whatsThis = arguments[2]; \
\
CAF_PDM_InitField( field, \ CAF_PDM_InitField( field, \
keyword, \ keyword, \
default, \ default, \
@ -58,25 +67,38 @@
iconResourceName, \ iconResourceName, \
caf::PdmAbstractFieldScriptingCapability::helpString( toolTip, keyword ), \ caf::PdmAbstractFieldScriptingCapability::helpString( toolTip, keyword ), \
whatsThis ); \ whatsThis ); \
caf::AddScriptingCapabilityToField( field, keyword ) caf::AddScriptingCapabilityToField( field, keyword ); \
}
#define CAF_PDM_InitScriptableFieldNoDefault( field, keyword, uiName, iconResourceName, toolTip, whatsThis ) \ #define CAF_PDM_InitScriptableFieldNoDefault( field, keyword, uiName, ... ) \
{ \
std::vector<QString> arguments = { __VA_ARGS__ }; \
QString iconResourceName; \
QString toolTip; \
QString whatsThis; \
if ( arguments.size() > 0 ) iconResourceName = arguments[0]; \
if ( arguments.size() > 1 ) toolTip = arguments[1]; \
if ( arguments.size() > 2 ) whatsThis = arguments[2]; \
\
CAF_PDM_InitFieldNoDefault( field, \ CAF_PDM_InitFieldNoDefault( field, \
keyword, \ keyword, \
uiName, \ uiName, \
iconResourceName, \ iconResourceName, \
caf::PdmAbstractFieldScriptingCapability::helpString( toolTip, keyword ), \ caf::PdmAbstractFieldScriptingCapability::helpString( toolTip, keyword ), \
whatsThis ); \ whatsThis ); \
caf::AddScriptingCapabilityToField( field, keyword ) caf::AddScriptingCapabilityToField( field, keyword ); \
}
#define CAF_PDM_InitScriptableFieldWithScriptKeyword( field, \ #define CAF_PDM_InitScriptableFieldWithScriptKeyword( field, keyword, scriptKeyword, default, uiName, ... ) \
keyword, \ { \
scriptKeyword, \ std::vector<QString> arguments = { __VA_ARGS__ }; \
default, \ QString iconResourceName; \
uiName, \ QString toolTip; \
iconResourceName, \ QString whatsThis; \
toolTip, \ if ( arguments.size() > 0 ) iconResourceName = arguments[0]; \
whatsThis ) \ if ( arguments.size() > 1 ) toolTip = arguments[1]; \
if ( arguments.size() > 2 ) whatsThis = arguments[2]; \
\
CAF_PDM_InitField( field, \ CAF_PDM_InitField( field, \
keyword, \ keyword, \
default, \ default, \
@ -84,22 +106,27 @@
iconResourceName, \ iconResourceName, \
caf::PdmAbstractFieldScriptingCapability::helpString( toolTip, scriptKeyword ), \ caf::PdmAbstractFieldScriptingCapability::helpString( toolTip, scriptKeyword ), \
whatsThis ); \ whatsThis ); \
caf::AddScriptingCapabilityToField( field, scriptKeyword ) caf::AddScriptingCapabilityToField( field, scriptKeyword ); \
}
#define CAF_PDM_InitScriptableFieldWithScriptKeywordNoDefault( field, \ #define CAF_PDM_InitScriptableFieldWithScriptKeywordNoDefault( field, keyword, scriptKeyword, uiName, ... ) \
keyword, \ { \
scriptKeyword, \ std::vector<QString> arguments = { __VA_ARGS__ }; \
uiName, \ QString iconResourceName; \
iconResourceName, \ QString toolTip; \
toolTip, \ QString whatsThis; \
whatsThis ) \ if ( arguments.size() > 0 ) iconResourceName = arguments[0]; \
if ( arguments.size() > 1 ) toolTip = arguments[1]; \
if ( arguments.size() > 2 ) whatsThis = arguments[2]; \
\
CAF_PDM_InitFieldNoDefault( field, \ CAF_PDM_InitFieldNoDefault( field, \
keyword, \ keyword, \
uiName, \ uiName, \
iconResourceName, \ iconResourceName, \
caf::PdmAbstractFieldScriptingCapability::helpString( toolTip, scriptKeyword ), \ caf::PdmAbstractFieldScriptingCapability::helpString( toolTip, scriptKeyword ), \
whatsThis ); \ whatsThis ); \
caf::AddScriptingCapabilityToField( field, scriptKeyword ) caf::AddScriptingCapabilityToField( field, scriptKeyword ); \
}
namespace caf namespace caf
{ {

View File

@ -48,7 +48,15 @@
class QTextStream; class QTextStream;
#define CAF_PDM_InitScriptableObject( uiName, iconResourceName, toolTip, whatsThis ) \ #define CAF_PDM_InitScriptableObject( uiName, ... ) \
std::vector<QString> arguments = { __VA_ARGS__ }; \
QString iconResourceName; \
QString toolTip; \
QString whatsThis; \
if ( arguments.size() > 0 ) iconResourceName = arguments[0]; \
if ( arguments.size() > 1 ) toolTip = arguments[1]; \
if ( arguments.size() > 2 ) whatsThis = arguments[2]; \
\
CAF_PDM_InitObject( uiName, iconResourceName, toolTip, whatsThis ); \ CAF_PDM_InitObject( uiName, iconResourceName, toolTip, whatsThis ); \
caf::PdmObjectScriptingCapabilityRegister::registerScriptClassNameAndComment( classKeyword(), \ caf::PdmObjectScriptingCapabilityRegister::registerScriptClassNameAndComment( classKeyword(), \
classKeyword(), \ classKeyword(), \

View File

@ -76,7 +76,7 @@ public:
m_proxyDouble.registerGetMethod( this, &SimpleObj::doubleMember ); m_proxyDouble.registerGetMethod( this, &SimpleObj::doubleMember );
AddUiCapabilityToField( &m_proxyDouble ); AddUiCapabilityToField( &m_proxyDouble );
AddXmlCapabilityToField( &m_proxyDouble ); AddXmlCapabilityToField( &m_proxyDouble );
CAF_PDM_InitFieldNoDefault( &m_proxyDouble, "ProxyDouble", "ProxyDouble", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_proxyDouble, "ProxyDouble", "ProxyDouble" );
#endif #endif
} }
@ -190,9 +190,9 @@ public:
"ScriptClassName_InheritedDemoObj", "ScriptClassName_InheritedDemoObj",
"Script comment test" ); "Script comment test" );
CAF_PDM_InitScriptableFieldNoDefault( &m_texts, "Texts", "Some words", "", "", "" ); CAF_PDM_InitScriptableFieldNoDefault( &m_texts, "Texts", "Some words" );
CAF_PDM_InitScriptableFieldNoDefault( &m_numbers, "Numbers", "Some words", "", "", "" ); CAF_PDM_InitScriptableFieldNoDefault( &m_numbers, "Numbers", "Some words" );
CAF_PDM_InitFieldNoDefault( &m_testEnumField, "TestEnumValue", "An Enum", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_testEnumField, "TestEnumValue", "An Enum" );
CAF_PDM_InitFieldNoDefault( &m_simpleObjectsField, CAF_PDM_InitFieldNoDefault( &m_simpleObjectsField,
"SimpleObjects", "SimpleObjects",
"SimpleObjectsField", "SimpleObjectsField",
@ -218,7 +218,7 @@ class MyPdmDocument : public caf::PdmDocument
public: public:
MyPdmDocument() MyPdmDocument()
{ {
CAF_PDM_InitObject( "PdmObjectCollection", "", "", "" ); CAF_PDM_InitObject( "PdmObjectCollection" );
CAF_PDM_InitFieldNoDefault( &objects, "PdmObjects", "", "", "", "" ) CAF_PDM_InitFieldNoDefault( &objects, "PdmObjects", "", "", "", "" )
} }

View File

@ -48,7 +48,7 @@ CAF_PDM_SOURCE_INIT( PdmDocument, "PdmDocument" );
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
PdmDocument::PdmDocument() PdmDocument::PdmDocument()
{ {
CAF_PDM_InitFieldNoDefault( &fileName, "DocumentFileName", "File Name", "", "", "" ); CAF_PDM_InitFieldNoDefault( &fileName, "DocumentFileName", "File Name" );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -77,8 +77,16 @@ class PdmObjectCapability;
/// Note that classKeyword() is not virtual in the constructor of the PdmObject /// Note that classKeyword() is not virtual in the constructor of the PdmObject
/// This is expected and fine. /// This is expected and fine.
#define CAF_PDM_InitObject( uiName, iconResourceName, toolTip, whatsThis ) \ #define CAF_PDM_InitObject( uiName, ... ) \
{ \ { \
std::vector<QString> arguments = { __VA_ARGS__ }; \
QString iconResourceName; \
QString toolTip; \
QString whatsThis; \
if ( arguments.size() > 0 ) iconResourceName = arguments[0]; \
if ( arguments.size() > 1 ) toolTip = arguments[1]; \
if ( arguments.size() > 2 ) whatsThis = arguments[2]; \
\
this->isInheritedFromPdmUiObject(); \ this->isInheritedFromPdmUiObject(); \
this->isInheritedFromPdmXmlSerializable(); \ this->isInheritedFromPdmXmlSerializable(); \
this->registerClassKeyword( classKeyword() ); \ this->registerClassKeyword( classKeyword() ); \
@ -94,8 +102,15 @@ class PdmObjectCapability;
/// Note that classKeyword() is not virtual in the constructor of the PdmObject /// Note that classKeyword() is not virtual in the constructor of the PdmObject
/// This is expected and fine. /// This is expected and fine.
#define CAF_PDM_InitField( field, keyword, default, uiName, iconResourceName, toolTip, whatsThis ) \ #define CAF_PDM_InitField( field, keyword, default, uiName, ... ) \
{ \ { \
std::vector<QString> arguments = { __VA_ARGS__ }; \
QString iconResourceName; \
QString toolTip; \
QString whatsThis; \
if ( arguments.size() > 0 ) iconResourceName = arguments[0]; \
if ( arguments.size() > 1 ) toolTip = arguments[1]; \
if ( arguments.size() > 2 ) whatsThis = arguments[2]; \
CAF_PDM_VERIFY_XML_KEYWORD( keyword ) \ CAF_PDM_VERIFY_XML_KEYWORD( keyword ) \
\ \
static bool chekingThePresenceOfHeaderAndSourceInitMacros = \ static bool chekingThePresenceOfHeaderAndSourceInitMacros = \
@ -116,8 +131,15 @@ class PdmObjectCapability;
/// Note that classKeyword() is not virtual in the constructor of the PdmObject /// Note that classKeyword() is not virtual in the constructor of the PdmObject
/// This is expected and fine. /// This is expected and fine.
#define CAF_PDM_InitFieldNoDefault( field, keyword, uiName, iconResourceName, toolTip, whatsThis ) \ #define CAF_PDM_InitFieldNoDefault( field, keyword, uiName, ... ) \
{ \ { \
std::vector<QString> arguments = { __VA_ARGS__ }; \
QString iconResourceName; \
QString toolTip; \
QString whatsThis; \
if ( arguments.size() > 0 ) iconResourceName = arguments[0]; \
if ( arguments.size() > 1 ) toolTip = arguments[1]; \
if ( arguments.size() > 2 ) whatsThis = arguments[2]; \
CAF_PDM_VERIFY_XML_KEYWORD( keyword ) \ CAF_PDM_VERIFY_XML_KEYWORD( keyword ) \
\ \
static bool chekingThePresenceOfHeaderAndSourceInitMacros = \ static bool chekingThePresenceOfHeaderAndSourceInitMacros = \

View File

@ -14,7 +14,7 @@ CAF_PDM_SOURCE_INIT( PdmObjectGroup, "PdmObjectGroup" );
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
PdmObjectGroup::PdmObjectGroup() PdmObjectGroup::PdmObjectGroup()
{ {
CAF_PDM_InitObject( "Object Group", "", "", "" ); CAF_PDM_InitObject( "Object Group" );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -51,7 +51,7 @@ CAF_PDM_SOURCE_INIT( PdmObjectCollection, "PdmObjectCollection" );
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
PdmObjectCollection::PdmObjectCollection() PdmObjectCollection::PdmObjectCollection()
{ {
CAF_PDM_InitObject( "PdmObjectCollection", "", "", "" ); CAF_PDM_InitObject( "PdmObjectCollection" );
CAF_PDM_InitFieldNoDefault( &objects, "PdmObjects", "", "", "", "" ) CAF_PDM_InitFieldNoDefault( &objects, "PdmObjects", "", "", "", "" )
} }

View File

@ -5,7 +5,7 @@ CAF_PDM_SOURCE_INIT( Child, "Child" );
Child::Child() Child::Child()
{ {
CAF_PDM_InitFieldNoDefault( &m_testObj, "Numbers", "Important Numbers", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_testObj, "Numbers", "Important Numbers" );
} }
Child::~Child() Child::~Child()

View File

@ -7,9 +7,9 @@ CAF_PDM_SOURCE_INIT( Parent, "Parent" );
Parent::Parent() Parent::Parent()
{ {
CAF_PDM_InitObject( "Parent", "", "", "" ); CAF_PDM_InitObject( "Parent" );
CAF_PDM_InitFieldNoDefault( &m_simpleObjectsField, "SimpleObjects", "A child object", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_simpleObjectsField, "SimpleObjects", "A child object" );
CAF_PDM_InitFieldNoDefault( &m_simpleObjectF, "SimpleObject", "A child object", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_simpleObjectF, "SimpleObject", "A child object" );
} }
Parent::~Parent() Parent::~Parent()

View File

@ -4,8 +4,8 @@ CAF_PDM_SOURCE_INIT( TestObj, "TestObj" );
TestObj::TestObj() TestObj::TestObj()
{ {
CAF_PDM_InitObject( "TestObj", "", "", "" ); CAF_PDM_InitObject( "TestObj" );
CAF_PDM_InitField( &m_position, "Position", 8765.2, "Position", "", "", "" ); CAF_PDM_InitField( &m_position, "Position", 8765.2, "Position" );
} }
TestObj::~TestObj() TestObj::~TestObj()

View File

@ -74,7 +74,7 @@ public:
m_proxyDouble.registerGetMethod( this, &SimpleObj::doubleMember ); m_proxyDouble.registerGetMethod( this, &SimpleObj::doubleMember );
AddUiCapabilityToField( &m_proxyDouble ); AddUiCapabilityToField( &m_proxyDouble );
AddXmlCapabilityToField( &m_proxyDouble ); AddXmlCapabilityToField( &m_proxyDouble );
CAF_PDM_InitFieldNoDefault( &m_proxyDouble, "ProxyDouble", "ProxyDouble", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_proxyDouble, "ProxyDouble", "ProxyDouble" );
#endif #endif
} }
@ -183,8 +183,8 @@ public:
{ {
CAF_PDM_InitObject( "InheritedDemoObj", "", "ToolTip InheritedDemoObj", "Whatsthis InheritedDemoObj" ); CAF_PDM_InitObject( "InheritedDemoObj", "", "ToolTip InheritedDemoObj", "Whatsthis InheritedDemoObj" );
CAF_PDM_InitFieldNoDefault( &m_texts, "Texts", "Some words", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_texts, "Texts", "Some words" );
CAF_PDM_InitFieldNoDefault( &m_testEnumField, "TestEnumValue", "An Enum", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_testEnumField, "TestEnumValue", "An Enum" );
CAF_PDM_InitFieldNoDefault( &m_simpleObjectsField, CAF_PDM_InitFieldNoDefault( &m_simpleObjectsField,
"SimpleObjects", "SimpleObjects",
"SimpleObjectsField", "SimpleObjectsField",
@ -208,7 +208,7 @@ class MyPdmDocument : public caf::PdmDocument
public: public:
MyPdmDocument() MyPdmDocument()
{ {
CAF_PDM_InitObject( "PdmObjectCollection", "", "", "" ); CAF_PDM_InitObject( "PdmObjectCollection" );
CAF_PDM_InitFieldNoDefault( &objects, "PdmObjects", "", "", "", "" ) CAF_PDM_InitFieldNoDefault( &objects, "PdmObjects", "", "", "", "" )
} }

View File

@ -130,7 +130,7 @@ public:
m_proxyDoubleField.registerSetMethod(this, &SmallDemoPdmObject::setDoubleMember); m_proxyDoubleField.registerSetMethod(this, &SmallDemoPdmObject::setDoubleMember);
m_proxyDoubleField.registerGetMethod(this, &SmallDemoPdmObject::doubleMember); m_proxyDoubleField.registerGetMethod(this, &SmallDemoPdmObject::doubleMember);
CAF_PDM_InitFieldNoDefault(&m_proxyDoubleField, "ProxyDouble", "Proxy Double", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_proxyDoubleField, "ProxyDouble", "Proxy Double");
CAF_PDM_InitFieldNoDefault(&m_colorTriplets, "colorTriplets", "color Triplets", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_colorTriplets, "colorTriplets", "color Triplets", "", "", "");