trallallero
17-12-2008, 10:08
Ho una classe LLMessage che è un gestore di messaggi e i messaggi sono contenuti in una std::list.
class LLMessage
{
public:
LLMessage() { Rewind(); }
bool GetNext (LLMsgVals& vals)
{
while ( m_ListIter != m_MsgVals.end() )
{
if ( (*m_ListIter).Delay == 0 || ((*m_ListIter).Delay > 0 && (*m_ListIter).ExpireTime <= time(NULL)) )
{
vals = *m_ListIter;
m_ListIter = m_MsgVals.erase(m_ListIter);
return true;
}
++m_ListIter;
}
m_ListIter = m_MsgVals.begin();
return false;
}
...
private:
list <LLMsgVals> m_MsgVals;
}
LLMsgVals è una struttura.
GetNext è una funzione che estrae un messaggio dalla lista, quindi lo elimina.
Adesso ho un problema: siccome devo usare questa lista anche da un altro processo (un autotester), prima di usarla la passo alla classe AutoTester come riferimento
AutoTesterSpace::AT_RESULT AT_Res = m_AutoTest->Process( msgIn, m_msgTrolley, matrix, time(NULL) );
che, come prima cosa, ne fa una copia per non rovinare l'originale.
AT_RESULT AutoTester::Process(LLCMessage& InMsg, LLMessage& OutMsg, ConnectionMatrix_t& matrix, int TransactionID)
{
m_OutMsg = OutMsg; // create a copy as the passed msg CANNOT BE CHANGED !!!
...
}
Beh, quando esco dalla funzione Process della classe AutoTester, la lista originale è vuota!
Ho provato ad aggiungere un copy constructor:
LLMessage(const LLMessage& msg) : m_MsgVals(msg.m_MsgVals) { Rewind(); }
ma nada ...
Non so se ho spiegato bene ... qualcuno mi sa aiutare ? :help:
Grazie.
class LLMessage
{
public:
LLMessage() { Rewind(); }
bool GetNext (LLMsgVals& vals)
{
while ( m_ListIter != m_MsgVals.end() )
{
if ( (*m_ListIter).Delay == 0 || ((*m_ListIter).Delay > 0 && (*m_ListIter).ExpireTime <= time(NULL)) )
{
vals = *m_ListIter;
m_ListIter = m_MsgVals.erase(m_ListIter);
return true;
}
++m_ListIter;
}
m_ListIter = m_MsgVals.begin();
return false;
}
...
private:
list <LLMsgVals> m_MsgVals;
}
LLMsgVals è una struttura.
GetNext è una funzione che estrae un messaggio dalla lista, quindi lo elimina.
Adesso ho un problema: siccome devo usare questa lista anche da un altro processo (un autotester), prima di usarla la passo alla classe AutoTester come riferimento
AutoTesterSpace::AT_RESULT AT_Res = m_AutoTest->Process( msgIn, m_msgTrolley, matrix, time(NULL) );
che, come prima cosa, ne fa una copia per non rovinare l'originale.
AT_RESULT AutoTester::Process(LLCMessage& InMsg, LLMessage& OutMsg, ConnectionMatrix_t& matrix, int TransactionID)
{
m_OutMsg = OutMsg; // create a copy as the passed msg CANNOT BE CHANGED !!!
...
}
Beh, quando esco dalla funzione Process della classe AutoTester, la lista originale è vuota!
Ho provato ad aggiungere un copy constructor:
LLMessage(const LLMessage& msg) : m_MsgVals(msg.m_MsgVals) { Rewind(); }
ma nada ...
Non so se ho spiegato bene ... qualcuno mi sa aiutare ? :help:
Grazie.