PlasCom2  1.0
XPACC Multi-physics simluation application
MobileParameters.C
Go to the documentation of this file.
1 #include "MobileParameters.H"
7 
8 
9 namespace ix {
10  namespace app {
11 
12  int MobileParameters::Pack(void **inbuf)
13  {
14  if(_buf && _mine){
15  delete [] (char *)_buf;
16  _buf = NULL;
17  _mine = false;
18  }
19  std::ostringstream Ostr;
20  Ostr << *this << std::endl;
21  if(!inbuf){
22  int nchar = util::String2Buf(Ostr.str(),&_buf);
23  if(_buf){
24  _mine = true;
25  return(nchar);
26  }
27  }
28  else {
29  // Caller must free inbuf, else it leaks
30  int nchar = util::String2Buf(Ostr.str(),inbuf);
31  if(*inbuf){
32  _buf = *inbuf;
33  _mine = false;
34  return(nchar);
35  }
36  }
37  return 0;
38  };
39 
40  int MobileParameters::UnPack(const void *inbuf)
41  {
42  if(!inbuf){
43  if(!_buf)
44  return 1;
45  std::string bufString((const char *)_buf,(const char *)_buf+_bsize);
46  std::istringstream Istr(bufString);
47  Istr >> *this;
48  if(_mine){
49  delete [] (char *)_buf;
50  _buf = NULL;
51  _mine = false;
52  _bsize = 0;
53  }
54  return(0);
55  }
56  else{
57  std::string bufString((const char *)inbuf);
58  std::istringstream Istr(bufString);
59  Istr >> *this;
60  return(0);
61  }
62  return 0;
63  }
64 
65  int MobileString::Pack(void **inbuf)
66  {
67  if(_buf && _mine){
68  delete [] (char *)_buf;
69  _buf = NULL;
70  _mine = false;
71  }
72  std::ostringstream Ostr;
73  Ostr << " " << *this << " ";
74  if(!inbuf){
75  int nchar = util::String2Buf(Ostr.str(),&_buf);
76  if(_buf){
77  _mine = true;
78  return(nchar);
79  }
80  }
81  else {
82  // Caller must free inbuf, else it leaks
83  int nchar = util::String2Buf(Ostr.str(),inbuf);
84  if(*inbuf){
85  _buf = *inbuf;
86  _mine = false;
87  return(nchar);
88  }
89  }
90  return 0;
91  };
92 
93  int MobileString::UnPack(const void *inbuf)
94  {
95  if(!inbuf){
96  if(!_buf)
97  return 1;
98  std::istringstream Istr(std::string((const char *)_buf));
99  Istr >> *this;
100  if(_mine){
101  delete [] (char *)_buf;
102  _buf = NULL;
103  _mine = false;
104  }
105  return(0);
106  }
107  else{
108  std::istringstream Istr(std::string((const char *)inbuf));
109  Istr >> *this;
110  return(0);
111  }
112  return 0;
113  }
114 }
115 }
virtual int Pack(void **=NULL)
Defines MPI-specific parallel global and program classes.
Mobile parameters object.
virtual int UnPack(const void *=NULL)
virtual int UnPack(const void *=NULL)
int String2Buf(const std::string &instr, void **buf)
virtual int Pack(void **=NULL)