c++

Can a PyQt program consume a DBus interface that exposes custom C++ types (marhsalled via Qt's MetaType system)? If so, how?

I have a Qt/C++ application that exposes some custom C++ classes via DBus methods (by registering them as MetaTypes, and using annotations in the xml), and I want my PyQt program to consume these methods. The problem I see is that the exposed types are C++ classes, not python, so how can I make python aware of these classes? ...

Prefix/Postfix increment operators

I'm wanting to make sure I understand pass-by-value vs pass-by-reference properly. In particular, I'm looking at the prefix/postfix versions of the increment ++ operator for an object. Let's suppose we have the following class X: class X{ private: int i; public: X(){i=0;} X& operator ++ (){ ++i; return *this; } //prefix increment...

What is an easy way to test whether any process of a given id is presently running on Linux?

In C++, I have a resource that is tied to a pid. Sometimes the process associated with that pid exits abnormally and leaks the resource. Therefore, I'm thinking of putting the pid in the file that records the resource as being in use. Then when I go to get a resource, if I see an item as registered as being in use, I would search to s...

How to use openssl to base 64 decode?

I am developing in C++ using Boost.Asio. I want to be able to base64 decode data and since Boost.Asio links to openssl I want to use it's functions to do so and not add an extra dependency(eg crypto++). I have found this code here that shows how to do it. (change int finalLen = BIO_read(bmem, (void*)pOut, outLen); to inLen ) I don't kno...

How can I delete a file upon its close in C++ on Linux?

I wish for a file to be deleted from disk only when it is closed. Up until that point, other processes should be able to see the file on disk and read its contents, but eventually after the close of the file, it should be deleted from disk and no longer visible on disk to other processes. ...

Accessibility: Managed vs Unmanaged code

I'm about to begin working on a Accessibility project for Windows (targeting XP through 7) and would like some advice on the pros an cons of using managed code vs unmanaged code. Basically the software will need to be able to read text from open windows, access menus, and other common functions programs like a JAWS or another screen read...

How far to go with a strongly typed language?

Let's say I am writing an API, and one of my functions take a parameter that represents a channel, and will only ever be between the values 0 and 15. I could write it like this: void Func(unsigned char channel) { if(channel < 0 || channel > 15) { // throw some exception } // do something } Or do I take advantage of C++ be...

Is it possible to use custom c++ classes with overloaded operators in QtScript?

Does anyone know if it is possible to have a C++ class with overloaded operators such as +,-,* and declare it somehow (this is where the magic happens) to a QtScriptEngine such that js-expressions like "a+b" are evaluated as they would be on the C++ side? ...

C++ objects serialization for Linux

I'm doing a program that needs send and receive data over the network. I never dealt with object serialization. I readed about some recommendations about Boost and Google Protocol Buffers. For use in Linux which is the best? If you know some other I will appreciate your help. Thanks. ...

How do I ensure that the same Python instance is always returned for a particular C++ instance?

I'm using Boost.Python to wrap a C++ library. How do I ensure that the same Python instance (by object identity) is always returned for a particular C++ instance (by pointer identity)? I can't extend the C++ classes, but I can add a member variable (such as a PyObject * or a boost::python::handle<>) if that helps. I'm thinking that I sh...

How do event listeners work?

Do they repeatedly check for the condition and execute if the condition is met. Ex, how the OS knows exactly when a USB device is plugged in, or how MSN knows exactly when you get an email. How does this work? Thanks ...

what is the proper way to delete a pointer in an array?

//the setup tiles = new Tile **[num_bands]; for( int i = 0 ; i < num_bands ; i++ ) tiles[i] = new Tile *[num_spokes]; for(int i=0; i < num_bands; i++){ for(int ii=0; ii < num_spokes; ii++){ tiles[i][ii] = 0; } } //the problem delete tiles[1][1]; When I delete a tile, tiles[1][1] still holds an address. I thought ...

More on the mediator pattern and OO design

So, I've come back to ask, once more, a patterns-related question. This may be too generic to answer, but my problem is this (I am programming and applying concepts that I learn as I go along): I have several structures within structures (note, I'm using the word structure in the general sense, not in the strict C struct sense (whoa, w...

Storing test data

Hi all, I'm currently in the early stages of designing a system that will end up having lots of tests. The application will be handling various XML data, and knowing the type of classes/functions that will go into this, I know that many tests (we're talking 100+) will need to load small XML documents that will then be used to test the p...

setting precision

I am starting out here with a simple temperature conversion program from F to C. I would like the C temperature to round to the 1/10 decimal place. I have 5 temperature conversions and can manually set the precision for each. But perhaps this is not a best practice? The Fahrenheit temperature for location 0 is 55 and to get a Celsius...

What is the double-pointer technique for simplifying the traversal of linked lists?

10 years ago I was shown a technique for traversing a linked list: instead of using a single pointer, you used a double-pointer. The technique yielded smaller, more elegant code by eliminating the need to check for certain boundary/edge cases. Does anyone know what this technique actually is? (Trying to remember, but cannot) ...

Writing stl compatible iterators

I'm trying to convert an iterator class I have to be stl compatible so that it can be used with the stl algorithms. In the following simple (and frankly useless) example, which should print the values 0 to 5 inclusive, I am getting the following errors, ISO C++ forbids incrementing a pointer of type ‘Iterator (*)()‘ and, invalid conve...

C++/cli -> calling c# dll -> calling OpenFileDialog issue

Hello Everyone, I write extensions to a C++ program. I write standard C/C++ dlls and I use IJW to call C# dlls. This has always worked perfectly until I wrote and called a C# dll that in turn called an OpenFileDialog and a SaveFileDialog. Whenever either was called with ShowDialog, the app would freeze. So in making a "Minimum Worki...

Automata based alternative to re2

I am needing to implement regular expressions in a C++ program I am writing, and I wanted to use re2 but I could not compile it on windows. Does anyone know of another regular expression library or whatever it's called that compiles easily on windows and isn't a "backtracking" regex engine, but an automata-theory based one (whatever that...

Perform connected_components with Boost adjacency_list where VertexList=listS

I use Boost Graph Library in a project and it is declared as: typedef adjacency_list <listS, listS, undirectedS, TrackInformation, LinkInformation> TracksConnectionGraph; Things are going fine until I have to call connected_components on my graph. typedef std::map<TracksConnectionGraph::vertex_descriptor, TracksConnectionGraph::vert...