From 2a4d9c98ee4ba40d4f5e8308aed6b46aae58739e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 2 Jul 2013 10:34:57 -0700 Subject: [PATCH] add return of number of alive agents from AgentList --- libraries/shared/src/AgentList.cpp | 12 ++++++++++++ libraries/shared/src/AgentList.h | 1 + 2 files changed, 13 insertions(+) diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 2db1e68318..f438591d75 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -191,6 +191,18 @@ Agent* AgentList::agentWithID(uint16_t agentID) { return NULL; } +int AgentList::numAliveAgents() const { + int numAliveAgents = 0; + + for (AgentList::iterator agent = begin(); agent != end(); agent++) { + if (agent->isAlive()) { + ++numAliveAgents; + } + } + + return numAliveAgents; +} + void AgentList::setAgentTypesOfInterest(const char* agentTypesOfInterest, int numAgentTypesOfInterest) { delete _agentTypesOfInterest; diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index c817adb6f3..44bab7aa97 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -63,6 +63,7 @@ public: void(*linkedDataCreateCallback)(Agent *); int size() { return _numAgents; } + int numAliveAgents() const; void lock() { pthread_mutex_lock(&mutex); } void unlock() { pthread_mutex_unlock(&mutex); }