Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IntList.hpp
Go to the documentation of this file.
1 #ifndef INTLIST_HPP
2 #define INTLIST_HPP
3 
4 #include "general.hpp"
5 #include <assert.h>
6 
7 class IntList {
8 public:
9 
10  IntList();
11  IntList( const IntList& olist );
12  ~IntList();
13 
14  const IntList& operator=( const IntList& olist);
15 
16  void append(int ed);
17  void insert(int ed);
18  void insert_first(int ed);
19 
20  void reset();
21  void next();
22 
23  int& get();
24  int remove();
25 
26  boolean empty();
27  int size();
28 
29  boolean move_to(int ed);
30  int index() const;
31  void index( int ind );
32 
33 private:
34 
35  struct Elem {
36  int d_val;
38 
39  Elem() : d_val(0), d_next(0) {}
40  Elem(int val, Elem* next = 0) :
41  d_val(val), d_next(next) {}
42 
43  ~Elem() {
44  if( d_next ) delete d_next;
45  }
46  };
47 
50 
51  int d_size;
52 };
53 
54 
55 inline void IntList::insert(int val) { // at d_current
56  assert( d_current || !d_first);
57  d_size++;
58  if( !d_current ){
59  d_first = new IntList::Elem( val );
61  return;
62  }
63  d_current->d_next = new Elem( val, d_current->d_next);
64 }
65 
66 inline void IntList::insert_first(int val) { // at d_current
67  d_size++;
68  d_first = new IntList::Elem( val, d_first);
70 }
71 
72 
73 inline void IntList::reset() {
75 }
76 
77 inline void IntList::next() {
79  if( !d_current ){
81  }
82 }
83 
84 inline int& IntList::get() {
85  return d_current->d_val;
86 }
87 
88 inline boolean IntList::empty(){
89  return ( d_size <= 0 ? TRUE : FALSE);
90 }
91 
92 inline int IntList::size(){
93  return d_size;
94 }
95 
96 
97 #endif
98 
99 
100 
101 
#define FALSE
Definition: vinci.h:133
Elem(int val, Elem *next=0)
Definition: IntList.hpp:40
Elem * d_first
Definition: IntList.hpp:48
Elem * d_next
Definition: IntList.hpp:37
int & get()
Definition: IntList.hpp:84
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
void insert(int ed)
Definition: IntList.hpp:55
int size()
Definition: IntList.hpp:92
#define TRUE
Definition: vinci.h:134
boolean empty()
Definition: IntList.hpp:88
void insert_first(int ed)
Definition: IntList.hpp:66
void reset()
Definition: IntList.hpp:73
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
void next()
Definition: IntList.hpp:77