|
Please, read the posting guidelines before posting (use the code tags to format your code properly, to make it more readable).
For your question, did you check the return value of GetCurrentBuffer ? See the documentation[^]
|
|
|
|
|
Hey,
So I am just trying to utilize some of the built-ins for from the stl containers. I want to be able to store a class in a map, using one of the params as the key, and then retrieve it via an iterator.
It looks like this:
typedef std::string NodeName;
typedef std::set<NodeName> NodeSet;
typedef std::map<NodeName, NodeSet> NodeMap;
class Node : public std::pair <NodeName, NodeSet>
NodeMap NMap;
...some code...
I can insert objects easily enough:
Node n (...);
NMap.insert (n);
lets say i do that a bunch.
I then want to iterator over the map, extracting the data as I go.
for (NodeMap::iterator it = NMap.begin (); it != NMap.end (); it++)
{
Node &node = *it; <-- fails
}
I get the following error:
"~/testing/nodelist% g++ NodeList.C
NodeList.C: In function âvoid compute()â:
NodeList.C:40: error: cannot dynamic_cast â& itâ (of type âstruct std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >*â) to type âclass Node*â (source type is not polymorphic)
NodeList.C:51: error: âclass std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >â has no member named âneighborhoodâ"
I tried dynamic casting but i couldn't seem to find it properly. Is there a legal way that I can do this? In the node class I made some handy little functions (nothing special), and I'd really like to be able to use them.
Could you please point out what my mistake is?
|
|
|
|
|
what you're doing looks terribly complex/convoluted - but anyway ..
you have an iterator 'it' to your map - which is a string 'NodeName' ->NodeSet , so,
it->first will be the string/NodeName
it->second will be the NodeSet
(ie, look up the properties of the iterator for a map)
|
|
|
|
|
Is their any standard formula to calculate time and space complexity of algo or please give me link to all above things r given..
|
|
|
|
|
Here[^] is what you could have found yourself.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
ohhh... I tried dis...but I didnt get wot I wanted exacly..
|
|
|
|
|
sam_psycho wrote: Is their any standard formula to calculate time and space complexity
Oh, no : too complex, both in space and time.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Oh, no : too complex, both in space and time. Big Grin
really? but I dont think it is toooooo complex...
|
|
|
|
|
|
|
Hi,
I woud Like to Use the CAsynSocket CLass as Member of CWinThread
In My Main Cwinthread I would like to Have 4 pointers to My CWinThreadSAsynSocket CLass'es
My question is the Following On Initinstance of the main thread
I would like to inistantiate them with the "new" operators and save thier m_thread id's
I Know that since CAsynSocket notfies completion via messages these Thread will have to be
of the UI variety
So. my question is When I want to pass them (threads a socket) to do work
I would ::Create the connection/socket
then Detach my socket and have them Attach the Socket
How do Notify them
Can I leave them in a Suspended status and do a Resume when I want them to take off
or since they are UI threads with a message pump they constantly have to be looping
and then my way of notifying them would be with PostThreadMessage ????
thankx
|
|
|
|
|
You shouldn't use Suspend/Resume, it has side effects, and it's meant to be used mostly by debuggers. It is better to use events[^].
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
This however is a UI thread with a Message Pump as CasyncSOcket post notificatins via messages
is it SAFE for a message Pump Thread to Wait for event Notification ????
|
|
|
|
|
I see your point. Well you can use MsgWaitForMultipleObjects[^], but even easier would be to use a user defined message instead of an event. One message to "start" and one message to "stop".
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Thankx
to Start CAsynSocketWinthread I can use PostMessageThread
I have to investigate and see how this works
In the Context of a Class or CWnd/Cdialog
thankx for the suggestion I will do some investigation
|
|
|
|
|
Forgot that CWnd/CDialog I have use message maps
Again thankx let me inestigate
|
|
|
|
|
It's something I did once when confronted with a similar problem. The code in your thread should look something like this pseudocode
if PeekMessage == MY_STOP_MESSAGE then
if GetMessage != MY_RESUME_MESSAGE then repeat
See the documentation in MSDN about PeekMessage and GetMessage
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Hi,
Sorry about the Delay'ed reply I had to check out
MsgWaitForMultipleObjects
Since My Code is MFC using MESSAGE_MAPS
was wondering how to handle it
So...
I think I'll have to use the Overridable
CWnd/CDialog Windowproc
to get a first look at the messages before
they are dispatched to the message map
e.g
then if its a message I'll use Peekmessage to
Pull it off the queue
When I have both the Event set and the Message
I'll use the info pointed to by Lparm(which I
saved in some global) area to do my
processing
thankx
|
|
|
|
|
Actually if you use PostThreadMessage you don't need to use MsgWaitForMultipleObjects, as you'll be using messages *instead of* events (hence no need to use MsgWaitForMultipleObjects to wait for events).
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
excuse me as I am probably not understanding
First of I am waiting for a reply in a Cdialog??
MsgWaitForMultipleObjects seem to be a neat way to check on a event in a UI thread or in this case Cdialog
while keeping the message Pump moving
|
|
|
|
|
Well yeah, but since you're already using a message pump, why not send a message instead of raising an event?
i.e. (from your sender thread)
PostThreadMessage MY_STOP_MESSAGE
....
PostThreadMessage MY_RESUME_MESSAGE
instead of
SetEvent MY_STOP_EVENT
....
SetEvent MY_RESUME_EVENT
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Yeah I understand
My two inputs one is from named pipes which I wait Overlapped.hEvent
and the other CAsynSocket
but you right I can wait for Multiple messages
thankx
|
|
|
|
|
what is the meaning of that statement?
*((*ptr+1)+2)
if i can use double dimension array in the declaration like
a[2][2]={1,2,3,4,5}
{2,4,6,8,9}
|
|
|
|
|
kumarashoka wrote: what is the meaning of that statement?
*((*ptr+1)+2)
Syntax error.
Please provide right context.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|