Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VariableDimensionArray Struct Reference

Variable dimension array, an array whose dimensions can be specified at runtime. More...

#include <datatypedef.h>

Collaboration diagram for VariableDimensionArray:

Public Member Functions

 VariableDimensionArray ()
 Default constructor that initializes values to default. More...
 
 ~VariableDimensionArray ()
 Destructor. More...
 
 VariableDimensionArray (const VariableDimensionArray &vda)
 Deep copy. More...
 
VariableDimensionArrayoperator= (const VariableDimensionArray &vda)
 Equals operator deep copy. More...
 
void initArray (std::vector< int > dim_sizes)
 Initialize the array with the specified dimensions. More...
 
int translate_coord_to_index (std::vector< int > vals)
 Translate coordinates to the flat index actually used for storage. More...
 
std::vector< int > translate_index_to_coords (int index)
 Translate index to coordinates. More...
 
int getValue (std::vector< int > rLoc)
 Get the value specified by the loc coordinates. More...
 
void setValue (std::vector< int > rLoc, int rVal)
 Set the value at the given coordinates. More...
 

Public Attributes

int * index
 Flat storage of values. More...
 
int index_size
 
std::vector< int > sizes
 

Detailed Description

Variable dimension array, an array whose dimensions can be specified at runtime.

Values are stored in a flat array (an array with 1 dimension), and arithmetic is used to translate between coordinates (with the array's dimensionality) to flat indices.

Definition at line 133 of file datatypedef.h.

Constructor & Destructor Documentation

Default constructor that initializes values to default.

Definition at line 138 of file datatypedef.h.

References index, and index_size.

138  {
139  this->index = NULL;
140  index_size = 0;
141  }
int * index
Flat storage of values.
Definition: datatypedef.h:296

Destructor.

Definition at line 146 of file datatypedef.h.

References index.

146  {
147  delete[] index;
148  }
int * index
Flat storage of values.
Definition: datatypedef.h:296

Deep copy.

Parameters
vdaArray to copy

Definition at line 154 of file datatypedef.h.

References i, index, index_size, and sizes.

154  {
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  }
int * index
Flat storage of values.
Definition: datatypedef.h:296
blockLoc i
Definition: read.cpp:79
std::vector< int > sizes
Definition: datatypedef.h:300

Member Function Documentation

int getValue ( std::vector< int >  rLoc)
inline

Get the value specified by the loc coordinates.

Parameters
rLocCoordinates for the value to retrieve
Returns
The value

Definition at line 272 of file datatypedef.h.

References index, sizes, and translate_coord_to_index().

Referenced by indexed_points::get_indexed_point().

272  {
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  }
int * index
Flat storage of values.
Definition: datatypedef.h:296
int translate_coord_to_index(std::vector< int > vals)
Translate coordinates to the flat index actually used for storage.
Definition: datatypedef.h:220
std::vector< int > sizes
Definition: datatypedef.h:300

Here is the call graph for this function:

Here is the caller graph for this function:

void initArray ( std::vector< int >  dim_sizes)
inline

Initialize the array with the specified dimensions.

Parameters
dim_sizesThe size of each dimension of the array

Definition at line 194 of file datatypedef.h.

References i, index, index_size, and sizes.

Referenced by manual_index_pts::set_layout().

194  {
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  }
int * index
Flat storage of values.
Definition: datatypedef.h:296
blockLoc i
Definition: read.cpp:79
std::vector< int > sizes
Definition: datatypedef.h:300

Here is the caller graph for this function:

VariableDimensionArray& operator= ( const VariableDimensionArray vda)
inline

Equals operator deep copy.

Parameters
vdaArray to copy
Returns
Reference to new object

Definition at line 171 of file datatypedef.h.

References i, index, index_size, and sizes.

171  {
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  }
int * index
Flat storage of values.
Definition: datatypedef.h:296
blockLoc i
Definition: read.cpp:79
std::vector< int > sizes
Definition: datatypedef.h:300
void setValue ( std::vector< int >  rLoc,
int  rVal 
)
inline

Set the value at the given coordinates.

Parameters
rLocLocation of the value to set
rValValue to set

Definition at line 286 of file datatypedef.h.

References index, sizes, and translate_coord_to_index().

Referenced by manual_index_pts::set_index().

286  {
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  }
int * index
Flat storage of values.
Definition: datatypedef.h:296
int translate_coord_to_index(std::vector< int > vals)
Translate coordinates to the flat index actually used for storage.
Definition: datatypedef.h:220
std::vector< int > sizes
Definition: datatypedef.h:300

Here is the call graph for this function:

Here is the caller graph for this function:

int translate_coord_to_index ( std::vector< int >  vals)
inline

Translate coordinates to the flat index actually used for storage.

Parameters
valsCoordinates to translate
Returns
Flat index location corresponding to the coordinates

Definition at line 220 of file datatypedef.h.

References i, and sizes.

Referenced by indexed_points::get_connected_points(), getValue(), and setValue().

220  {
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  }
blockLoc i
Definition: read.cpp:79
std::vector< int > sizes
Definition: datatypedef.h:300

Here is the caller graph for this function:

std::vector<int> translate_index_to_coords ( int  index)
inline

Translate index to coordinates.

Parameters
indexFlat index value
Returns
Coordinates of the point specified by the flat index

Definition at line 245 of file datatypedef.h.

References i, index_size, and sizes.

Referenced by indexed_points::get_connected_points().

245  {
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  }
int * index
Flat storage of values.
Definition: datatypedef.h:296
blockLoc i
Definition: read.cpp:79
std::vector< int > sizes
Definition: datatypedef.h:300

Here is the caller graph for this function:

Member Data Documentation

int* index

Flat storage of values.

Definition at line 296 of file datatypedef.h.

Referenced by getValue(), initArray(), operator=(), setValue(), VariableDimensionArray(), and ~VariableDimensionArray().

int index_size

The documentation for this struct was generated from the following file: