c++

tr1::hash for boost::thread::id?

Dear all: I started to use the unordered_set class from the tr1 namespace to speed-up access against the plain (tree-based) STL map. However, I wanted to store references to threads ID in boost (boost::thread::id), and realized that the API of those identifiers is so opaque that you cannot clearly obtain a hash of it. Surprisingly, boo...

Best audio playback api for C/C++ under Linux?

What is the best audio playback api for C/C++ for Linux, preferrably free/open source? I need it for embedded Linux, so I'm looking for something as lightweight as possible with not to many dependencies? Thanks a lot! ...

windows CreateFilemapping

link textIn my project I have implemented the CreateFileMapping concept to share memory between two processes. I have a server process in which I store the memory address of my session data, which contains details about a particular image. And I have a client process in which I read that address from the buffer. Now the problem is the ad...

Counting instances of individual derived classes

Hello, I'd like to be able to count instances of classes that belong in the same class hierarchy. For example, let's say I have this: class A; class B: public A; class C: public B; and then I have this code A* tempA = new A; B* tempB = new B; C* tempC = new C; C* tempC2 = new C; printf(tempA->GetInstancesCount()); printf(tempB->Ge...

What's the proper "C++ way" to do global variables?

I have a main application class, which contains a logger, plus some general app configurations, etc. Now I will display a lot of GUI windows and so on (that will use the logger and configs), and I don't want to pass the logger and configurations to every single constructor. I have seen some variants, like declaring the main class ext...

More threads, better performance?

When I write a message driven app. much like a standard windows app only that it extensively uses messaging for internal operations, what would be the best approach regarding to threading? As I see it, there are basically three approaches (if you have any other setup in mind, please share): Having a single thread process all of the me...

Qt best choice for animation on embedded?

I'm looking into technologies for a new embedded product that has a 1 ghz via processor, and a via s3 graphics chip. So far the target platform is Linux, but would like the option to move it over to a windows based platform. The application would consist of widgets like buttons, graphs, and numeric/text displays. More importantly, the ...

Can you provide an example of parsing HTML with your favorite parser?

This question is a lazy way of collecting examples of parsing HTML with a variety of languages and parsing libraries. Individual comments will be linked to in answers to questions about how to parse HTML with regexes as a way of showing the right way to do things (similar to how I use Can you provide some examples of why it is hard to p...

Structure to hold value by ranged key

I need a structure to hold a value based on a key that has a range. My implementation is C++, so any STL or Boost would be excellent. I have as range-key, which are doubles, and value [0,2) -> value1 [2,5) -> value2 [5,10) -> value3 etc Such that a search of 1.23 should return value1, and so on. Right now I am using a vector contai...

How to split Dot Net Hosting function when calling via C++ dll

I am exploring calling .net methods from unmanaged C++ code and have found the function below in How To Inject a Managed .NET Assembly (DLL) Into Another Process void StartTheDotNetRuntime() { // Bind to the CLR runtime.. ICLRRuntimeHost *pClrHost = NULL; HRESULT hr = CorBindToRuntimeEx( NULL, L"wks", 0, CLSID_CLRRun...

C hard coding an array of typedef struct

This is such a dumb question it's frustrating even asking it. Please, bear with me, I'm feeling particularly dumb over this one today.... I've got a library with a certain typedef struct. basically: typedef struct {int x; int y;} coords; What I really wanted to do was declare in my header a variable array of this: coords MyCoord...

std::map iterator not iterating in MFC app

I have a std::map declared thusly in a legacy MFC application: typedef std::map<long, CNutrientInfo> NUTRIENT_INFO_MAP; typedef NUTRIENT_INFO_MAP::const_iterator NUTRIENT_INFO_ITER; typedef NUTRIENT_INFO_MAP::value_type NUTRIENT_INFO_PAIR; static NUTRIENT_INFO_MAP m_NutrientInfoMap; m_NutrientInfoMap is populated when the app loads by...

Return class pointer from a function

I am not sure what is wrong with this (keep in mind I'm kinda sorta new to C++) I have this class: Foo { string name; public: SetName(string); } string Foo::SetName(string name) { this->name = name; return this->name; }; ////////////////////////////////////////////// //This is where I am trying to return a Foo pointer fro...

element-wise operations with boost c++ ublas matrix and vector types

i'd like to perform element-wise functions on boost matrix and vector types, e.g. take the logarithm of each element, exponentiate each element, apply special functions, such as gamma and digamma, etc. (similar to matlab's treatment of these functions applied to matrices and vectors.) i suppose writing a helper function that brute-force...

Handle Tab key in GLUT

Hi everyone! I use OpenGL+GLUT for simple application, but I can't handle a "Tab" key press. Does anybody knows how to handle pressing of Tab key ? thanx P.S.:Mac OS 10.5.6, GCC 4.0 Solution void processNormalKeys(unsigned char key, int x, int y){ if ((int)key == 9) { //tab pressed .... } .... } .... int ma...

Profiling disk access

Currently I am working on a MFC application which reads and writes in to the disk. Sometimes this application runs amazingly fast and sometimes it is damn slow. I am guessing that it is because of the disk access involved, hence I want to profile it. These are some questions in this regard: (1).Currently I am using AQTime profiler to pr...

How can I change Windows shell (cmd.exe) environment variables from C++?

I would like to write a program that sets an environment variable in an instance of the shell (cmd.exe) it was called from. The idea is that I could store some state in this variable and then use it again on a subsequent call. I know there are commands like SetEnvironmentVariable, but my understanding is that those only change the va...

MS Extensions To STL

Hi all, If this is a "Google Is Your Friend" question, I apologize in advance. I've searched but perhaps I've been using the wrong terms for searching. Can anyone point me to any sort of introductory document on the STL extensions which MS provided with Visual Studio 2003? I believe the libraries were licensed from Dinkumware and I'v...

How to create an iterator over elements that match a derived type in C++?

I'd like an iterator in C++ that can only iterate over elements of a specific type. In the following example, I want to iterate only on elements that are SubType instances. vector<Type*> the_vector; the_vector.push_back(new Type(1)); the_vector.push_back(new SubType(2)); //SubType derives from Type the_vector.push_back(new Type(3)); t...

Undefined reference? Is there something I'm not seeing? (c++, singleton class)

I can't seem to make this undefined reference go away. http://imgur.com/1qqDi.png (screenshot of issue) I have this code under the private section of Scene.h: static Scene * scene_; There is a #include "Scene.h" at the very first part of the header of Scene.cpp This is the only error I'm receiving at the moment, any ideas? I'll s...