ElInfoStack.cc 1.23 KB
Newer Older
Thomas Witkowski's avatar
Thomas Witkowski committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "ElInfoStack.h"
#include "Mesh.h"

namespace AMDiS {
  
  ElInfoStack::ElInfoStack(Mesh *mesh) 
    : mesh_(mesh),
      stackPosition_(-1)
  {
    elInfoStack_.resize(20);
    for (int i = 0; i < 20; i++) {
      elInfoStack_[i] = mesh_->createNewElInfo();
    }
  }

  ElInfoStack::~ElInfoStack()
  {
    for (int i = 0; i < static_cast<int>(elInfoStack_.size()); i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
19
      delete elInfoStack_[i];
Thomas Witkowski's avatar
Thomas Witkowski committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    }     
  }

  ElInfo* ElInfoStack::getNextElement()
  {
    // Check if the stack if large enough. If not, the stack is enlarged
    // and new elements are created.
    if (stackPosition_ + 1 >= static_cast<int>(elInfoStack_.size())) {
      int oldSize = elInfoStack_.size();
      elInfoStack_.resize(oldSize + oldSize / 2);
      for (int i = oldSize; i < static_cast<int>(elInfoStack_.size()); i++) {
	elInfoStack_[i] = mesh_->createNewElInfo();
      }
    }

    stackPosition_++;
    
    return elInfoStack_[stackPosition_];
  }

  void ElInfoStack::getBackElement()
  {
    TEST_EXIT_DBG(stackPosition_ >= 0)("Invalid stack position!\n");

    stackPosition_--;
  }

  ElInfo* ElInfoStack::getCurrentElement()
  {
    TEST_EXIT_DBG(stackPosition_ >= 0)("Invalid stack position!\n");
    
    return elInfoStack_[stackPosition_];
  }
}