source: trunk/examples/extended/parallel/ParN04/include/MarshaledG4String.h@ 810

Last change on this file since 810 was 807, checked in by garnier, 17 years ago

update

File size: 3.6 KB
Line 
1// This file was generated automatically by marshalgen.
2
3#ifndef MarshaledG4String_H
4#define MarshaledG4String_H
5
6
7#include <G4String.hh>
8
9
10#include <stdio.h>
11#include <string.h>
12#include "MarshaledObj.h"
13
14 class MarshaledG4String;
15
16 class ShadowedMarshaledG4String : public G4String{
17 friend class MarshaledG4String;
18};
19
20 class MarshaledG4String : public MarshaledObj {
21public:
22 G4String* param;
23 ShadowedMarshaledG4String* Shadowed_param;
24public:
25
26
27// Function implementations
28
29MarshaledG4String(G4String* objptr) : MarshaledObj() {
30 msh_isUnmarshalDone = false;
31 this->param = objptr;
32 this->Shadowed_param = (ShadowedMarshaledG4String*)this->param;
33 if (objptr == NULL)
34 return;
35
36 marshal1();
37}
38
39MarshaledG4String(void *buf, char isUnmarshaling = 'u')
40: MarshaledObj(buf, isUnmarshaling) {
41 msh_isUnmarshalDone = false;
42}
43
44~MarshaledG4String() {
45 //if(msh_isUnmarshalDone && this->param != NULL) {
46 //delete this->param;
47 //}
48}
49
50G4String* unmarshal() {
51 //We don't want to unmarshal the buffer is empty.
52 if(msh_size <= MSH_HEADER_SIZE) {
53 //This is buggy, we can't always assume that
54 //obj == NULL <==> List is empty.
55 return NULL;
56 } else {
57 {
58 param = new G4String();
59 }
60 this->Shadowed_param = (ShadowedMarshaledG4String*)this->param;
61 this->msh_isUnmarshalDone = true;
62 unmarshal1();
63 return this->param;
64 }
65}
66
67void unmarshalTo(G4String* obj) {
68 //We don't want to unmarshal the buffer is empty.
69 if(msh_size <= MSH_HEADER_SIZE) {
70 //This is buggy, we can't always assume that
71 //obj == NULL <==> List is empty.
72 return;
73 } else {
74 this->param = obj;
75 this->Shadowed_param = (ShadowedMarshaledG4String*)this->param;
76 this->msh_isUnmarshalDone = true;
77 unmarshal1();
78 }
79}
80
81void marshal1() {
82 //declare field_size to be the size of this field
83 int msh_currentSize = 0;
84 if (isUnmarshaling())
85 throw "Tried to marshal in obj marked isUnmarshaling == true";
86
87 //Copy the sizespec into msh_currentSize here:
88 {
89 int size = param->size()+1;
90 while(size%8) size++;
91 msh_currentSize = size;
92 }
93
94 //Increase the size of buffer if needed
95 EXTEND_BUFFER(msh_currentSize + sizeof(int) + sizeof(int)); // 4 bytes for the total size of field, 4 bytes for the number of elements in the array (in the case of array marshaling)
96 //Mark the beginning position for this field, will write the total size of this field here later
97 msh_field_begin = msh_cursor;
98
99 //Advance cursor of distance = sizeof(int)
100 msh_cursor += sizeof(int);
101
102 //Now just copy "get" functions here
103 {
104 memcpy(msh_cursor, param->c_str(), param->size());
105 *(msh_cursor+param->size()) = '\0';
106
107 }
108 //Now advance the cursor
109 msh_cursor += msh_currentSize;
110 //Now set the size of this field
111 int tmp; //use memcpy instead of *(int*)... =... to prevent bus error
112 tmp = (msh_cursor-msh_field_begin) - sizeof(int);
113 memcpy(msh_field_begin, &tmp, sizeof(int));
114
115 //Now set msh_size
116 msh_size = msh_cursor - msh_buffer;
117 MSH_SET_TOTALSIZE(msh_size); MSH_SET_TYPECHOICE(msh_typechoice);
118}
119
120void unmarshal1() {
121 //declare currentSize to be the size of this field
122 int msh_currentSize = 0;
123 //copy the size of the current field into currentSize
124 memcpy(&msh_currentSize, msh_cursor, sizeof(int));
125 msh_cursor += sizeof(int);
126 //Now copy the setspec here
127 {
128 G4String* s = new G4String(msh_cursor);
129 memcpy(param, s, sizeof(G4String));
130
131 }
132 msh_cursor += msh_currentSize;
133}
134
135};
136#endif
137
Note: See TracBrowser for help on using the repository browser.