Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IntList.cpp
Go to the documentation of this file.
1 
2 #include "IntList.hpp"
3 
5  d_first(0),
6  d_current(0),
7  d_size(0) {}
8 
9 IntList::IntList( const IntList& olist) :
10  d_size(olist.d_size) {
11 
12  // just add all the list
13  Elem* oelem = olist.d_first;
14  Elem* prev(0);
15  while( oelem ){
16  Elem *nelem = new IntList::Elem( oelem->d_val );
17  if( prev ){
18  prev->d_next = nelem;
19  }
20  else {
21  d_first = nelem;
22  }
23  prev = nelem;
24  oelem = oelem->d_next;
25  }
27 }
28 
29 
31  if( d_first ) delete d_first;
32 }
33 
34 const IntList& IntList::operator=( const IntList& olist){
35 
36  if( d_first ) delete d_first;
37 
38  d_size = olist.d_size;
39  // just add all the list
40  Elem* oelem = olist.d_first;
41  Elem* prev(0);
42  while( oelem ){
43  Elem *nelem = new IntList::Elem( oelem->d_val );
44  if( prev ){
45  prev->d_next = nelem;
46  }
47  else {
48  d_first = nelem;
49  }
50  prev = nelem;
51  oelem = oelem->d_next;
52  }
54  return *this;
55 }
56 
57 void IntList::append(int val){
58 
59  Elem* bef(0);
60  Elem* af( d_first );
61  while( af ){
62  bef = af;
63  af = af->d_next;
64  }
65  if( bef ){
66  bef->d_next = new IntList::Elem( val );
67  }
68  else {
69  d_first = new Elem( val );
71  }
72  d_size++;
73 }
74 
76 
77  int val = d_current->d_val;
78 
79  d_size--;
80 
81  Elem* bef(0);
82  Elem* af( d_first );
83  while( af != d_current){
84  bef = af;
85  af = af->d_next;
86  }
87  if( !bef ){
89  }
90  else {
91  bef->d_next = d_current->d_next;
92  }
94  af->d_next = 0;
95  delete af;// the old current - remove only it
96  if( !d_current ) d_current = d_first;
97  return val;
98 }
99 
100 
101 
102 boolean IntList::move_to(int val){
103  d_current = d_first;
104  while( d_current && d_current->d_val != val ){
106  }
107  return( d_current ? TRUE : FALSE );
108 }
109 
110 int IntList::index() const {
111 
112  int ind = 0;
113  Elem* pass = d_first;
114  while( pass != d_current ){
115  ind++;
116  pass = pass->d_next;
117  }
118  return ind;
119 }
120 
121 void IntList::index( int ind ){
122 
123  d_current = d_first;
124  int i;
125  for( i = 0; i < ind; i++ ){
127  }
128 }
129 
130 
#define FALSE
Definition: vinci.h:133
Elem * d_first
Definition: IntList.hpp:48
Elem * d_next
Definition: IntList.hpp:37
IntList()
Definition: IntList.cpp:4
boolean move_to(int ed)
Definition: IntList.cpp:102
~IntList()
Definition: IntList.cpp:30
Elem * d_current
Definition: IntList.hpp:49
int remove()
Definition: IntList.cpp:75
blockLoc i
Definition: read.cpp:79
#define TRUE
Definition: vinci.h:134
const IntList & operator=(const IntList &olist)
Definition: IntList.cpp:34
int d_size
Definition: IntList.hpp:51
void append(int ed)
Definition: IntList.cpp:57
int index() const
Definition: IntList.cpp:110