From ea509ff38924d5e35a4d8296ab46e2d406ed3a0e Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Thu, 8 Sep 2022 10:37:29 +0200 Subject: [PATCH] Improved SDF documentation for example1 Custom datatype now supported --- SDFTools/documentation/example1.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/SDFTools/documentation/example1.md b/SDFTools/documentation/example1.md index 2f493dd1..15014105 100755 --- a/SDFTools/documentation/example1.md +++ b/SDFTools/documentation/example1.md @@ -99,7 +99,32 @@ Once it is done, we can start creating instance of those nodes. We will also nee floatType=CType(F32) ``` -Now, we can define the nodes for the graph: +It is also possible to use a custom datatype, the `example8` is giving an example: + +```python +complexType=CStructType("complex","MyComplex",8) +``` + +This is defining a new datatype that is mapped to the type `complex` in C/C++ and the class `MyComplex` in Python. The last argument is the size in bytes of the struct in C. + +The type complex may be defined with: + +```c +typedef struct { + float re; + float im; +} complex; +``` + +**Note that:** + +- The value **must have** value semantic in C/C++. So avoid classes +- In Python, the classes have reference semantic which implies some constraints: + - You should never modify an object from the read buffer + - You should change the field of an object in the write buffer + - If you need a new object : copy or create a new object. Never use an object from the read buffer as it is if you intend to customize it + +Once a datatype has been defined and chosen, we can define the nodes for the graph: ```python src=Source("source",floatType,5)