From: spo Date: Fri, 27 May 2016 12:26:16 +0000 (+0300) Subject: Cleare Macros for easy atribute initialization in C++HighAPI interfaces X-Git-Tag: V_2.4.0~91^2~86 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cfe5bbc0ebcc59652a4aa95539f2580b8efc8d6a;p=modules%2Fshaper.git Cleare Macros for easy atribute initialization in C++HighAPI interfaces --- diff --git a/CMakeCommon/PythonAPI.cmake b/CMakeCommon/PythonAPI.cmake index 123354160..c6f311bac 100644 --- a/CMakeCommon/PythonAPI.cmake +++ b/CMakeCommon/PythonAPI.cmake @@ -33,5 +33,5 @@ endforeach() add_custom_command(OUTPUT doxyhelp.i COMMAND "${DOXYGEN_EXECUTABLE}" COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/doxy2swig.py xml/index.xml doxyhelp.i - DEPENDS ${doc_sources} + DEPENDS ${doc_sources} ${PROJECT_SOURCE_DIR}/doc/swig/doxyfile.in ) diff --git a/doc/swig/doxyfile.in b/doc/swig/doxyfile.in index bffdb82f1..60b3b276e 100644 --- a/doc/swig/doxyfile.in +++ b/doc/swig/doxyfile.in @@ -251,7 +251,7 @@ ENABLE_PREPROCESSING = YES MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = NO SEARCH_INCLUDES = YES -INCLUDE_PATH = +INCLUDE_PATH = @PROJECT_SOURCE_DIR@/src/ModelHighAPI INCLUDE_FILE_PATTERNS = PREDEFINED = Standard_EXPORT __Standard_API __Draw_API Handle(a):=Handle DEFINE_STANDARD_ALLOC DEFINE_NCOLLECTION_ALLOC DEFINE_STANDARD_HANDLE DEFINE_STANDARD_RTTI EXPAND_AS_DEFINED = diff --git a/doc/tui/doxyfile.in b/doc/tui/doxyfile.in index 8cbc02357..538e95925 100644 --- a/doc/tui/doxyfile.in +++ b/doc/tui/doxyfile.in @@ -1578,7 +1578,7 @@ SEARCH_INCLUDES = YES # contain include files that are not input files but should be processed by # the preprocessor. -INCLUDE_PATH = +INCLUDE_PATH = @PROJECT_SOURCE_DIR@/src/ModelHighAPI # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the diff --git a/src/ConstructionAPI/ConstructionAPI_Point.cpp b/src/ConstructionAPI/ConstructionAPI_Point.cpp index 7464536c4..e28a96bb4 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Point.cpp @@ -27,10 +27,8 @@ ConstructionAPI_Point::ConstructionAPI_Point( const ModelHighAPI_Double & theZ) : ModelHighAPI_Interface(theFeature) { - if (initialize()) { + if (initialize()) setPoint(theX, theY, theZ); - execute(); - } } ConstructionAPI_Point::~ConstructionAPI_Point() @@ -38,52 +36,16 @@ ConstructionAPI_Point::~ConstructionAPI_Point() } -//-------------------------------------------------------------------------------------- -bool ConstructionAPI_Point::initialize() -{ - if (!myFeature) { - throwException("ConstructionAPI_Point exception: The feature is NULL."); - return false; - } - - if (feature()->getKind() != "Point") { - throwException("ConstructionAPI_Point exception: Wrong feature kind."); - return false; - } - - // data() throws exceptions if the attribute is invalid - myX = feature()->real("x"); - myY = feature()->real("y"); - myZ = feature()->real("z"); - - if (!myX || !myY || !myZ) - return false; - - return true; -} - //-------------------------------------------------------------------------------------- void ConstructionAPI_Point::setPoint(const ModelHighAPI_Double & theX, const ModelHighAPI_Double & theY, const ModelHighAPI_Double & theZ) { - theX.fillAttribute(myX); - theY.fillAttribute(myY); - theZ.fillAttribute(myZ); -} + theX.fillAttribute(myx); + theY.fillAttribute(myy); + theZ.fillAttribute(myz); -//-------------------------------------------------------------------------------------- -std::shared_ptr ConstructionAPI_Point::x() const -{ - return myX; -} -std::shared_ptr ConstructionAPI_Point::y() const -{ - return myY; -} -std::shared_ptr ConstructionAPI_Point::z() const -{ - return myZ; + execute(); } //-------------------------------------------------------------------------------------- diff --git a/src/ConstructionAPI/ConstructionAPI_Point.h b/src/ConstructionAPI/ConstructionAPI_Point.h index 4df2ded97..aef5b8150 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.h +++ b/src/ConstructionAPI/ConstructionAPI_Point.h @@ -11,6 +11,7 @@ #include "ConstructionAPI.h" #include +#include //-------------------------------------------------------------------------------------- class ModelAPI_AttributeDouble; class ModelAPI_Document; @@ -33,25 +34,18 @@ public: /// Destructor virtual ~ConstructionAPI_Point(); + INTERFACE_3("Point", + x, "x", Double, /** X attribute */, + y, "y", Double, /** Y attribute */, + z, "z", Double, /** Z attribute */) + /// Set point values void setPoint(const ModelHighAPI_Double & theX, const ModelHighAPI_Double & theY, const ModelHighAPI_Double & theZ); - - /// X attribute - std::shared_ptr x() const; - /// Y attribute - std::shared_ptr y() const; - /// Z attribute - std::shared_ptr z() const; - -protected: - std::shared_ptr myX, myY, myZ; - - bool initialize(); }; -//! Pointer on point object +//! Pointer on Point object typedef std::shared_ptr PointPtr; /**\ingroup CPPHighAPI diff --git a/src/ConstructionAPI/Test/TestPoint.cpp b/src/ConstructionAPI/Test/TestPoint.cpp index b136b0367..b053d5f6c 100644 --- a/src/ConstructionAPI/Test/TestPoint.cpp +++ b/src/ConstructionAPI/Test/TestPoint.cpp @@ -117,7 +117,8 @@ TEST_F(ConstructionAPI_Point_Constructor_Test, GetFeatureAndValues) { ConstructionAPI_Point aPoint(aFeature, 10, "20", std::string("x + 30")); } -TEST_F(ConstructionAPI_Point_Constructor_Test, addPointWithValues) { + +TEST_F(ConstructionAPI_Point_Constructor_Test, addPoint) { DocumentPtr aDocument(&aMockDocument, &null_deleter); EXPECT_CALL(aMockDocument, addFeature("Point", true)); diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h index 61b1979a0..896b00759 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelection.h +++ b/src/ModelAPI/ModelAPI_AttributeSelection.h @@ -49,7 +49,7 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute /// Returns a textual string of the selection /// \param theDefaultValue a value, which is used if the naming name can not be obtained virtual std::string namingName(const std::string& theDefaultValue = "") = 0; - + /// Returns an id of the selection virtual int Id() = 0; diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index 7ae927be6..c9fa67ca8 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -6,6 +6,7 @@ SET(PROJECT_HEADERS ModelHighAPI.h ModelHighAPI_Double.h ModelHighAPI_Interface.h + ModelHighAPI_Macro.h ) SET(PROJECT_SOURCES diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i index 754aa7707..19a930efa 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -40,3 +40,4 @@ // all supported interfaces %include "ModelHighAPI_Double.h" %include "ModelHighAPI_Interface.h" +%include "ModelHighAPI_Macro.h" diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.cpp b/src/ModelHighAPI/ModelHighAPI_Interface.cpp index a72146ab6..e5a81879b 100644 --- a/src/ModelHighAPI/ModelHighAPI_Interface.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Interface.cpp @@ -28,6 +28,11 @@ std::shared_ptr ModelHighAPI_Interface::feature() const return myFeature; } +const std::string& ModelHighAPI_Interface::getKind() +{ + return feature()->getKind(); +} + void ModelHighAPI_Interface::execute() { feature()->execute(); diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.h b/src/ModelHighAPI/ModelHighAPI_Interface.h index 4393b4807..295d87036 100644 --- a/src/ModelHighAPI/ModelHighAPI_Interface.h +++ b/src/ModelHighAPI/ModelHighAPI_Interface.h @@ -28,6 +28,9 @@ public: /// Return ModelAPI_Feature std::shared_ptr feature() const; + /// Shortcut for feature()->getKind() + const std::string& getKind(); + /// Shortcut for feature()->execute() void execute(); diff --git a/src/ModelHighAPI/ModelHighAPI_Macro.h b/src/ModelHighAPI/ModelHighAPI_Macro.h new file mode 100644 index 000000000..a00b07526 --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_Macro.h @@ -0,0 +1,272 @@ +// Name : ModelHighAPI_Macro.h +// Purpose: +// +// History: +// 27/05/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_MACRO_H_ +#define SRC_MODELHIGHAPI_MODELHIGHAPI_MACRO_H_ + +//-------------------------------------------------------------------------------------- +#include + +//-------------------------------------------------------------------------------------- +// See ModelAPI_Feature functions +#define FN_Boolean boolean +#define FN_DocRef document +#define FN_Double real +#define FN_Integer integer +#define FN_RefAttr refattr +#define FN_Reference reference +#define FN_RefList reflist +#define FN_Selection selection +#define FN_SelectionList selectionList +#define FN_String string + +//-------------------------------------------------------------------------------------- +#define VAR_NAME(NAME) my##NAME + +//-------------------------------------------------------------------------------------- +// Used in INTERFACE_N for create variable and getter +#define DEFINE_ATTRIBUTE(NAME, TYPE, COMMENT) \ + COMMENT \ + std::shared_ptr NAME() const { return VAR_NAME(NAME); } \ + protected: \ + std::shared_ptr VAR_NAME(NAME); \ + public: + +//-------------------------------------------------------------------------------------- +// Used in INTERFACE_N inside START_INIT/END_INIT for set variable with attribute received from feature +#define SET_ATTRIBUTE(NAME, TYPE, ATT_NAME) \ + VAR_NAME(NAME) = feature()->FN_##TYPE(ATT_NAME); \ + if (!VAR_NAME(NAME)) \ + return false; + +//-------------------------------------------------------------------------------------- +#define INTERFACE_COMMON(KIND) \ + static std::string ID() { return KIND; } + +//-------------------------------------------------------------------------------------- +#define START_INIT() \ + bool initialize() { \ + if (!feature()) { \ + throwException(ID() + " exception: The feature is NULL."); \ + return false; \ + } \ + if (getKind() != ID()) { \ + throwException(ID() + " exception: Wrong feature kind."); \ + return false; \ + } + +//-------------------------------------------------------------------------------------- +#define END_INIT() \ + return true; \ + } + + +//-------------------------------------------------------------------------------------- +#define INTERFACE_2(KIND, \ + N_0, AN_0, T_0, C_0, \ + N_1, AN_1, T_1, C_1) \ + public: \ + INTERFACE_COMMON(KIND) \ + DEFINE_ATTRIBUTE(N_0, T_0, C_0) \ + DEFINE_ATTRIBUTE(N_1, T_1, C_1) \ + protected: \ + START_INIT() \ + SET_ATTRIBUTE(N_0, T_0, AN_0) \ + SET_ATTRIBUTE(N_1, T_1, AN_1) \ + END_INIT() \ + public: + +//-------------------------------------------------------------------------------------- +#define INTERFACE_3(KIND, \ + N_0, AN_0, T_0, C_0, \ + N_1, AN_1, T_1, C_1, \ + N_2, AN_2, T_2, C_2) \ + public: \ + INTERFACE_COMMON(KIND) \ + DEFINE_ATTRIBUTE(N_0, T_0, C_0) \ + DEFINE_ATTRIBUTE(N_1, T_1, C_1) \ + DEFINE_ATTRIBUTE(N_2, T_2, C_2) \ + protected: \ + START_INIT() \ + SET_ATTRIBUTE(N_0, T_0, AN_0) \ + SET_ATTRIBUTE(N_1, T_1, AN_1) \ + SET_ATTRIBUTE(N_2, T_2, AN_2) \ + END_INIT() \ + public: + +//-------------------------------------------------------------------------------------- +#define INTERFACE_4(KIND, \ + N_0, AN_0, T_0, C_0, \ + N_1, AN_1, T_1, C_1, \ + N_2, AN_2, T_2, C_2, \ + N_3, AN_3, T_3, C_3) \ + public: \ + INTERFACE_COMMON(KIND) \ + DEFINE_ATTRIBUTE(N_0, T_0, C_0) \ + DEFINE_ATTRIBUTE(N_1, T_1, C_1) \ + DEFINE_ATTRIBUTE(N_2, T_2, C_2) \ + DEFINE_ATTRIBUTE(N_3, T_3, C_3) \ + protected: \ + START_INIT() \ + SET_ATTRIBUTE(N_0, T_0, AN_0) \ + SET_ATTRIBUTE(N_1, T_1, AN_1) \ + SET_ATTRIBUTE(N_2, T_2, AN_2) \ + SET_ATTRIBUTE(N_3, T_3, AN_3) \ + END_INIT() \ + public: + +//-------------------------------------------------------------------------------------- +#define INTERFACE_5(KIND, \ + N_0, AN_0, T_0, C_0, \ + N_1, AN_1, T_1, C_1, \ + N_2, AN_2, T_2, C_2, \ + N_3, AN_3, T_3, C_3, \ + N_4, AN_4, T_4, C_4) \ + public: \ + INTERFACE_COMMON(KIND) \ + DEFINE_ATTRIBUTE(N_0, T_0, C_0) \ + DEFINE_ATTRIBUTE(N_1, T_1, C_1) \ + DEFINE_ATTRIBUTE(N_2, T_2, C_2) \ + DEFINE_ATTRIBUTE(N_3, T_3, C_3) \ + DEFINE_ATTRIBUTE(N_4, T_4, C_4) \ + protected: \ + START_INIT() \ + SET_ATTRIBUTE(N_0, T_0, AN_0) \ + SET_ATTRIBUTE(N_1, T_1, AN_1) \ + SET_ATTRIBUTE(N_2, T_2, AN_2) \ + SET_ATTRIBUTE(N_3, T_3, AN_3) \ + SET_ATTRIBUTE(N_4, T_4, AN_4) \ + END_INIT() \ + public: + +//-------------------------------------------------------------------------------------- +#define INTERFACE_6(KIND, \ + N_0, AN_0, T_0, C_0, \ + N_1, AN_1, T_1, C_1, \ + N_2, AN_2, T_2, C_2, \ + N_3, AN_3, T_3, C_3, \ + N_4, AN_4, T_4, C_4, \ + N_5, AN_5, T_5, C_5) \ + public: \ + INTERFACE_COMMON(KIND) \ + DEFINE_ATTRIBUTE(N_0, T_0, C_0) \ + DEFINE_ATTRIBUTE(N_1, T_1, C_1) \ + DEFINE_ATTRIBUTE(N_2, T_2, C_2) \ + DEFINE_ATTRIBUTE(N_3, T_3, C_3) \ + DEFINE_ATTRIBUTE(N_4, T_4, C_4) \ + DEFINE_ATTRIBUTE(N_5, T_5, C_5) \ + protected: \ + START_INIT() \ + SET_ATTRIBUTE(N_0, T_0, AN_0) \ + SET_ATTRIBUTE(N_1, T_1, AN_1) \ + SET_ATTRIBUTE(N_2, T_2, AN_2) \ + SET_ATTRIBUTE(N_3, T_3, AN_3) \ + SET_ATTRIBUTE(N_4, T_4, AN_4) \ + SET_ATTRIBUTE(N_5, T_5, AN_5) \ + END_INIT() \ + public: + +//-------------------------------------------------------------------------------------- +#define INTERFACE_7(KIND, \ + N_0, AN_0, T_0, C_0, \ + N_1, AN_1, T_1, C_1, \ + N_2, AN_2, T_2, C_2, \ + N_3, AN_3, T_3, C_3, \ + N_4, AN_4, T_4, C_4, \ + N_5, AN_5, T_5, C_5, \ + N_6, AN_6, T_6, C_6) \ + public: \ + INTERFACE_COMMON(KIND) \ + DEFINE_ATTRIBUTE(N_0, T_0, C_0) \ + DEFINE_ATTRIBUTE(N_1, T_1, C_1) \ + DEFINE_ATTRIBUTE(N_2, T_2, C_2) \ + DEFINE_ATTRIBUTE(N_3, T_3, C_3) \ + DEFINE_ATTRIBUTE(N_4, T_4, C_4) \ + DEFINE_ATTRIBUTE(N_5, T_5, C_5) \ + DEFINE_ATTRIBUTE(N_6, T_6, C_6) \ + protected: \ + START_INIT() \ + SET_ATTRIBUTE(N_0, T_0, AN_0) \ + SET_ATTRIBUTE(N_1, T_1, AN_1) \ + SET_ATTRIBUTE(N_2, T_2, AN_2) \ + SET_ATTRIBUTE(N_3, T_3, AN_3) \ + SET_ATTRIBUTE(N_4, T_4, AN_4) \ + SET_ATTRIBUTE(N_5, T_5, AN_5) \ + SET_ATTRIBUTE(N_6, T_6, AN_6) \ + END_INIT() \ + public: + +//-------------------------------------------------------------------------------------- +#define INTERFACE_8(KIND, \ + N_0, AN_0, T_0, C_0, \ + N_1, AN_1, T_1, C_1, \ + N_2, AN_2, T_2, C_2, \ + N_3, AN_3, T_3, C_3, \ + N_4, AN_4, T_4, C_4, \ + N_5, AN_5, T_5, C_5, \ + N_6, AN_6, T_6, C_6, \ + N_7, AN_7, T_7, C_7) \ + public: \ + INTERFACE_COMMON(KIND) \ + DEFINE_ATTRIBUTE(N_0, T_0, C_0) \ + DEFINE_ATTRIBUTE(N_1, T_1, C_1) \ + DEFINE_ATTRIBUTE(N_2, T_2, C_2) \ + DEFINE_ATTRIBUTE(N_3, T_3, C_3) \ + DEFINE_ATTRIBUTE(N_4, T_4, C_4) \ + DEFINE_ATTRIBUTE(N_5, T_5, C_5) \ + DEFINE_ATTRIBUTE(N_6, T_6, C_6) \ + DEFINE_ATTRIBUTE(N_7, T_7, C_7) \ + protected: \ + START_INIT() \ + SET_ATTRIBUTE(N_0, T_0, AN_0) \ + SET_ATTRIBUTE(N_1, T_1, AN_1) \ + SET_ATTRIBUTE(N_2, T_2, AN_2) \ + SET_ATTRIBUTE(N_3, T_3, AN_3) \ + SET_ATTRIBUTE(N_4, T_4, AN_4) \ + SET_ATTRIBUTE(N_5, T_5, AN_5) \ + SET_ATTRIBUTE(N_6, T_6, AN_6) \ + SET_ATTRIBUTE(N_7, T_7, AN_7) \ + END_INIT() \ + public: + +//-------------------------------------------------------------------------------------- +#define INTERFACE_9(KIND, \ + N_0, AN_0, T_0, C_0, \ + N_1, AN_1, T_1, C_1, \ + N_2, AN_2, T_2, C_2, \ + N_3, AN_3, T_3, C_3, \ + N_4, AN_4, T_4, C_4, \ + N_5, AN_5, T_5, C_5, \ + N_6, AN_6, T_6, C_6, \ + N_7, AN_7, T_7, C_7, \ + N_8, AN_8, T_8, C_8) \ + public: \ + INTERFACE_COMMON(KIND) \ + DEFINE_ATTRIBUTE(N_0, T_0, C_0) \ + DEFINE_ATTRIBUTE(N_1, T_1, C_1) \ + DEFINE_ATTRIBUTE(N_2, T_2, C_2) \ + DEFINE_ATTRIBUTE(N_3, T_3, C_3) \ + DEFINE_ATTRIBUTE(N_4, T_4, C_4) \ + DEFINE_ATTRIBUTE(N_5, T_5, C_5) \ + DEFINE_ATTRIBUTE(N_6, T_6, C_6) \ + DEFINE_ATTRIBUTE(N_7, T_7, C_7) \ + DEFINE_ATTRIBUTE(N_8, T_8, C_8) \ + protected: \ + START_INIT() \ + SET_ATTRIBUTE(N_0, T_0, AN_0) \ + SET_ATTRIBUTE(N_1, T_1, AN_1) \ + SET_ATTRIBUTE(N_2, T_2, AN_2) \ + SET_ATTRIBUTE(N_3, T_3, AN_3) \ + SET_ATTRIBUTE(N_4, T_4, AN_4) \ + SET_ATTRIBUTE(N_5, T_5, AN_5) \ + SET_ATTRIBUTE(N_6, T_6, AN_6) \ + SET_ATTRIBUTE(N_7, T_7, AN_7) \ + SET_ATTRIBUTE(N_8, T_8, AN_8) \ + END_INIT() \ + public: + +//-------------------------------------------------------------------------------------- +#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_MACRO_H_ */ diff --git a/src/ModelHighAPI/ModelHighAPI_swig.h b/src/ModelHighAPI/ModelHighAPI_swig.h index 63b3b1b43..eba21331f 100644 --- a/src/ModelHighAPI/ModelHighAPI_swig.h +++ b/src/ModelHighAPI/ModelHighAPI_swig.h @@ -11,5 +11,6 @@ #include "ModelHighAPI_Double.h" #include "ModelHighAPI_Interface.h" + #include "ModelHighAPI_Macro.h" #endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_SWIG_H_ */ diff --git a/src/ModelHighAPI/Test/TestDouble.cpp b/src/ModelHighAPI/Test/TestDouble.cpp index 23c47a5d3..546db2d73 100644 --- a/src/ModelHighAPI/Test/TestDouble.cpp +++ b/src/ModelHighAPI/Test/TestDouble.cpp @@ -35,9 +35,9 @@ TEST_F(HighModelAPI_Double_Test, Default) { } TEST_F(HighModelAPI_Double_Test, Double) { - ModelHighAPI_Double aValue(100); + ModelHighAPI_Double aValue(100.5); - EXPECT_CALL(aMockAttributeDouble, setValue(100.)); + EXPECT_CALL(aMockAttributeDouble, setValue(100.5)); aValue.fillAttribute(anAttributeDouble); }