I have probably trivial problem. I'm trying to use GEOS library. I have my functions using GEOS library in my own library. And I want to use this library in my QGIS plugin writen in C++. The problem is, that functions in my library work with geos::geom::Geometry, but in QGIS plugin, there is GEOSGeometry. I thought that it is the same thing, but it probably isn't.
Can anyone explain me the difference between these two and give me an advice, how to convert them to each other or tell me what I'm doing wrong? Thanks.
GEOSGeometry is a typedef for the structure used in the C (not C++) API. It is stated on the official documentation that the use of the C API is preferred to the C++ API as it may be more stable (in terms of future changes).
I'm not sure if you can simply cast the structures (I'd advise against it). I suggest you use the C API instead of the C++ API.
No, you can not simply cast between GEOS C API type GEOSGeometry and C++ API types from hierarchy rooted at geos::geom::Geometry class.
You can, however, convert your geometries using WKB as an interchange format, between the C API and the C++ API objects.
Related
I'm really sorry if my question might be too noob or something else. But, I find my self a little bit confusing between some commands found in OpenCV.
After browsing the OpenCV documentation , I found that there are commands like cvMemStorage and cv::MemStorage, cvMat and cv::Mat, cvSeq and cv::Seq, cvNormalBayesClassifier and cv::NormalBayesClassifier.
So, what are the differences between those commands?
Are they just a different style of commands between the C and C++ style?
So why don't they (OpenCV team) just use one style in most of the c and c++ world?
Any help and comments would be really appreciated.
Thank you
The convention seems to be that cvSomething is a C type or function, and cv::Something is the corresponding C++ version. In C++, cv is a namespace.
OpenCV maintains both C and a C++ interfaces, which is the reason you get both variants (there are also python bindings, which can make the all-in-one documentation confusing).
The core library of OpenCV version 2.x is written in C++. The coding convention is to have everything in the namespace cv. (See here or here).
The old API (version 1.x) was a C API. The convention was to add the prefix cv.
The old 1.x API is still exposed to client code. Usually, you will not need it. (As stated in the OpenCV documentation for Dynamic structure (since you referenced the cvCreateMemStorage), "if you use the new C++, Python, Java etc interface, you will unlikely need this functionality. Use std::vector or other high-level data structures.")
I'm a Python guy building a Linux-based web service for a client who wants me to interface with a small C++ library that they're currently using with a bunch of Windows based VB applications.
They have assured me that the library is fairly simple (as far as they go I guess), and that they just need to know how best to compile and deliver it to me so that I can use it in Python under Linux.
I've read a bit about the ctypes library and other options (SWIG, etc), but for some reason I haven't really been able to wrap my head around the concept and still don't know how to tell them what I need.
I'm pretty sure having them re-write it with Python.h, etc is out, so I'm hoping there's a way I can simply have them compile it on Linux as a .so and just import it into Python. Is such a thing possible? How does one accomplish this?
No, such a thing is not possible.
Either they have to provide Python bindings, or you do. Either one of you can do this in any of the following ways:
Using <Python.h> directly to write a C extension module.
Using boost::python to make writing the extension module much easier (especially when they're using C++ rather than C).
Using SWIG, SIP, or similar tools to partly automate the writing of the extension module.
Using Cython to write the extension module in a Python-like language, instead of in C or C++.
Using ctypes from within Python.
For very simple cases (especially if they're actually exporting a C interface to their C++ code), ctypes probably is the easiest solution. Otherwise, I'd suggest looking at Cython first. But at any rate, you're going to have to wrap your head around one of the solutions—or convince them to do it instead.
Due to complexities of the C++ ABI (such as name mangling), it's generally difficult and platform-specific to load a C++ library directly from Python using ctypes.
I'd recommend you either create a simple C API which can be easily wrapped with ctypes, or use SWIG to generate wrapper types and a proper extension module for Python.
With native c++, I mean, not managed c++, not cli, not any special things from microsoft, I can:
1) get high performance
2) use existing c++ code library and engine
3) write cross platform code (for example, for ios and android)
it needn't be fully native c++, I can use managed code to do the ui things, like object-c in ios and java in android, but beside interface, can I use native c++ code?
I suggest you have a look at the presentation here: Using the Windows Runtime from C++ and especially at the comments from Herb Sutter. I quote:
Please answer this question: If I decide to write C++ GUI application
in Metro style am I forced to use all these proprietary ref, sealed,
^, Platform::String^ extensions for GUI components or not?
#Tomas: No, you are not forced to use them. We are providing two
supported ways:
1) These language extensions (C++/CX).
2) A C++ template library (WRL), see
Windows Kits\8.0\Include\winrt\wrl as Yannick mentioned. WRL is a C++
library-based solution sort of along the lines of ATL, which offers
what I think you're looking for -- template wrapper/convenience
classes and explicit smart pointers and such.
Yes you absolutely can, real native C++ is fully supported.
You do however mostly have to use the new WinRT libraries to do an user interface or system calls and although they are native code and fully callable from C++ directly the interface to them makes it very painful indeed to do so, as everything is a reference counted COM object and in addition it's not so easy to create instances of them as just calling "new" so you have to write a lot of ugly code to do so.
As the earlier answer said, microsoft provide two ways to help with this. One is via language extensions to c++ and the other is a c++ template library. Personally I consider both to be rather ugly for doing something as simple as calling an API but that's just me :)
But to answer your question, it's completely possible to write your application in real native c++. You won't need to use managed code at all for anything. But you'll probably want to use either the language extensions or the template library to make calling the API more easy.
Personally I'm hoping someone writes a wrapper for WinRT that exposes the most necessary functionality as a more usable c++ native library and then everyone can just use that from c++ instead...
I'm in the process of writing a C interface to a C++ library, and I'm looking for some high-quality examples (or best practices).
So far this one seems pretty promising: http://czmq.zeromq.org/manual:czmq
Any other suggestions?
You could look into the Parma Polyhedra Library as an example of excellent C interface to a well written C++ library. PPL is a free GPL-ed software, notably used inside the GCC compiler.
Another high quality example is the Open Dynamics Engine. It has a C++ backend and a C frontend. Everything is C linkable.
C++ example
C example
If your C++ library is written as COM on Windows. There are tools to automatically generate the C interface for it.
I can suggest FTGL which is a C++ library providing a C interface. Here are two sample programs that achieve exactly the same thing:
C++ version
C version
Note also that FTGL uses the pImpl paradigm in order to achieve binary compatibility across versions. See here why it's good.
Disclaimer: I'm an FTGL contributor.
libGLU (OpenGL Utility Library) is partially written in C++: http://cgit.freedesktop.org/mesa/mesa/tree/src/glu
libzmq is a kind of weird case since the low-level C API was originally meant to look like POSIX sockets, and absolutely not object-oriented (we made it more consistent and organized over time). Meanwhile the actual library is in C++.
The C++-to-C interface is in libzmq/src/zmq.cpp, and consists of a bunch of simple C functions that call the 'real' C++ code.
CZMQ on the other hand aims for something more classy, providing a simple class model with constructors, destructors, containers, private properties, etc. Nothing radical but does turn C into a much more elegant language.
I'm not sure how well the CZMQ class approach would map to a C++ API unless that API was explicitly designed to be mapped.
Disclaimer: I'm the author of most of CZMQ.
I am using the Ubuntu OS to create a library written in c++.
I've created an shared library and now I need to document my work.
I would like to know what is the smartest and fastest way to do it?
If you're looking for API documentation of your classes / types, you might want to look into Doxygen.