ElementData.cc 1.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


13
#include "ElementData.h"
14

15
16
namespace AMDiS {

17
18
19
20
21
  void ElementData::coarsenElementData(Element* parent, 
				       Element* thisChild,
				       Element* otherChild,
				       int elTypeParent) 
  {
22
23
24
25
    if (decorated) {
      decorated->coarsenElementData(parent, thisChild, otherChild, elTypeParent);
      delete decorated;
      decorated = NULL;
26
27
28
29
30
    }
  }

  bool ElementData::deleteDecorated(int typeID)
  {
31
32
33
34
    if (decorated) {
      if (decorated->isOfType(typeID)) {
	ElementData *tmp = decorated;
	decorated = decorated->decorated;
35
36
37
38
	delete tmp;
	tmp = NULL;
	return true;
      } else {
39
	return decorated->deleteDecorated(typeID);
40
41
42
43
44
45
46
      }
    } 
    return false;    
  }

  void ElementData::deleteDecorated()
  {
47
48
49
    if (decorated) {
      decorated->deleteDecorated();
      delete decorated;
50
51
52
53
54
55
56
57
58
    }
  }
  
  ElementData::~ElementData()
  {
  }

  void ElementData::serialize(std::ostream& out) 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
59
    std::string decoratedType;
60
61
    if (decorated) {
      decoratedType = decorated->getTypeName();
Thomas Witkowski's avatar
Thomas Witkowski committed
62
      out << decoratedType << "\n";
63
      decorated->serialize(out);
64
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
65
      out << "NULL\n";
66
67
68
    }
  }

69
70
  void ElementData::deserialize(std::istream& in) 
  {
71
    TEST_EXIT(decorated == NULL)
72
      ("there are already decorated element data\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
73
    std::string decoratedType;
74
75
    in >> decoratedType; 
    in.get();
76
    if (decoratedType != "NULL") {
77
78
      decorated = 
	CreatorMap<ElementData>::getCreator(decoratedType, "deserialization from file")->create();
79
      decorated->deserialize(in);
80
    } else {
81
      decorated = NULL;
82
    }
83
84
85
  }

}