AgentsQueue.cpp 1.98 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * AgentsQueue.cpp
 *
 *  Created on: 14.04.2015
 *      Author: piccolo
 */

#include "AgentsQueue.h"
9

10 11 12 13
#include "Pedestrian.h"

using namespace std;

14
vector<Pedestrian*> AgentsQueueIn::_agentsQueue;
15 16
vector<Pedestrian*> AgentsQueueOut::_agentsQueue;

17
mutex AgentsQueueIn::_queueMutex;
18 19
mutex AgentsQueueOut::_queueMutex;

20

21
void AgentsQueueIn::Add(vector<Pedestrian*>& peds)
22 23 24 25 26 27
{
     _queueMutex.lock();
     _agentsQueue.insert(_agentsQueue.end(),peds.begin(),peds.end());
     _queueMutex.unlock();
}

28
void AgentsQueueIn::GetandClear(std::vector<Pedestrian*>& peds)
29 30 31 32 33 34 35 36 37 38 39 40
{
     _queueMutex.lock();

     if(_agentsQueue.size()!=0)
     {
          peds.insert(peds.end(),_agentsQueue.begin(), _agentsQueue.end());
          //_agentsQueue.pop_back();
          _agentsQueue.clear();
     }
     _queueMutex.unlock();
}

41
bool AgentsQueueIn::IsEmpty()
42 43 44 45
{
     return (_agentsQueue.size()==0);
}

46 47 48 49
int AgentsQueueIn::Size()
{
     return _agentsQueue.size();
}
50 51 52 53 54 55 56 57 58

/////////////////////////////////////////////////////
////////////////////////////////////////////////////

void AgentsQueueOut::Add(vector<Pedestrian*>& peds)
{
     _queueMutex.lock();
     _agentsQueue.insert(_agentsQueue.end(),peds.begin(),peds.end());

59
     //todo: Can save time using a map
60
     std::sort( _agentsQueue.begin(), _agentsQueue.end() );
61 62
     _agentsQueue.erase( std::unique( _agentsQueue.begin(), _agentsQueue.end() ), _agentsQueue.end() );

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
     _queueMutex.unlock();
}

void AgentsQueueOut::Add(Pedestrian* ped)
{
     _queueMutex.lock();
     _agentsQueue.push_back(ped);
     _queueMutex.unlock();
}

void AgentsQueueOut::GetandClear(std::vector<Pedestrian*>& peds)
{
     _queueMutex.lock();

     if(_agentsQueue.size()!=0)
     {
          peds.insert(peds.end(),_agentsQueue.begin(), _agentsQueue.end());
          //_agentsQueue.pop_back();
          _agentsQueue.clear();
     }
     _queueMutex.unlock();
}

bool AgentsQueueOut::IsEmpty()
{
     return (_agentsQueue.size()==0);
}
90 91 92 93 94

int AgentsQueueOut::Size()
{
     return _agentsQueue.size();
}