From malte.dreschert at gmail.com Sat Jan 15 19:46:48 2022 From: malte.dreschert at gmail.com (Malte Dreschert) Date: Sun, 16 Jan 2022 01:46:48 +0100 Subject: [C++-sig] wrap union types with boost.python Message-ID: Hello, I discovered boost.python not long ago and I really like how simple I can wrap my code. I stumbled upon the following struct and don't know how to wrap it. Help is greatly appreciated. struct someStruct { union { float a; float b; }; } Thank you very much, Cheers, Malte -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan at seefeld.name Sun Jan 16 10:18:25 2022 From: stefan at seefeld.name (Stefan Seefeld) Date: Sun, 16 Jan 2022 10:18:25 -0500 Subject: [C++-sig] wrap union types with boost.python In-Reply-To: References: Message-ID: <2322a32d-5ba3-b7db-98fd-7d16c115fbcd@seefeld.name> Hi Malte, the first step is for you to decide what semantics you want `someStruct` to carry, which would then translate into an API. This is also a prerequisite for using this in pure C++, i.e. without any Python bindings. It just becomes more obvious if you want to think about accessing this in a pythonic way. So, can you rephrase your question by describing `someStruct` in terms of behaviour rather than structure, i.e. in an "object-oriented" way ? Stefan -- ...ich hab' noch einen Koffer in Berlin... -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: .signature.png Type: image/png Size: 2754 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan.vcf Type: text/vcard Size: 4 bytes Desc: not available URL: From malte.dreschert at gmail.com Sun Jan 16 12:29:42 2022 From: malte.dreschert at gmail.com (Malte Dreschert) Date: Sun, 16 Jan 2022 18:29:42 +0100 Subject: [C++-sig] wrap union types with boost.python In-Reply-To: <2322a32d-5ba3-b7db-98fd-7d16c115fbcd@seefeld.name> References: <2322a32d-5ba3-b7db-98fd-7d16c115fbcd@seefeld.name> Message-ID: Hi Stefan, thanks for answering and a greetings from northern Germany to Berlin :) the struct is meant to hold color values (three floats) but the color space can be different. It contains three of these unions and one enum value that contains the information which color space was used when the values were written. The floats are either rgb or hsv. The library is for reading a binary file and I only have these structs and some methods I need to wrap, that means I only need to read the values. I guess I would first check the color space and then interpret the three values accordingly. Does that help? I don't want to post the code directly because it is in house code. Thank you very much, Cheers, Malte On Sun, Jan 16, 2022 at 4:18 PM Stefan Seefeld wrote: > Hi Malte, > > the first step is for you to decide what semantics you want `someStruct` > to carry, which would then translate into an API. This is also a > prerequisite for using this in pure C++, i.e. without any Python bindings. > It just becomes more obvious if you want to think about accessing this in a > pythonic way. > > So, can you rephrase your question by describing `someStruct` in terms of > behaviour rather than structure, i.e. in an "object-oriented" way ? > > [image: Stefan] > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: .signature.png Type: image/png Size: 2754 bytes Desc: not available URL: From stefan at seefeld.name Sun Jan 16 12:46:54 2022 From: stefan at seefeld.name (Stefan Seefeld) Date: Sun, 16 Jan 2022 12:46:54 -0500 Subject: [C++-sig] wrap union types with boost.python In-Reply-To: References: <2322a32d-5ba3-b7db-98fd-7d16c115fbcd@seefeld.name> Message-ID: On 2022-01-16 12:29, Malte Dreschert wrote: > Hi Stefan, > > thanks for answering and a greetings from northern Germany to Berlin :) > > the struct is meant to hold color values (three floats) but the color > space can be different. > It contains three of these unions and one enum value that contains the > information which color space was used when the values were written. > The floats are either rgb or hsv. > > The library is for reading a binary file and I only have these structs > and some methods I need to wrap, that means I only need to read the > values. > I guess I would first check the color space and then interpret the > three values accordingly. Right, and I assume you already have a C++ API to access that struct, even if it isn't in terms of member functions. As far as the raw data type and its binary representation is concerned, there is nothing special here, i.e. you could wrap it in a Python object as-is. But what you likely want is a set of (member) functions to access the values, and that is very likely mapping to your C++ API more than mapping to the struct directly. For example, let's assume you have: ``` struct someStruct {/*...*/}; float get_value(someStruct const &); void set_value(someStruct &, float); ``` you may decide to map `get_value` and `set_value` to direct methods: ``` class_ s("someStruct"); s.def("get_value", get_value); s.def("set_value", set_value); ``` (Notice how the freestanding functions lend themselves naturally to become methods as their first argument is the equivalent of the otherwise implied "this" pointer...) Or you may want to map both directly to a property: ``` class_ s("someStruct"); s.add_property("value", get_value, set_value); ``` Either way, there is nothing special in this wrapping concerning the fact that your struct contains a union. Rather, it's your C++ API that will have to deal with that. Regards (from Montreal ;-)), Stefan -- ...ich hab' noch einen Koffer in Berlin... -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: .signature.png Type: image/png Size: 2754 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stefan.vcf Type: text/vcard Size: 4 bytes Desc: not available URL: From stefan.seefeld at gmail.com Sun Jan 16 12:41:23 2022 From: stefan.seefeld at gmail.com (Stefan Seefeld) Date: Sun, 16 Jan 2022 12:41:23 -0500 Subject: [C++-sig] wrap union types with boost.python In-Reply-To: References: <2322a32d-5ba3-b7db-98fd-7d16c115fbcd@seefeld.name> Message-ID: <1885da51-581c-fea3-37ea-343ef37e256f@gmail.com> On 2022-01-16 12:29, Malte Dreschert wrote: > Hi Stefan, > > thanks for answering and a greetings from northern Germany to Berlin :) > > the struct is meant to hold color values (three floats) but the color > space can be different. > It contains three of these unions and one enum value that contains the > information which color space was used when the values were written. > The floats are either rgb or hsv. > > The library is for reading a binary file and I only have these structs > and some methods I need to wrap, that means I only need to read the > values. > I guess I would first check the color space and then interpret the > three values accordingly. Right, and I assume you already have a C++ API to access that struct, even if it isn't in terms of member functions. As far as the raw data type and its binary representation is concerned, there is nothing special here, i.e. you could wrap it in a Python object as-is. But what you likely want is a set of (member) functions to access the values, and that is very likely mapping to your C++ API more than mapping to the struct directly. For example, let's assume you have: ``` struct someStruct {/*...*/}; float get_value(someStruct const &); void set_value(someStruct &, float); ``` you may decide to map `get_value` and `set_value` to direct methods: ``` class_ s("someStruct"); s.def("get_value", get_value); s.def("set_value", set_value); ``` (Notice how > > Does that help? I don't want to post the code directly because it is > in house code. > > Thank you very much, > > Cheers, > > Malte > > > On Sun, Jan 16, 2022 at 4:18 PM Stefan Seefeld > wrote: > > Hi Malte, > > the first step is for you to decide what semantics you want > `someStruct` to carry, which would then translate into an API. > This is also a prerequisite for using this in pure C++, i.e. > without any Python bindings. It just becomes more obvious if you > want to think about accessing this in a pythonic way. > > So, can you rephrase your question by describing `someStruct` in > terms of behaviour rather than structure, i.e. in an > "object-oriented" way ? > > Stefan > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: .signature.png Type: image/png Size: 2754 bytes Desc: not available URL: From mayurkedari16 at gmail.com Thu Jan 20 13:16:41 2022 From: mayurkedari16 at gmail.com (Mayuresh Kedari) Date: Thu, 20 Jan 2022 23:46:41 +0530 Subject: [C++-sig] Boost.Python Installation with all other Boost libaries Message-ID: Hello, I?m getting errors & didn?t find the correct solution. Error ? *C:\boost\boost_1_78_0\boost/python/detail/wrap_python.hpp(57): fatal error C1083: Cannot open include file: 'pyconfig.h': No such file or directory* Why this error is occurring? And also I want to know, how should I escape the whitespace character while specifying the path of Python in the project-config.jam file (On windows..) It would be great if you provide the whole tutorial to install the Boost.Python from scratch along with the other boost libraries on Windows with an msvc toolset. *Thanks & Regards,* *Mayuresh Kedari* -------------- next part -------------- An HTML attachment was scrubbed... URL: