|
Chris Hambleton wrote:
Is there a built-in function that would allow me to do this without having to create a new map and do this through a loop?
Nope. A map is normally a red-black tree implementation, so by swapping a key-value pair, you've essentially invalidated the location of that node in the tree.
You can always remove the key-value pair first and then add the swapped values back in the tree. (More overhead, less memory usage of course.)
Brandon
|
|
|
|
|
Humm, perhaps you could use a multimap, since insertion and remotion from the multimap doesn't invalidate the iterator(if I'm not mistaken here).
Cheers,
Joao Vaz
A Programming Language is a tool that has profound influence on our thinking habits -The late giant Edsger Dijkstra 1930 - 2002
And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary. -
|
|
|
|
|
Well, until Joaquin bidirectional map comes out I suggest you use two maps and use one of them depending on what the keys are. This is what I have been doing.
Best regards,
Alexandru Savescu
|
|
|
|
|
Why not store as the value both they value and the key
struct
{
int key;
int value;
} KeyValuePair;
std::map<int, KeyValuePair> mymap;
Then you can search through the map (although not as fast) by eithe the key or value.
Todd Smith
|
|
|
|
|
You can already do a linear search for values. Why add the key to the data set?
--
Please state the nature of your medical emergency.
|
|
|
|
|
You can always to this:
template <typename key_t, typename value_t>
class bidir_map {
typedef map<key_t, value_t> key_to_value_map;
typedef map<value_t, key_t> value_to_key_map;
key_to_value_map key_map;
value_to_key_map value_map;
};
Although, this may not be the most efficient implementation in terms of size. But if your collections is small, then this may be a cheap solution.
--
Please state the nature of your medical emergency.
|
|
|
|
|
Hello guys,
I have an ATL project with a COM object called IJeremy it has a method called SetMsg which takes an IMessage* as an [in] param.
This object fails to compile - it tells me:
error MIDL2025 : syntax error : expecting a type specification near "IMessage"
What is the best way around to get it to work?
I have tried importing CDOSys.Idl from my IDL, however it does not compile because of many errors.
Has anyone done this before?
Thanks for the help,
Jeremy
Jeremy Pullicino
Professional C++ Developer
Done any hacking lately?
|
|
|
|
|
Have you tried inserting a forward declaration for IMessage ?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Yes, I did that, however, I get another error when I do that.
error MIDL2011 : unresolved type declaration : IMessage [ Parameter 'pIMessage' of Procedure 'Submit' ( Interface 'ISubmitMsg2' ) ]
'Submit' is my method
'ISubmitMsg2' is my interface
Thanks,
Jeremy.
Jeremy Pullicino
Professional C++ Developer
Done any hacking lately?
|
|
|
|
|
Try moving the forward declaration of IMessage into the library block where ISubmitMsg2 is defined.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Jeremy Pullicino wrote:
I have an ATL project with a COM object called IJeremy it has a method called SetMsg which takes an IMessage* as an [in] param.
Why not pass the IUnknown* I/F and requery back for IMessage* I/F?
|
|
|
|
|
Bill S wrote:
Why not pass the IUnknown* I/F and requery back for IMessage* I/F?
I am currently doing that
I would like to manage to get an IMessage* through however...
Jeremy.
Jeremy Pullicino
Professional C++ Developer
Done any hacking lately?
|
|
|
|
|
Jeremy Pullicino wrote:
I would like to manage to get an IMessage* through however...
I assume that IMessage I/F is your own custom interface. You will have to import the interface definition file that provides the marshalling definition for this interface. This is created when compiling the IDL file that contains the IMessage I/F definition. Give it a try.
Best Regards,
|
|
|
|
|
Jeremy,
Try making your "in" look like this
[in]BSTR param
make sure you change the prototype in header file to reflect this change and update the function on the CPP file also.
let me know if this helps
in your code after you get the message that the container is returning to you, you will need to do something like this:
STDMETHODIMP CJeremy::SetMsg(BSTR param)
{
USES_CONVERSION;
LPSTR lpParam = W2A(param);
::MessageBox(NULL, lpParam, "Title", MB_OK);
return S_OK;
}
or very close to that in order to read the .
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
How can I catch a fired COM event in an ATL based NT/win2k service?
I have found only examples of clients written in VB or MFC.
Alma.
|
|
|
|
|
|
|
Hi, everyone!
Look at the source codes,
--------
/* #define WIN32 */
#ifdef WIN32
#define MORECORE wsbrk
#endif
--------
Such is the comments,
--------
WIN32 (default: undefined)
Define this on MS win (95, nt) platforms to compile in sbrk emulation.
--------
I have two questions,
1. What means WIN32? When the variable "WIN32" becomes
defined? When it is not defined?
2. What means "sbrk" in the comment? What means "wsbrk"?
Btw: the software is written for both Windows and Linux
platforms.
Cheers,
George
|
|
|
|
|
You need not crosspost, unless you intend to be flamed in no time ,
And I swallow a small raisin.
|
|
|
|
|
Thanks, StephaneRodriguez pal!
What means "flamed"? My English is not
very nice. But I will accept your advice.
However my boss is asked me to hand in the
project immediately, but I am in trouble as you
see.
Cheers,
George
|
|
|
|
|
A couple of people have already argued against you about the crosspost. See for yourself : the lounge.
And I swallow a small raisin.
|
|
|
|
|
Oh, I am sorry about that, StephaneRodriguez.
Yesterday, it is a very urgent case, my boss, ...
I promise that case will not happen again.
Cheers,
George
|
|
|
|
|
George Ma wrote:
What means "flamed"?
Basically it means that people starts writing not-so-nice things to you, because they get angry with you...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Oh, I am sorry about that, Anders.
Yesterday, it is a very urgent case, my boss, ...
I promise that case will not happen again.
Cheers,
George
|
|
|
|
|
We are asking you not to post in multiple forums. For example, your size_t question does not belong in the ATL/WTL/STL forum. Posting in more forums will not get you an answer quicker, and it's considered impolite on the net.
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|