RepastHPC  2.3.1
RelativeLocationMap.h
1 /*
2  * Repast for High Performance Computing (Repast HPC)
3  *
4  * Copyright (c) 2010 Argonne National Laboratory
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with
8  * or without modification, are permitted provided that the following
9  * conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * Neither the name of the Argonne National Laboratory nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  *
35  * RelativeLocationMap.h
36  *
37  * Created on: July 28, 2015
38  * Author: jtm
39  */
40 
41 #ifndef RELATIVELOCATIONMAP_H_
42 #define RELATIVELOCATION_H_
43 
44 #include "RelativeLocation.h"
45 using namespace std;
46 
47 namespace repast {
48 
49 template<typename T>
51 private:
52  vector<T>* data;
53  int size;
54 
55 public:
57  virtual ~RelativeLocationMap();
58 
59  T& get(int key);
60  T& get(RelativeLocation location);
61  T& operator[](RelativeLocation location);
62  int getSize();
63 };
64 
65 template<typename T>
67  size = location.getTotalValues();
68  data = new vector<T>(size);
69 }
70 
71 template<typename T>
72 RelativeLocationMap<T>::~RelativeLocationMap(){
73  delete data;
74 }
75 
76 template<typename T>
77 T& RelativeLocationMap<T>::get(int key){
78  if(key < 0 || key > size) return 0;
79  return data[key];
80 }
81 
82 template<typename T>
83 T& RelativeLocationMap<T>::RelativeLocationMap<T>::get(RelativeLocation location){
84  return get(location.getIndex());
85 }
86 
87 template<typename T>
88 T& RelativeLocationMap<T>::operator[](RelativeLocation location){
89  return data[location.getIndex()];
90 }
91 
92 template<typename T>
93 int RelativeLocationMap<T>::getSize(){
94  return size;
95 }
96 
97 }
98 
99 #endif /* DIFFUSIONLAYERND_H_ */
repast::RelativeLocation::getTotalValues
int getTotalValues()
Gets the total number of relative location values (including the center spot)
Definition: RelativeLocation.cpp:193
repast::RelativeLocationMap
Definition: RelativeLocationMap.h:50
repast::RelativeLocation
A RelativeLocation is a vector of integers that express a relative location in a coordinate system; t...
Definition: RelativeLocation.h:103