Skip to content

Commit ca158c3

Browse files
committed
Add compiler define if SIMPL_ENABLE_PYTHON is turned on.
Update clang-format to NOT sort the includes. Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
1 parent 7f1a7e8 commit ca158c3

3 files changed

Lines changed: 182 additions & 2 deletions

File tree

.clang-format

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ ConstructorInitializerIndentWidth: 0
7272
# PenaltyReturnTypeOnItsOwnLine: 60
7373
PointerAlignment: Left
7474
# ReflowComments: true
75-
# SortIncludes: true
75+
SortIncludes: false
7676
# SpaceAfterCStyleCast: false
7777
# SpaceBeforeAssignmentOperators: true
7878
SpaceBeforeParens: Never
@@ -83,7 +83,7 @@ SpaceBeforeParens: Never
8383
# SpacesInCStyleCastParentheses: false
8484
# SpacesInParentheses: false
8585
# SpacesInSquareBrackets: false
86-
# Standard: Cpp11
86+
Standard: Cpp11
8787
TabWidth: 2
8888
UseTab: Never
8989
...
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/* ============================================================================
2+
* Copyright (c) 2019 BlueQuartz Software, LLC
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* Redistributions in binary form must reproduce the above copyright notice, this
12+
* list of conditions and the following disclaimer in the documentation and/or
13+
* other materials provided with the distribution.
14+
*
15+
* Neither the names of any of the BlueQuartz Software contributors
16+
* may be used to endorse or promote products derived from this software without
17+
* specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
28+
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*
30+
*
31+
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
32+
#pragma once
33+
34+
/* *****************************************************************************
35+
* *****************************************************************************
36+
* *****************************************************************************
37+
*
38+
* PyBind11 Macros that we can use to explicitly define which setters & getters
39+
* will be exposed to the Python library
40+
*/
41+
42+
/**
43+
* @brief PYB11_CREATE_BINDINGS This macro lets the wrapper know that we want to
44+
* wrap this class with Python bindings. It should only take a single argument
45+
* which is the name of the class. If this line is commented out using the standard
46+
* C++ style of single line comment then <b>NO WRAPPING</b> will be performed
47+
* on the class.
48+
* @code
49+
* PYB11_CREATE_BINDINGS(AbstractFilter)
50+
* @endcode
51+
*/
52+
#define PYB11_CREATE_BINDINGS(...)
53+
54+
/**
55+
* @brief PYB11_NO_BINDINGS This macro will ensure that the class is NOT wrapped
56+
* with python bindings. Only a single argument which is the name of the class
57+
* should be used.
58+
* @code
59+
* PYB11_NO_BINDINGS(AbstractFilter)
60+
* @endcode
61+
*/
62+
#define PYB11_NO_BINDINGS(...)
63+
64+
/**
65+
* @brief PYB11_STATIC_CREATION This macro will wrap the "static New()" function
66+
* that most of the SIMPL classes implement as a way to instantiate the class in
67+
* addition to other static methods that are used for a class. The argument types
68+
* to the static method should be listed <b>WITHOUT</b> any spaces for each argument.
69+
*
70+
* @code
71+
* PYB11_STATIC_CREATION(Create ARGS std::vector<std::vector<double>> std::list<std::string> std::list<std::string>)
72+
* @endcode
73+
*
74+
* If there are several static creation methods that overload each other then the following form can be used:
75+
*
76+
* @code
77+
* PYB11_STATIC_CREATION(New OVERLOAD QString)
78+
* PYB11_STATIC_CREATION(New OVERLOAD DataArrayPath)
79+
* @endcode
80+
*/
81+
#define PYB11_STATIC_CREATION(...)
82+
83+
/**
84+
* @brief PYB11_CREATION This macro is used for non-static constructors that need
85+
* to be wrapped. The argument types need to be lists where each argument cannot
86+
* containe spaces. Use a typedef if needed, but using a typedef also has its
87+
* own issues. @see DataArrayPath for an example.
88+
*
89+
* @code
90+
* PYB11_CREATION(ARGS QString QString QString)
91+
* @endcode
92+
*/
93+
#define PYB11_CREATION(...)
94+
95+
/**
96+
* @brief PYB11_ENUMERATION This macro will allow a class enumeration to be wrapped
97+
* in Python an available to the Python side. @see IGeoemtry for an example. The
98+
* macro should only take a single argument.
99+
* @code
100+
* PYB11_ENUMERATION(Type)
101+
* PYB11_ENUMERATION(VtkCellType)
102+
* @endcode
103+
*/
104+
#define PYB11_ENUMERATION(...)
105+
106+
/**
107+
* @brief PYB11_PROPERTY This macro is used to wrap a single class instance property
108+
* that is typically used as an input parameter for a filter. This macro should
109+
* <b>NOT</b> be used for just wrapping instance methods. Use the PYB11_METHOD for
110+
* that. @see AbstractFilter. There are number of arguments depending on if the
111+
* property is a read-only or read-write variable. At least 4 arguments to the
112+
* macro are required when the property is read only.
113+
* @code
114+
PYB11_PROPERTY(QString NameOfClass READ getNameOfClass)
115+
* @endcode
116+
* and 6 arguments when the property is read-write.
117+
* @code
118+
* PYB11_PROPERTY(bool Cancel READ getCancel WRITE setCancel)
119+
* @endcode
120+
*
121+
* and if there are additional overloads of the Getter that returns a const reference such as
122+
* @code
123+
* const QString& getFoo() const;
124+
* @endcode
125+
*
126+
* then you would add on the CONST_GET_OVERLOAD as the last argument to the macro.
127+
*/
128+
#define PYB11_PROPERTY(...)
129+
130+
/**
131+
* @brief This macro is used to expose a method to the Python bindings. The signature
132+
* of the macro should be the following:
133+
* PYB11_METHOD( _return_type_ _name_of_method_ [ARGS|OVERLOAD] ....)
134+
* If the ARGS command is used then simply list the variable names for each argument.
135+
* For example if you have a method "void getFoo(const QString &foo)" that you want
136+
* to expose:
137+
* @code
138+
* PYB11_METHOD(void getFoo ARGS Foo)
139+
* @endcode
140+
*
141+
* If your method does not take any arguments then leave out the ARGS keyword.
142+
*
143+
* If you are have overloads of the method that you want to expose to Python then
144+
* the "OVERLOAD" version of the method should be used. Again, say we have two
145+
* methods that we want to expose.
146+
* @code
147+
* void setPath(const QString &name)
148+
* void setPath(const DataArrayPath &path)
149+
* @endcode
150+
*
151+
* then we would use the following set of invocations:
152+
* @code
153+
* PYB11_METHOD(void setPath OVERLOAD const.QString.&,Name)
154+
* PYB11_METHOD(void setPath OVERLOAD const.DataArrayPath.&,Path)
155+
* @endcode
156+
* Note that in order to get the (const QString &) correct we used the '.' charater
157+
* to declare the type. This is required as the macro is split using spaces. When
158+
* then end code is generated the '.' characters will be replaced with spaces.
159+
*
160+
* If the method that is being wrapped in python is a 'const' method then the last argument should be CONST_METHOD. In
161+
* the example below there is a pair of overloaded methods that are both 'const'.
162+
*
163+
* @code
164+
* PYB11_METHOD(bool doesDataContainerExist OVERLOAD const.QString.&,Name CONST_METHOD)
165+
* PYB11_METHOD(bool doesDataContainerExist OVERLOAD const.DataArrayPath.&,Path CONST_METHOD)
166+
* @endcode
167+
*/
168+
#define PYB11_METHOD(...)
169+
170+
// End of PYBIND11 Macro Definitions
171+
/* *****************************************************************************
172+
* *****************************************************************************
173+
* *****************************************************************************
174+
*/

Source/SIMPLib/SIMPLibConfiguration.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
/* define to 1 if we are enabling NTFS file checking */
4040
#cmakedefine SIMPL_NTFS_FILE_CHECK @SIMPL_NTFS_FILE_CHECK@
4141

42+
/* define to 1 if we are enabling Python Wrapping through Pybind11 */
43+
#cmakedefine SIMPL_ENABLE_PYTHON @SIMPL_ENABLE_PYTHON@
4244

4345
/* ****************************************************************************
4446
* These define what source groups are being compiled
@@ -78,6 +80,10 @@
7880
/* Include the DLL export preprocessor defines */
7981
#include "SIMPLib/Common/SIMPLibDLLExport.h"
8082

83+
#ifdef SIMPL_ENABLE_PYTHON
84+
#include "SIMPLib/Common/SIMPLPythonMacros.h"
85+
#endif
86+
8187
/* We are going to disable some warnings just to get a grip on all the warnings that get produced
8288
* during an MSVC build */
8389
#cmakedefine SIMPLib_DISABLE_MSVC_WARNINGS @SIMPLib_DISABLE_MSVC_WARNINGS@

0 commit comments

Comments
 (0)