Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
datatypedef.h
Go to the documentation of this file.
1 /*
2  * datatypedef.h
3  *
4  * Defines neccessary structs
5  */
6 
7 
8 #ifndef _DATATYPEDEF_H_
9 #define _DATATYPEDEF_H_
10 
11 #include <cstdio>
12 #include <cstdlib>
13 #include <iostream>
14 #include <string>
15 #include <vector>
16 
17 using std::string;
18 
22 struct index_order{
23  std::vector<int> order;
25 };
26 
27 
31 struct adj_map{
32  int variable;
33  long double factor;
34 };
35 
36 
37 
41 struct cmp_map{
42 
43  int metric;
44 
45  std::vector<int> file1_partitions;
46  int var1;
47 
49  int var2;
50 };
51 
52 
53 
57 struct rgb_color{
58  int r;
59  int g;
60  int b;
61 };
62 
63 
64 
68 struct pnt{
69  long double *vals;
70  int size;
71 
75  pnt(){
76  size = 0;
77  vals = NULL;
78  }
79 
83  ~pnt(){
84  if(size > 0)
85  delete[] vals;
86  }
87 
91  pnt(const pnt &p){
92  size = p.size;
93 
94  if(size > 0){
95  vals = new long double[size];
96 
97  for(int i=0; i<size; i++){
98  vals[i] = p.vals[i];
99  }
100  }
101  }
102 
107  pnt & operator = (const pnt &p){
108 
109  if(this != &p){
110  if(size > 0)
111  delete[] vals;
112 
113  size = p.size;
114  vals = new long double[size];
115 
116  for(int i=0; i<size; i++){
117  vals[i] = p.vals[i];
118  }
119  }
120 
121  return *this;
122  }
123 };
124 
125 
126 
134 
139  this->index = NULL;
140  index_size = 0;
141  }
142 
147  delete[] index;
148  }
149 
155  this->sizes = vda.sizes;
156  this->index_size = vda.index_size;
157 
158  if(index_size > 0){
159  this->index = new int[index_size];
160 
161  for(int i=0; i<index_size; i++)
162  index[i] = vda.index[i];
163  }
164  }
165 
172  if(this != &vda){
173  if(index_size > 0)
174  delete[] index;
175 
176  this->sizes = vda.sizes;
177  this->index_size = vda.index_size;
178 
179  if(index_size > 0){
180  this->index = new int[index_size];
181 
182  for(int i=0; i<index_size; i++)
183  index[i] = vda.index[i];
184  }
185  }
186 
187  return *this;
188  }
189 
194  void initArray(std::vector<int> dim_sizes){
195 
196  if(this->index != NULL)
197  return;
198 
199  int i_size = 1;
200  for(int i=0; i<dim_sizes.size(); i++){
201  i_size *= dim_sizes[i];
202  }
203 
204  index = new int[i_size];
205  index_size = i_size;
206 
207  for(int i=0; i<i_size; i++)
208  index[i] = -1;
209 
210  for(int i=0; i<dim_sizes.size(); i++){
211  this->sizes.push_back(dim_sizes[i]);
212  }
213  }
214 
220  int translate_coord_to_index(std::vector<int> vals){
221 
222  int flat_i = 0;
223 
224  for(int i=0; i<vals.size(); i++){
225 
226  if(vals[i] >= sizes[i] || vals[i] < 0)
227  return -1;
228 
229  int multiplier = 1;
230  for(int m=(i+1); m<vals.size(); m++){
231  multiplier *= sizes[m];
232  }
233 
234  flat_i += vals[i] * multiplier;
235  }
236 
237  return flat_i;
238  }
239 
245  std::vector<int> translate_index_to_coords(int index){
246  if(index > index_size){
247  std::vector<int> blank_ret;
248  return blank_ret;
249  }
250 
251  std::vector<int> ret;
252 
253  for(int i=0; i<sizes.size(); i++){
254 
255  int dimsize = 1;
256  for(int m=(i+1); m<sizes.size(); m++){
257  dimsize *= sizes[m];
258  }
259 
260  ret.push_back(index / dimsize);
261  index = index % dimsize;
262  }
263 
264  return ret;
265  }
266 
272  int getValue(std::vector<int> rLoc){
273 
274  if(rLoc.size() != sizes.size())
275  return -1;
276 
277  int flat_i = translate_coord_to_index(rLoc);
278  return index[flat_i];
279  }
280 
286  void setValue(std::vector<int> rLoc, int rVal){
287 
288  if(rLoc.size() != sizes.size())
289  return;
290 
291  int flat_i = translate_coord_to_index(rLoc);
292  index[flat_i] = rVal;
293  }
294 
296  int *index;
298 
299  //Dimenional layout
300  std::vector<int> sizes;
301 };
302 
303 
304 
305 #endif
int variable
Definition: datatypedef.h:32
std::vector< int > file1_partitions
Definition: datatypedef.h:45
int metric
Definition: datatypedef.h:43
int size
Definition: datatypedef.h:70
std::vector< int > translate_index_to_coords(int index)
Translate index to coordinates.
Definition: datatypedef.h:245
Variable dimension array, an array whose dimensions can be specified at runtime.
Definition: datatypedef.h:133
Used to store index order information.
Definition: datatypedef.h:22
int partition_number
Definition: datatypedef.h:24
Used by cmd parser to store comparison information.
Definition: datatypedef.h:41
long double * vals
Definition: datatypedef.h:69
VariableDimensionArray & operator=(const VariableDimensionArray &vda)
Equals operator deep copy.
Definition: datatypedef.h:171
~pnt()
Destructor.
Definition: datatypedef.h:83
std::vector< int > order
Definition: datatypedef.h:23
int var2
Definition: datatypedef.h:49
VariableDimensionArray(const VariableDimensionArray &vda)
Deep copy.
Definition: datatypedef.h:154
VariableDimensionArray()
Default constructor that initializes values to default.
Definition: datatypedef.h:138
int * index
Flat storage of values.
Definition: datatypedef.h:296
Point object that represents a single point.
Definition: datatypedef.h:68
pnt(const pnt &p)
Deep copy constructor.
Definition: datatypedef.h:91
blockLoc i
Definition: read.cpp:79
~VariableDimensionArray()
Destructor.
Definition: datatypedef.h:146
int translate_coord_to_index(std::vector< int > vals)
Translate coordinates to the flat index actually used for storage.
Definition: datatypedef.h:220
void setValue(std::vector< int > rLoc, int rVal)
Set the value at the given coordinates.
Definition: datatypedef.h:286
long double factor
Definition: datatypedef.h:33
std::vector< int > sizes
Definition: datatypedef.h:300
Store color information.
Definition: datatypedef.h:57
Used to store adjustment (normalization factor, conversion factor) information.
Definition: datatypedef.h:31
int var1
Definition: datatypedef.h:46
int file2_partition
Definition: datatypedef.h:48
pnt & operator=(const pnt &p)
Equals operator, deep copy.
Definition: datatypedef.h:107
pnt()
Constructor that initializes values to defaults.
Definition: datatypedef.h:75
int getValue(std::vector< int > rLoc)
Get the value specified by the loc coordinates.
Definition: datatypedef.h:272
void initArray(std::vector< int > dim_sizes)
Initialize the array with the specified dimensions.
Definition: datatypedef.h:194