NeoPZ
TPZMatWithMemTranslator.h
Go to the documentation of this file.
1 /*
2  * File: TPZMatWithMemTranslator.h
3  * Author: thiago
4  *
5  * Created on 12 de Março de 2018, 18:43
6  */
7 
8 #ifndef TPZMATWITHMEMTRANSLATOR_H
9 #define TPZMATWITHMEMTRANSLATOR_H
10 
11 #include "TPZMaterialTranslator.h"
12 #include "TPZChunkInTranslation.h"
13 #include "Hash/TPZHash.h"
14 
15 template <class TMEMTranslator, class TFatherTranslator = TPZMaterialTranslator>
16 class TPZMatWithMemTranslator : public TFatherTranslator {
17 public:
20 
21  virtual void UpdateStream(TPZChunkInTranslation& chunk, const std::map<std::string, uint64_t>& toVersion);
22 
23  virtual void UpdateAttributes(TPZChunkInTranslation& chunk, const std::map<std::string, uint64_t>& toVersion);
24 
25  virtual ~TPZMatWithMemTranslator();
26 private:
27  void UpdateAttributesV3(TPZChunkInTranslation& chunk, const std::map<std::string, uint64_t>& toVersion);
28  void UpdateFromV3(TPZChunkInTranslation& chunk, const std::map<std::string, uint64_t>& toVersion);
29 
30  TMEMTranslator tMEMTranslator;
31  TFatherTranslator parentTranslator;
32 };
33 
34 template <class TMEMTranslator, class TFatherTranslator>
36 }
37 
38 template <class TMEMTranslator, class TFatherTranslator>
40 }
41 
42 template <class TMEMTranslator, class TFatherTranslator>
43 void TPZMatWithMemTranslator<TMEMTranslator, TFatherTranslator>::UpdateStream(TPZChunkInTranslation& chunk, const std::map<std::string, uint64_t>& toVersion) {
44  auto old_version = chunk.mOldVersion["NeoPZ"];
45  auto new_version = toVersion.at("NeoPZ");
46  switch (old_version) {
47  case 1:
48  case 2:
49  if (new_version <= 3) {
50  UpdateAttributesV3(chunk, toVersion);
51  break;
52  } else {
53  DebugStop();
54  }
55  case 3:
56  if (new_version == 3) {
57  UpdateAttributesV3(chunk, toVersion);
58  } else {
59  UpdateFromV3(chunk, toVersion);
60  }
61  break;
62  default:
63  UpdateAttributes(chunk, toVersion);
64  break;
65  }
66 }
67 
68 template <class TMEMTranslator, class TFatherTranslator>
69 void TPZMatWithMemTranslator<TMEMTranslator, TFatherTranslator>::UpdateAttributesV3(TPZChunkInTranslation& chunk, const std::map<std::string, uint64_t>& toVersion) {
70  parentTranslator.UpdateStream(chunk, toVersion);
71  int updatemem;
72  chunk.mOldStream.Read(&updatemem);
73  chunk.mNewStream.Write(&updatemem);
74  tMEMTranslator.UpdateStream(chunk, toVersion);
75  int i, size;
76  chunk.mOldStream.Read(&size);
77  chunk.mNewStream.Write(&size);
78  for (i = 0; i < size; i++) {
79  tMEMTranslator.UpdateStream(chunk, toVersion); //fMemory[i]
80  }
81 }
82 
83 template <class TMEMTranslator, class TFatherTranslator>
84 void TPZMatWithMemTranslator<TMEMTranslator, TFatherTranslator>::UpdateFromV3(TPZChunkInTranslation& chunk, const std::map<std::string, uint64_t>& toVersion) {
85  parentTranslator.UpdateStream(chunk, toVersion);
86  int updatemem;
87  chunk.mOldStream.Read(&updatemem);
88  chunk.mNewStream.Write(&updatemem);
89  tMEMTranslator.UpdateStream(chunk, toVersion);
90  int size;
91  chunk.mOldStream.Read(&size);
93  chunk.mNewStream.Write(&objId);
94  int admChunkVectorClassId = Hash("TPZAdmChunkVector") ^ (Hash("TPZChunkVector") ^ tMEMTranslator.GetClassId() << 1 ^ (10 << 2)) << 1;
95  TPZAutoPointer<TPZChunkInTranslation> admChunkVectorChunk = new TPZChunkInTranslation(objId, admChunkVectorClassId, chunk.mOldStream, chunk.mOldVersion);
96  TPZPersistenceManager::SetChunk(objId, admChunkVectorChunk);
97  uint64_t size_64 = size;
98  admChunkVectorChunk->mNewStream.Write(&size_64);
99  for (int i = 0; i < size; i++) {
100  tMEMTranslator.UpdateStream(*admChunkVectorChunk, toVersion); //fMemory[i]
101  }
102  chunk.mOldStream = admChunkVectorChunk->mOldStream;
103  admChunkVectorChunk->mOldStream.clear();
104  int compactScheme = 0;
105  admChunkVectorChunk->mNewStream.Write(&compactScheme);
106  {
107  int64_t nel = 0;
108  admChunkVectorChunk->mNewStream.Write(&nel);
109  }//TPZStack<int> fFree;
110  {
111  int64_t nel = 0;
112  admChunkVectorChunk->mNewStream.Write(&nel);
113  } //TPZManVector<int> fNFree;
114  chunk.mNewObjIds.push_back(objId);
115 }
116 
117 template <class TMEMTranslator, class TFatherTranslator>
118 void TPZMatWithMemTranslator<TMEMTranslator, TFatherTranslator>::UpdateAttributes(TPZChunkInTranslation& chunk, const std::map<std::string, uint64_t>& toVersion) {
119  parentTranslator.UpdateStream(chunk, toVersion);
120  int updatemem;
121  chunk.mOldStream.Read(&updatemem);
122  chunk.mNewStream.Write(&updatemem);
123  tMEMTranslator.UpdateStream(chunk, toVersion);
124  TPZPersistenceManager::TranslateNextPointer(chunk, toVersion); //fMemory[i]
125 }
126 
127 template <class TMEMTranslator, class TFatherTranslator>
129 }
130 
131 
132 
133 #endif /* TPZMATWITHMEMTRANSLATOR_H */
134 
void UpdateAttributesV3(TPZChunkInTranslation &chunk, const std::map< std::string, uint64_t > &toVersion)
virtual void Read(int *p, int howMany=1)
static void TranslateNextPointer(TPZChunkInTranslation &chunk, const std::map< std::string, uint64_t > &toVersion)
virtual void UpdateStream(TPZChunkInTranslation &chunk, const std::map< std::string, uint64_t > &toVersion)
virtual void UpdateAttributes(TPZChunkInTranslation &chunk, const std::map< std::string, uint64_t > &toVersion)
virtual void Write(const int *p, int howMany=1)
static int64_t NewChunkInTranslation()
std::map< std::string, uint64_t > mOldVersion
static void SetChunk(const int64_t &objId, TPZAutoPointer< TPZChunkInTranslation > chunk)
TPZStack< int64_t, 2 > mNewObjIds
TPZContBufferedStream mOldStream
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
void UpdateFromV3(TPZChunkInTranslation &chunk, const std::map< std::string, uint64_t > &toVersion)
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
TFatherTranslator parentTranslator
void push_back(const T object)
Definition: pzstack.h:48
TPZContBufferedStream mNewStream