ElementData.cc 1.55 KB
Newer Older
1
#include "MemoryManager.h"
2
3
4
5
#include "ElementData.h"

namespace AMDiS {

6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
  void ElementData::coarsenElementData(Element* parent, 
				       Element* thisChild,
				       Element* otherChild,
				       int elTypeParent) 
  {
    if (decorated_) {
      decorated_->coarsenElementData(parent, thisChild, otherChild, elTypeParent);
      delete decorated_;
      decorated_ = NULL;
    }
  }

  bool ElementData::deleteDecorated(int typeID)
  {
    if (decorated_) {
      if (decorated_->isOfType(typeID)) {
	ElementData *tmp = decorated_;
	decorated_ = decorated_->decorated_;
	delete tmp;
	tmp = NULL;
	return true;
      } else {
	return decorated_->deleteDecorated(typeID);
      }
    } 
    return false;    
  }

  void ElementData::deleteDecorated()
  {
    if (decorated_) {
      decorated_->deleteDecorated();
      DELETE decorated_;
    }
  }
  
  ElementData::~ElementData()
  {
  }

  void ElementData::serialize(std::ostream& out) 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
48
    std::string decoratedType;
49
    if (decorated_) {
50
      decoratedType = decorated_->getTypeName();
Thomas Witkowski's avatar
Thomas Witkowski committed
51
      out << decoratedType << "\n";
52
53
      decorated_->serialize(out);
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
54
      out << "NULL\n";
55
56
57
    }
  }

58
59
  void ElementData::deserialize(std::istream& in) 
  {
60
61
    TEST_EXIT(decorated_ == NULL)
      ("there are already decorated element data\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
62
    std::string decoratedType;
63
64
    in >> decoratedType; 
    in.get();
65
    if (decoratedType != "NULL") {
66
67
68
69
      decorated_ = CreatorMap<ElementData>::getCreator(decoratedType)->create();
      decorated_->deserialize(in);
    } else {
      decorated_ = NULL;
70
    }
71
72
73
  }

}