what median_unsafe in C++ mean - c++

I run into a C++ code:
vector<double> PITs;
if(PITs.size() > 0) PIT = util::median_unsafe(PITs);
What is mean by util::median_unsafe, why I cant find it in C++ reference? thanks

Maybe because it is not a part of C++ standard library. It is probably something from another part of the code you have. If you use some IDE it probably supports something like "GoTo Declaration/Definition", so you might be able to find out where that function comes from.

Related

How to find a pointer to a function by string

I have a list of functions in a text file that I'd like to expose to LLVM for its execution engine at run time, I'm wondering if its possible to find pointers to the functions at runtime rather than hard code in all the GlobalMappings by hand as I'd probably like to add in more later. For example:
// File: InternalFunctions.txt
PushScreen
PopScreen
TopScreen
// File: ExposeEngine.cpp
// Somehow figure out the address of the function specified in a string
void* addy = magicAddress("PushScreen");
jit->addGlobalMapping(llvmfunction, addy);
If this is possible I love to know how to do it, as I am trying to write my game engine by jit-ing c++. I was able to create some results earlier, but I had to hard-code in the mappings. I noticed that Gtk uses something along the lines of what I'm asking. When you use glade and provide a signal handler, the program you build in c will automatically find the function in your executable referenced by the string provided in the glade file. If getting results requires me to look into this Gtk thing I'd be more than happy to, but I don't know what feature or part of the api deals with that - I've already tried to look it up. I'd love to hear suggestions or advice.
Yes, you can do this. Look at the man pages for dlopen() and dlsym(): these functions are standard on *nix systems and let you look up symbols (functions or variables) by name. There is one significant issue, which is that C++ function names are usually "mangled" to encode type information. A typical way around this is to define a set of wrapper functions in an extern "C" {} block: these will be non-member, C-style functions which can then call into your C++ code. Their names will not be mangled, making them easy to look up using dlsym().
This is a pretty standard way that some plugin architectures work. Or at least used to work, before everyone started using interpreted languages!

Replacing CString in mingw compiler for eclipse

I have some code which is relatively big, but there is one part of it which uses something called CString (http://msdn.microsoft.com/en-us/library/aa300688%28v=vs.60%29.aspx) . Right now I am using the mingw compiler on eclipse and it doesnt seem to recognize it which makes sense. But I need to use the other part of the code. I know I can replace the CString with a const char * but there are several function like append which the code uses which are not defined. I was wondering whats the best way to port this code? Also there are other stdafx.h dependencies also like _T(). Whats the best approach I should take now?
There is a CString replacement over on CodeProject. I just googled for "CString alternative". I haven't looked at it but it should be easier to use that instead of std::string.

in-built C++ function that makes case insensitive comparision of two strings

Is there any in-built function in C++ library that is able to make case insensitive comparision of two strings ? I am aware of simple approaches like using toupper/tolower,writing function ourselves.I want to know if there is anything in string.h library or other which is able to meet above objective.Here,
strcasecmp of C don't support strings,so not much of help in C++.It only works with char *.
Any help would be very thankful.
P.S. Boost libraries won't be of much help.
Thanks.
If you are willing to call strcasecmp, then you can call it in C++ too:
int cmp_result = strcasecmp(s1.c_str(), s2.c_str());
There is none. C++ does not provide any meaningful textual support beyond simply storing it. You will have to look to ICU.

Getting strange error when attempting to convert Unmanaged C++ class to Managed C++ class (for use in .net)

Greetings,
First off, I am not a C++ developer, so please forgive my shortcomings....
I am attempting to take another developer's C++ unmanaged code and re-work it so it can be called from a managed DLL from our c#.net application. Please keep in mind that I'm a .net developer, and I haven't touched C++ in like 12 years. And when I did... I made a rock-paper-scissor game. :(
Anyway... I found a nice little note from another developer on a forum that suggested we go ahead and add a garbage collector to the class in the .h file with "Public __gc". Well, there are two classes I'm trying to convert to managed code, so I went ahead and did that... and one of them just instantly worked! The other... well, is throwing this error:
'cannot convert parameter 5 from 'char *__gc *' to 'char **'
Ok, so I know this has something to do with pointers pointing to more pointers and stuff... but here are the variables in question that DID work when the garbage collector wasn't added to the class name, and now won't build with it added:
<<< HEADER FILE >>>
public __gc class bob
{
...
public:
char *img_buff;
...
int init(void);
}
<<< CPP FILE >>>
int init(void)
{
...
nRet = is_AllocImageMem(hcam,
img_wid,
img_hgt,
depth,
&img_buff, << doesn't like it here
&mem_id );
...
}
Any suggestions or ideas? I just don't know enough about "*" and & and pointers and stuff in C++.
Thanks in advance. Best wishes!!!
What version of Visual Studio do you have? The __gc stuff is Managed C++, which was awful. You want C++/CLI, where the magic words are public ref class. Still, no matter which way you do this, you're going to have to understand pointers a little bit, because you're going to have code that says "I take a native pointer" and you intend to hand it a managed reference to something on the garbage collected heap. You'll have to change that code to make it work.
I am pretty sure using PInvoke is going to be a better plan for you because it won't require as much tweaking of the C++ code. If you have C++ expertise on the team my answer would be different.

Why can't I index a std::vector in the immediate window?

So, I have a vector
std::vector<std::string> lines.
I fill this vector up, and can access it like
std::string temp = lines[0];
However, in the immediate window, both
lines[0] - error:overloaded operator not found
and
lines.at(0) - error:symbol is ambiguous
don't work at all. Is there a trick to using the immediate window with c++. I'm mostly coming from a C# background, where everything works nicely (and I have intellisense in the Immediate Window). I wasn't expecting C++ to be great, but I figured it would work for things besides ints. Can anyone tell me what I'm doing wrong? Thanks.
EDIT: I should be clear, nothing really works in the immediate window, this is just a simplified example
EDIT: I'm in debug mode
The immediate and watch windows don't support overloaded operators. There is some support in there for printing standard containers as a whole in a sensible fashion (see, e.g., http://www.virtualdub.org/blog/pivot/entry.php?id=120), but this doesn't extend to being able to use operator[] on them.
Hopefully this will be improved in later revisions of the debugger, but for now, to look at the i'th element of a vector, try lines._Myfirst[i].
(_Myfirst, in the standard libraries that come with VC++, happens to be the member variable in a std::vector that points to the first element of the sequence. So this is just examining a vector as if it were any other object. To work this out, I had to look at the headers... not very convenient, but hopefully this will help you. You can probably do something similar with the other containers, but you'll have to look in the headers to work out how.)
(By the way, if you've been working in C#, the C++ debugger will probably seem by comparison a bit less slick in general, and this is just one example of that. I get the impression there's been much more work put into the CLR side.)
In nowaday's Visual Studio versions (e.g. 2013/2015) _Myfirst member variable does no longer exist for a std::vector variable. Use _C_begin instead - means for the given example use e.g. lines._C_begin[i].