File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimplePositionMapPointers< AnimalTypes > Class Template Reference

#include <PositionMap.h>

Public Member Functions

virtual int GetMapValue (unsigned a_x, unsigned a_y)
 
virtual void AddMapValue (unsigned a_x, unsigned a_y, AnimalTypes *a_value)
 
virtual void ClearMapValue (unsigned a_x, unsigned a_y)
 
virtual AnimalTypes * DecMapValue (unsigned a_x, unsigned a_y)
 
virtual bool RemoveMapValue (unsigned a_x, unsigned a_y, AnimalTypes *a_value)
 
virtual bool IsMapValue (unsigned a_x, unsigned a_y, AnimalTypes *a_value)
 
virtual int GetMapDensity (unsigned a_x, unsigned a_y, unsigned a_range)
 
virtual int GetMapDensityEdge (unsigned a_x, unsigned a_y, unsigned a_range)
 
virtual bool GetMapPositive (unsigned a_x, unsigned a_y, unsigned a_range)
 
virtual int SumMap ()
 
 SimplePositionMapPointers ()
 
 SimplePositionMapPointers (Landscape *a_l)
 
virtual ~SimplePositionMapPointers ()
 

Public Attributes

vector< vector< AnimalTypes * > * > m_TheMapSpmi
 
unsigned int m_maxx {}
 
unsigned int m_maxy {}
 

Constructor & Destructor Documentation

◆ SimplePositionMapPointers() [1/2]

template<typename AnimalTypes >
SimplePositionMapPointers< AnimalTypes >::SimplePositionMapPointers ( )
294  {
295 }

◆ SimplePositionMapPointers() [2/2]

template<typename AnimalTypes >
SimplePositionMapPointers< AnimalTypes >::SimplePositionMapPointers ( Landscape a_l)
explicit
297  {
298  m_maxx = a_l->SupplySimAreaWidth();
299  m_maxy = a_l->SupplySimAreaHeight();
300  m_TheMapSpmi.resize(m_maxx * m_maxy);
301  for (unsigned y = 0; y < m_maxy; y++)
302  {
303  for (unsigned x = 0; x < m_maxx; x++)
304  {
305  m_TheMapSpmi[x + y * m_maxx] = new vector<AnimalTypes*>();
306  }
307  }
308 }

References Landscape::SupplySimAreaHeight(), and Landscape::SupplySimAreaWidth().

◆ ~SimplePositionMapPointers()

template<typename AnimalTypes >
SimplePositionMapPointers< AnimalTypes >::~SimplePositionMapPointers ( )
virtual
310  {
311  for (unsigned y = 0; y < m_maxy; y++)
312  {
313  for (unsigned x = 0; x < m_maxx; x++)
314  {
315  delete m_TheMapSpmi[x + y * m_maxx];
316  }
317  }
318 }

Member Function Documentation

◆ AddMapValue()

template<typename AnimalTypes >
virtual void SimplePositionMapPointers< AnimalTypes >::AddMapValue ( unsigned  a_x,
unsigned  a_y,
AnimalTypes *  a_value 
)
inlinevirtual
201  {
202 
203  m_TheMapSpmi[a_x + a_y * m_maxx]->push_back(a_value);
204 
205  }

References SimplePositionMapPointers< AnimalTypes >::m_maxx, and SimplePositionMapPointers< AnimalTypes >::m_TheMapSpmi.

◆ ClearMapValue()

template<typename AnimalTypes >
virtual void SimplePositionMapPointers< AnimalTypes >::ClearMapValue ( unsigned  a_x,
unsigned  a_y 
)
inlinevirtual

◆ DecMapValue()

template<typename AnimalTypes >
virtual AnimalTypes* SimplePositionMapPointers< AnimalTypes >::DecMapValue ( unsigned  a_x,
unsigned  a_y 
)
inlinevirtual
214  {
215  AnimalTypes* val;
216 
217  if (m_TheMapSpmi[a_x + a_y * m_maxx]->size() > 0) { // can happen that there is nobody here because of parallel threads, so gracefully ignore this
218  val = (m_TheMapSpmi[a_x + a_y * m_maxx]->back());
219  m_TheMapSpmi[a_x + a_y * m_maxx]->pop_back();
220  }
221 
222  return (val);
223  }

References SimplePositionMapPointers< AnimalTypes >::m_maxx, and SimplePositionMapPointers< AnimalTypes >::m_TheMapSpmi.

◆ GetMapDensity()

template<typename AnimalTypes >
virtual int SimplePositionMapPointers< AnimalTypes >::GetMapDensity ( unsigned  a_x,
unsigned  a_y,
unsigned  a_range 
)
inlinevirtual
248  {
249  int dens = 0;
250  for (unsigned x = a_x; x < a_x + a_range; x++)
251  {
252  for (unsigned y = a_y; y < a_y + a_range; y++)
253  dens += (m_TheMapSpmi[x + y * m_maxx]->size());
254  }
255  return dens;
256  }

References SimplePositionMapPointers< AnimalTypes >::m_maxx, and SimplePositionMapPointers< AnimalTypes >::m_TheMapSpmi.

