Как правильно распечатать const char * struct член списка? - PullRequest
0 голосов
/ 13 июня 2019

Я пытаюсь отобразить элементы структуры списка в OMNeT ++, все элементы отображаются правильно, если только член не имеет тип const char *.Я запутался, потому что после трех push_back в списке, когда я отображаю.Все члены последнего отправленного элемента отображаются правильно, даже если он имеет тип const char *.Но для двух первых нажатых элементов член типа cont char * ничего не отображает, мусор или «DETAIL (Ipv4) Drones.host [3] .ipv4.ip».

Ipv4Address srcAddress = recMtlsd->getSrcAddress();
Ipv4Address dstAddress = recMtlsd->getDstAddress();
const char* position = recMtlsd->getPosition();
simtime_t time = recMtlsd->getTime();
int srcID = recMtlsd->getId();
EV_DEBUG << "Source : " << srcAddress << endl; 
EV_DEBUG << "Destination : " << dstAddress << endl;
EV_DEBUG << "Position : " << position << endl;
EV_DEBUG << "Time : " << time << endl;
EV_DEBUG << "Source ID: " << srcID << endl;
// All precedent displays are working correctly

/*typedef struct Mtlsd{
Ipv4Address originatorAddr, destinationAddr;
const char *position;
int originatorId;
simtime_t time;
}MTLSD;*/

MTLSD recitem;
recitem.originatorAddr = srcAddress;
recitem.originatorId = srcID;
recitem.destinationAddr = dstAddress;
recitem.position = position;
recitem.time = time;
EV_DEBUG << "Source : " << recitem.originatorAddr << endl;
EV_DEBUG << "Destination : " << recitem.dstinationAddr << endl;
EV_DEBUG << "Position : " << recitem.position << endl;
EV_DEBUG << "Time : " << recitem.time << endl;
EV_DEBUG << "Source ID: " << recitem.srcID << endl;
// All precedent displays are working correctly
/*typedef struct Mtlsd_data{
list<MTLSD> q;
int ID;
}MTLSD_DATA;*/
list<MTLSD_DATA> mtlsd_file;

auto node = find_if(mtlsd_file.begin(), mtlsd_file.end(), [=] (MTLSD_DATA const& i){return (i.ID == srcID);});
        bool found = (node != mtlsd_file.end());
        if (!found)
        {
            MTLSD_DATA recdata;
            recdata.ID = srcID;
            recdata.q.push_back(recitem);
            mtlsd_file.push_back(recdata);
            EV_DEBUG << "For node " << srcID ;
            for(auto claim=mtlsd_file.back().q.begin(); claim!=mtlsd_file.back().q.end();++claim)
            {
                EV_DEBUG << "(" << string(claim->position) << ", " << claim->time << ");" << endl;
            }
            // The precedent display works correctly
        }
        else
        {
            EV_DEBUG << "I already have data about the node " << node->ID << endl;
                if (node->q.size() == 3)
                {
                    EV_DEBUG << "I already have three time-location claim in the queue" << endl;
                    EV_DEBUG << "Here they are: ";
                    EV_DEBUG << "For node " << (*node).ID << endl;
                    for(auto fileclaim=(*node).q.begin(); fileclaim!=(*node).q.end();++fileclaim)
                        EV_DEBUG << "(" << string((*fileclaim).position) << ", " << (*fileclaim).time << ");" << endl;
                    EV_DEBUG << "I will delete the old one (" << node->q.front().position << ", " << node->q.front().time << ")" << endl;
                    node->q.pop_front();
                }
                node->q.push_back(recitem);
                EV_DEBUG << "I have pushed this new one : (" << string(node->q.back().position) << ", " << node->q.back().time << ")" << endl;
        }
            EV_DEBUG << "Here they are all time-location claims in the queue : ";
            for(auto fileclaims=node->q.begin(); fileclaims!=node->q.end();++fileclaims)
            {
                EV_DEBUG << "(" << string(fileclaims->position) << ", " << fileclaims->time << ");" << endl;
            }
            // The last element is displayed correctly, but those before not.
            .
            .
            .
...