Ice Sheet System Model  4.18
Code documentation
Public Member Functions | Data Fields
DataSet Class Reference

Declaration of DataSet class. More...

#include <DataSet.h>

Inheritance diagram for DataSet:
Constraints Contours Elements Loads Materials Nodes Observations Options Results Vertices

Public Member Functions

 DataSet ()
 
 DataSet (int enum_type)
 
 ~DataSet ()
 
void Marshall (char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
 
int GetEnum ()
 
int GetEnum (int offset)
 
void Echo ()
 
void DeepEcho ()
 
int AddObject (Object *object)
 
int DeleteObject (int id)
 
int Size ()
 
void clear ()
 
ObjectGetObjectByOffset (int offset)
 
ObjectGetObjectById (int *poffset, int eid)
 
void Presort ()
 
void Sort ()
 
DataSetCopy (void)
 
int DeleteObject (Object *object)
 

Data Fields

std::vector< Object * > objects
 
int enum_type
 
int sorted
 
int presorted
 
int numsorted
 
int * sorted_ids
 
int * id_offsets
 

Detailed Description

Declaration of DataSet class.

Declaration of DataSet class. A DataSet is a Container of Objects.

Definition at line 14 of file DataSet.h.

Constructor & Destructor Documentation

◆ DataSet() [1/2]

DataSet::DataSet ( )

Definition at line 27 of file DataSet.cpp.

27  {/*{{{*/
28 
29  sorted=0;
30  numsorted=0;
31  presorted=0;
32  enum_type=-1;
33  sorted_ids=NULL;
34  id_offsets=NULL;
35 
36 }

◆ DataSet() [2/2]

DataSet::DataSet ( int  enum_type)

Definition at line 38 of file DataSet.cpp.

38  {/*{{{*/
39  enum_type=dataset_enum;
40 
41  sorted=0;
42  numsorted=0;
43  presorted=0;
44  sorted_ids=NULL;
45  id_offsets=NULL;
46 
47 }

◆ ~DataSet()

DataSet::~DataSet ( )

Definition at line 85 of file DataSet.cpp.

85  {/*{{{*/
86  clear();
87  xDelete<int>(sorted_ids);
88  xDelete<int>(id_offsets);
89 }

Member Function Documentation

◆ Marshall()

void DataSet::Marshall ( char **  pmarshalled_data,
int *  pmarshalled_data_size,
int  marshall_direction 
)

Definition at line 93 of file DataSet.cpp.

93  { /*{{{*/
94 
95  vector<Object*>::iterator obj;
96  int obj_size=0;
97  int obj_enum=0;
98  int i;
99 
100  if(marshall_direction==MARSHALLING_FORWARD || marshall_direction==MARSHALLING_SIZE){
101  obj_size=objects.size();
102  }
103  else{
104  clear();
105  }
106 
112 
113  /*Now branch according to direction of marshalling: */
114  if(marshall_direction==MARSHALLING_FORWARD || marshall_direction==MARSHALLING_SIZE){
115  if(!(this->sorted && numsorted>0 && this->id_offsets)){
116  sorted_ids=NULL;
117  id_offsets=NULL;
118  }
121  MARSHALLING(obj_size);
122 
123  /*Go through our objects, and marshall them into the buffer: */
124  for( obj=this->objects.begin() ; obj < this->objects.end(); obj++ ){
125  obj_enum=(*obj)->ObjectEnum();
126  MARSHALLING(obj_enum);
127  (*obj)->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
128  }
129  }
130  else{
131 
134  if (!(this->sorted && numsorted>0)){
135  sorted_ids=NULL;
136  id_offsets=NULL;
137  }
138  MARSHALLING(obj_size);
139 
140  /*This is the heart of the demashalling method. We have a buffer coming
141  in, and we are supposed to create a dataset out of it. No such thing
142  as class orientation for buffers, we need to key off the enum of each
143  object stored in the buffer. */
144  for(i=0;i<obj_size;i++){
145 
146  /*Recover enum of object first: */
147  MARSHALLING(obj_enum);
148 
149  /*Giant case statement to spin-up the right object, and demarshall into it the information
150  *stored in the buffer: */
151  if(obj_enum==NodeEnum){
152  Node* node=NULL;
153  node=new Node();
154  node->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
155  this->AddObject(node);
156  }
157  else if(obj_enum==VertexEnum){
158  Vertex* vertex=NULL;
159  vertex=new Vertex();
160  vertex->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
161  this->AddObject(vertex);
162  }
163  else if(obj_enum==MaticeEnum){
164  Matice* matice=NULL;
165  matice=new Matice();
166  matice->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
167  this->AddObject(matice);
168  }
169  else if(obj_enum==MatestarEnum){
170  Matestar* matestar=NULL;
171  matestar=new Matestar();
172  matestar->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
173  this->AddObject(matestar);
174  }
175  else if(obj_enum==SpcStaticEnum){
176  SpcStatic* spcstatic=NULL;
177  spcstatic=new SpcStatic();
178  spcstatic->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
179  this->AddObject(spcstatic);
180  }
181  else if(obj_enum==SpcDynamicEnum){
182  SpcDynamic* spcdynamic=NULL;
183  spcdynamic=new SpcDynamic();
184  spcdynamic->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
185  this->AddObject(spcdynamic);
186  }
187  else if(obj_enum==SpcTransientEnum){
188  SpcTransient* spctransient=NULL;
189  spctransient=new SpcTransient();
190  spctransient->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
191  this->AddObject(spctransient);
192  }
193  else if(obj_enum==TriaEnum){
194  Tria* tria=NULL;
195  tria=new Tria();
196  tria->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
197  this->AddObject(tria);
198  }
199  else if(obj_enum==PentaEnum){
200  Penta* penta=NULL;
201  penta=new Penta();
202  penta->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
203  this->AddObject(penta);
204  }
205  else if(obj_enum==TetraEnum){
206  Tetra* tetra=NULL;
207  tetra=new Tetra();
208  tetra->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
209  this->AddObject(tetra);
210  }
211  else if(obj_enum==SegEnum){
212  Seg* seg=NULL;
213  seg=new Seg();
214  seg->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
215  this->AddObject(seg);
216  }
217  else if(obj_enum==RiftfrontEnum){
218  Riftfront* rift=NULL;
219  rift=new Riftfront();
220  rift->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
221  this->AddObject(rift);
222  }
223  else if(obj_enum==NumericalfluxEnum){
224  Numericalflux* numflux=NULL;
225  numflux=new Numericalflux();
226  numflux->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
227  this->AddObject(numflux);
228  }
229  else if(obj_enum==PengridEnum){
230  Pengrid* pengrid=NULL;
231  pengrid=new Pengrid();
232  pengrid->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
233  this->AddObject(pengrid);
234  }
235  else if(obj_enum==PenpairEnum){
236  Penpair* penpair=NULL;
237  penpair=new Penpair();
238  penpair->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
239  this->AddObject(penpair);
240  }
241  else if(obj_enum==DoubleExternalResultEnum){
243  result->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
244  result->Echo();
245  this->AddObject(result);
246  }
247  else _error_("could not recognize enum type: " << obj_enum << ": " << EnumToStringx(obj_enum) );
248  }
249  }
250 }

◆ GetEnum() [1/2]

int DataSet::GetEnum ( )

Definition at line 324 of file DataSet.cpp.

324  {/*{{{*/
325  return enum_type;
326 }

◆ GetEnum() [2/2]

int DataSet::GetEnum ( int  offset)

Definition at line 328 of file DataSet.cpp.

328  {/*{{{*/
329 
330  return objects[offset]->ObjectEnum();
331 
332 }

◆ Echo()

void DataSet::Echo ( void  )

Definition at line 307 of file DataSet.cpp.

307  {/*{{{*/
308 
309  vector<Object*>::iterator object;
310 
311  _assert_(this);
312 
313  _printf0_("DataSet echo: " << objects.size() << " objects\n");
314 
315  for ( object=objects.begin() ; object < objects.end(); object++ ){
316 
317  /*Call echo on object: */
318  (*object)->Echo();
319 
320  }
321  return;
322 }

◆ DeepEcho()

void DataSet::DeepEcho ( void  )

Definition at line 291 of file DataSet.cpp.

291  {/*{{{*/
292 
293  vector<Object*>::iterator object;
294 
295  _assert_(this);
296 
297  _printf0_("DataSet echo: " << objects.size() << " objects\n");
298 
299  for ( object=objects.begin() ; object < objects.end(); object++ ){
300 
301  /*Call deep echo on object: */
302  (*object)->DeepEcho();
303 
304  }
305 }

◆ AddObject()

int DataSet::AddObject ( Object object)

Definition at line 252 of file DataSet.cpp.

252  {/*{{{*/
253 
254  _assert_(this);
255  objects.push_back(object);
256 
257  return 1;
258 }

◆ DeleteObject() [1/2]

int DataSet::DeleteObject ( int  id)

◆ Size()

int DataSet::Size ( void  )

Definition at line 399 of file DataSet.cpp.

399  {/*{{{*/
400  _assert_(this!=NULL);
401 
402  return objects.size();
403 }

◆ clear()

void DataSet::clear ( )

Definition at line 260 of file DataSet.cpp.

260  {/*{{{*/
261 
262 /* use reverse_iterator for efficiency in matlab memory manager
263  (keeping old code in case it needs to revert back) */
264 
265 // vector<Object*>::iterator object;
266  vector<Object*>::reverse_iterator object;
267 
268 // for ( object=objects.begin() ; object < objects.end(); object++ ){
269 // delete (*object);
270 // }
271  for ( object=objects.rbegin() ; object < objects.rend(); object++ ){
272  delete (*object);
273  }
274  objects.clear();
275 }

◆ GetObjectByOffset()

Object * DataSet::GetObjectByOffset ( int  offset)

Definition at line 334 of file DataSet.cpp.

334  {/*{{{*/
335 
336  /*Check index in debugging mode*/
337  _assert_(this!=NULL);
338  _assert_(offset>=0);
339  _assert_(offset<this->Size());
340 
341  return objects[offset];
342 
343 }

◆ GetObjectById()

Object * DataSet::GetObjectById ( int *  poffset,
int  eid 
)

Definition at line 345 of file DataSet.cpp.

345  {/*{{{*/
346 
347  int id_offset;
348  int offset;
349 
350  _assert_(this);
351  if(!sorted || objects.size()>numsorted)_error_("trying to binary search on a non-sorted dataset!");
352 
353  /*Carry out a binary search on the sorted_ids: */
354  if(!binary_search(&id_offset,eid,sorted_ids,objects.size())){
355  _error_("could not find object with id " << eid << " in DataSet " << EnumToStringx(enum_type));
356  }
357 
358  /*Convert the id offset into sorted offset: */
359  offset=id_offsets[id_offset];
360 
361  /*Assign output pointers if requested:*/
362  if(poffset)*poffset=offset;
363 
364  /*Return object at offset position in objects :*/
365  return objects[offset];
366 }

◆ Presort()

void DataSet::Presort ( )

Definition at line 368 of file DataSet.cpp.

368  {/*{{{*/
369 
370  /*vector of objects is already sorted, just allocate the sorted ids and their
371  * offsets:*/
372  if(objects.size()){
373 
374  /*Delete existing ids*/
375  if(sorted_ids) xDelete<int>(sorted_ids);
376  if(id_offsets) xDelete<int>(id_offsets);
377 
378  /*Allocate new ids*/
379  sorted_ids=xNew<int>(objects.size());
380  id_offsets=xNew<int>(objects.size());
381 
382  /*Build id_offsets and sorted_ids*/
383  for(int i=0;i<objects.size();i++){
384  id_offsets[i]=i;
385  sorted_ids[i]=objects[i]->Id();
386 
387  /*In debugging mode, make sure Ids are ACTUALLY sorted...*/
388  #ifdef _ISSM_DEBUG_
389  //if(i>0) _assert_(sorted_ids[i]>sorted_ids[i-1]);
390  #endif
391  }
392  }
393 
394  /*set sorted flag: */
395  numsorted=objects.size();
396  sorted=1;
397 }

◆ Sort()

void DataSet::Sort ( )

Definition at line 405 of file DataSet.cpp.

405  {/*{{{*/
406 
407  /*Only sort if we are not already sorted: */
408  if(!sorted){
409  _error_("not implemented yet!");
410  }
411 }

◆ Copy()

DataSet * DataSet::Copy ( void  )

Definition at line 49 of file DataSet.cpp.

49  {/*{{{*/
50 
51  vector<Object*>::iterator obj;
52  Object* object_copy=NULL;
53 
54  DataSet* copy=new DataSet(this->enum_type);
55 
56  copy->sorted=this->sorted;
57  copy->numsorted=this->numsorted;
58  copy->presorted=this->presorted;
59 
60  /*Now we need to deep copy the objects: */
61  for ( obj=this->objects.begin() ; obj < this->objects.end(); obj++ ){
62  /*Call copy on object: */
63  object_copy = (*obj)->copy();
64  copy->AddObject(object_copy);
65  }
66 
67  /*Build id_offsets and sorted_ids*/
68  int objsize = this->numsorted;
69  if(this->sorted && objsize>0 && this->id_offsets){
70  /*Allocate new ids*/
71  copy->id_offsets=xNew<int>(objsize);
72  xMemCpy<int>(copy->id_offsets,this->id_offsets,objsize);
73  }
74  else copy->id_offsets=NULL;
75  if(this->sorted && objsize>0 && this->sorted_ids){
76  /*Allocate new ids*/
77  copy->sorted_ids=xNew<int>(objsize);
78  xMemCpy<int>(copy->sorted_ids,this->sorted_ids,objsize);
79  }
80  else copy->sorted_ids=NULL;
81 
82  return copy;
83 }

◆ DeleteObject() [2/2]

int DataSet::DeleteObject ( Object object)

Definition at line 277 of file DataSet.cpp.

277  {/*{{{*/
278 
279  vector<Object*>::iterator iterator;
280 
281  if(object){
282  iterator = find(objects.begin(), objects.end(),object);
283  delete *iterator;
284  objects.erase(iterator);
285  }
286 
287  return 1;
288 
289 }

Field Documentation

◆ objects

std::vector<Object*> DataSet::objects

Definition at line 19 of file DataSet.h.

◆ enum_type

int DataSet::enum_type

Definition at line 22 of file DataSet.h.

◆ sorted

int DataSet::sorted

Definition at line 25 of file DataSet.h.

◆ presorted

int DataSet::presorted

Definition at line 26 of file DataSet.h.

◆ numsorted

int DataSet::numsorted

Definition at line 27 of file DataSet.h.

◆ sorted_ids

int* DataSet::sorted_ids

Definition at line 28 of file DataSet.h.

◆ id_offsets

int* DataSet::id_offsets

Definition at line 29 of file DataSet.h.


The documentation for this class was generated from the following files:
DataSet::Size
int Size()
Definition: DataSet.cpp:399
SpcTransientEnum
@ SpcTransientEnum
Definition: EnumDefinitions.h:1281
PengridEnum
@ PengridEnum
Definition: EnumDefinitions.h:1229
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
Seg::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Seg.cpp:122
TetraEnum
@ TetraEnum
Definition: EnumDefinitions.h:1300
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
DataSet::AddObject
int AddObject(Object *object)
Definition: DataSet.cpp:252
Penpair::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Penpair.cpp:86
MARSHALLING_ENUM
#define MARSHALLING_ENUM(EN)
Definition: Marshalling.h:14
DataSet::objects
std::vector< Object * > objects
Definition: DataSet.h:19
MARSHALLING_SIZE
@ MARSHALLING_SIZE
Definition: Marshalling.h:11
NodeEnum
@ NodeEnum
Definition: EnumDefinitions.h:659
PenpairEnum
@ PenpairEnum
Definition: EnumDefinitions.h:1230
Matestar
Definition: Matestar.h:24
DataSet::sorted_ids
int * sorted_ids
Definition: DataSet.h:28
GenericExternalResult::Echo
void Echo(void)
Definition: GenericExternalResult.h:155
Pengrid::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Pengrid.cpp:121
Tetra::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Tetra.cpp:120
SegEnum
@ SegEnum
Definition: EnumDefinitions.h:1268
Penta
Definition: Penta.h:29
Vertex::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Vertex.cpp:116
SpcStatic
Definition: SpcStatic.h:13
MARSHALLING_DYNAMIC
#define MARSHALLING_DYNAMIC(FIELD, TYPE, SIZE)
Definition: Marshalling.h:61
SpcStatic::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: SpcStatic.cpp:75
SpcTransient::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: SpcTransient.cpp:81
Object
Definition: Object.h:13
Tetra
Definition: Tetra.h:27
Riftfront::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Riftfront.cpp:189
SpcStaticEnum
@ SpcStaticEnum
Definition: EnumDefinitions.h:1280
Penpair
Definition: Penpair.h:16
MatestarEnum
@ MatestarEnum
Definition: EnumDefinitions.h:1168
NumericalfluxEnum
@ NumericalfluxEnum
Definition: EnumDefinitions.h:1206
DataSet::sorted
int sorted
Definition: DataSet.h:25
EnumToStringx
const char * EnumToStringx(int enum_in)
Definition: EnumToStringx.cpp:15
Pengrid
Definition: Pengrid.h:21
Matestar::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Matestar.cpp:103
SpcDynamicEnum
@ SpcDynamicEnum
Definition: EnumDefinitions.h:1279
MARSHALLING
#define MARSHALLING(FIELD)
Definition: Marshalling.h:29
SpcDynamic::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: SpcDynamic.cpp:73
DataSet::enum_type
int enum_type
Definition: DataSet.h:22
Penta::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Penta.cpp:143
RiftfrontEnum
@ RiftfrontEnum
Definition: EnumDefinitions.h:1240
DataSet::clear
void clear()
Definition: DataSet.cpp:260
VertexEnum
@ VertexEnum
Definition: EnumDefinitions.h:1322
SpcTransient
Definition: SpcTransient.h:13
Seg
Definition: Seg.h:27
SpcDynamic
Definition: SpcDynamic.h:13
Matice
Definition: Matice.h:24
GenericExternalResult
Definition: GenericExternalResult.h:21
Node::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Node.cpp:251
Node
Definition: Node.h:23
Matice::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Matice.cpp:161
Numericalflux
Definition: Numericalflux.h:18
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
Tria
Definition: Tria.h:29
DataSetEnum
@ DataSetEnum
Definition: EnumDefinitions.h:1028
PentaEnum
@ PentaEnum
Definition: EnumDefinitions.h:1231
MARSHALLING_FORWARD
@ MARSHALLING_FORWARD
Definition: Marshalling.h:9
GenericExternalResult::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: GenericExternalResult.h:169
DoubleExternalResultEnum
@ DoubleExternalResultEnum
Definition: EnumDefinitions.h:1042
Tria::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Tria.cpp:146
DataSet::numsorted
int numsorted
Definition: DataSet.h:27
Numericalflux::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Numericalflux.cpp:203
Object::copy
virtual Object * copy()=0
MaticeEnum
@ MaticeEnum
Definition: EnumDefinitions.h:1169
Vertex
Definition: Vertex.h:19
binary_search
int binary_search(int *poffset, int target, int *sorted_integers, int num_integers)
Definition: binary_search.cpp:14
DataSet
Declaration of DataSet class.
Definition: DataSet.h:14
DataSet::id_offsets
int * id_offsets
Definition: DataSet.h:29
DataSet::DataSet
DataSet()
Definition: DataSet.cpp:27
TriaEnum
@ TriaEnum
Definition: EnumDefinitions.h:1318
DataSet::presorted
int presorted
Definition: DataSet.h:26
Riftfront
Definition: Riftfront.h:16