◆ GetMapDensityEdge()

template<typename AnimalTypes >
virtual int SimplePositionMapPointers< AnimalTypes >::GetMapDensityEdge ( unsigned  a_x,
unsigned  a_y,
unsigned  a_range 
)
inlinevirtual
258  {
259  if (a_x + a_range >= m_maxx) a_range = m_maxx - a_x;
260  if (a_y + a_range >= m_maxy) a_range = m_maxy - a_y;
261  int dens = 0;
262  for (unsigned x = a_x; x < a_x + a_range; x++)
263  {
264  for (unsigned y = a_y; y < a_y + a_range; y++)
265  dens += (m_TheMapSpmi[x + y * m_maxx]->size());
266  }
267  return dens;
268  }

References SimplePositionMapPointers< AnimalTypes >::m_maxx, SimplePositionMapPointers< AnimalTypes >::m_maxy, and SimplePositionMapPointers< AnimalTypes >::m_TheMapSpmi.

◆ GetMapPositive()

template<typename AnimalTypes >
virtual bool SimplePositionMapPointers< AnimalTypes >::GetMapPositive ( unsigned  a_x,
unsigned  a_y,
unsigned  a_range 
)
inlinevirtual
270  {
271  for (unsigned x = a_x; x < a_x + a_range; x++)
272  {
273  for (unsigned y = a_y; y < a_y + a_range; y++)
274  if (m_TheMapSpmi[x + y * m_maxx]->size() > 0) return true;
275  }
276  return false;
277  }

References SimplePositionMapPointers< AnimalTypes >::m_maxx, and SimplePositionMapPointers< AnimalTypes >::m_TheMapSpmi.

◆ GetMapValue()

template<typename AnimalTypes >
virtual int SimplePositionMapPointers< AnimalTypes >::GetMapValue ( unsigned  a_x,
unsigned  a_y 
)
inlinevirtual

◆ IsMapValue()

template<typename AnimalTypes >
virtual bool SimplePositionMapPointers< AnimalTypes >::IsMapValue ( unsigned  a_x,
unsigned  a_y,
AnimalTypes *  a_value 
)
inlinevirtual
238  {
239  bool res = false;
240 
241  auto an = std::find(m_TheMapSpmi[a_x + a_y * m_maxx]->begin(), m_TheMapSpmi[a_x + a_y * m_maxx]->end(), a_value);
242  if (an != m_TheMapSpmi[a_x + a_y * m_maxx]->end()) res = true;
243 
244  return res;
245  }

References SimplePositionMapPointers< AnimalTypes >::m_maxx, and SimplePositionMapPointers< AnimalTypes >::m_TheMapSpmi.

◆ RemoveMapValue()

template<typename AnimalTypes >
virtual bool SimplePositionMapPointers< AnimalTypes >::RemoveMapValue ( unsigned  a_x,
unsigned  a_y,
AnimalTypes *  a_value 
)
inlinevirtual
226  {
227  bool res = false;
228 
229  auto an = std::find(m_TheMapSpmi[a_x + a_y * m_maxx]->begin(), m_TheMapSpmi[a_x + a_y * m_maxx]->end(), a_value);
230  if (an != m_TheMapSpmi[a_x + a_y * m_maxx]->end()) {
231  m_TheMapSpmi[a_x + a_y * m_maxx]->erase(an);
232  res = true;
233  }
234  return res;
235  }

References SimplePositionMapPointers< AnimalTypes >::m_maxx, and SimplePositionMapPointers< AnimalTypes >::m_TheMapSpmi.

◆ SumMap()

template<typename AnimalTypes >
virtual int SimplePositionMapPointers< AnimalTypes >::SumMap ( )
inlinevirtual

Used as a debug test to be sure all additions/deletions are done correctly.

281  {
283  int nos = 0;
284  const unsigned sz = m_maxy * m_maxx;
285  for (unsigned i = 0; i < sz; i++) nos += m_TheMapSpmi[i]->size();
286  return nos;
287  }

References SimplePositionMapPointers< AnimalTypes >::m_maxx, SimplePositionMapPointers< AnimalTypes >::m_maxy, and SimplePositionMapPointers< AnimalTypes >::m_TheMapSpmi.

Member Data Documentation

◆ m_maxx

◆ m_maxy

template<typename AnimalTypes >
unsigned int SimplePositionMapPointers< AnimalTypes >::m_maxy {}

◆ m_TheMapSpmi


The documentation for this class was generated from the following file:
SimplePositionMapPointers::m_TheMapSpmi
vector< vector< AnimalTypes * > * > m_TheMapSpmi
Definition: PositionMap.h:192
Landscape::SupplySimAreaHeight
int SupplySimAreaHeight(void)
Gets the simulation landscape height.
Definition: Landscape.h:2302
Landscape::SupplySimAreaWidth
int SupplySimAreaWidth(void)
Gets the simulation landscape width.
Definition: Landscape.h:2297
SimplePositionMapPointers::m_maxx
unsigned int m_maxx
Definition: PositionMap.h:193
SimplePositionMapPointers::m_maxy
unsigned int m_maxy
Definition: PositionMap.h:193