xc
MovablePointerContainer.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // XC program; finite element analysis code
4 // for structural analysis and design.
5 //
6 // Copyright (C) Luis C. Pérez Tato
7 //
8 // This program derives from OpenSees <http://opensees.berkeley.edu>
9 // developed by the «Pacific earthquake engineering research center».
10 //
11 // Except for the restrictions that may arise from the copyright
12 // of the original program (see copyright_opensees.txt)
13 // XC is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // This software is distributed in the hope that it will be useful, but
19 // WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program.
26 // If not, see <http://www.gnu.org/licenses/>.
27 //----------------------------------------------------------------------------
28 //MovablePointerContainer
29 
30 
31 #ifndef MovablePointerContainer_h
32 #define MovablePointerContainer_h
33 
34 #include "MovableObject.h"
35 #include "Communicator.h"
36 
37 namespace XC {
38 
40 //
42 template <class T>
44  {
45  protected:
46  T *(FEM_ObjectBroker::*ptrFunc)(int);
47 
48  DbTagData &getDbTagData(void) const;
49  T *getBrokedObject(const int &,const int &,const Communicator &);
50  virtual int sendData(Communicator &)= 0;
51  virtual int recvData(const Communicator &)= 0;
52  public:
53  MovablePointerContainer(const int &, T *(FEM_ObjectBroker::*pF)(int));
54  int sendSelf(Communicator &);
55  int recvSelf(const Communicator &);
56  };
57 
58 
60 template <class T>
62  :MovableObject(classTag), ptrFunc(pF) {}
63 
66 template <class T>
68  {
69  static DbTagData retval(5);
70  return retval;
71  }
72 
74 template <class T>
75 T *XC::MovablePointerContainer<T>::getBrokedObject(const int &dbTag,const int &classTag,const Communicator &comm)
76  { return getBrokedMovable(dbTag,classTag,comm,this->ptrFunc); }
77 
79 template <class T>
81  {
82  inicComm(5);
83  int result= this->sendData(comm);
84 
85  const int dataTag= getDbTag(comm);
86  result+= comm.sendIdData(getDbTagData(),dataTag);
87  if(result < 0)
88  std::cerr << "MovablePointerContainer::sendSelf() - failed to send data\n";
89  return result;
90  }
91 
93 template <class T>
95  {
96  inicComm(5);
97  const int dataTag = getDbTag();
98  int result= comm.receiveIdData(getDbTagData(),dataTag);
99  if(result<0)
100  std::cerr << "MovablePointerContainer::recvSelf() - failed to receive data\n";
101  else
102  result+= recvData(comm);
103  return result;
104  }
105 
106 } // end of XC namespace
107 
108 #endif
109 
int sendIdData(const DbTagData &, const int &)
Sends miembro data through the communicator argument.
Definition: Communicator.cc:411
T * getBrokedMovable(const int &dbTag, const int &classTag, const Communicator &comm, T *(FEM_ObjectBroker::*ptrFunc)(int))
Returns an empty object of the class identified by classTag.
Definition: MovableObject.h:152
Communication parameters between processes.
Definition: Communicator.h:66
Object that can move between processes.
Definition: MovableObject.h:100
Vector that stores the dbTags of the class members.
Definition: DbTagData.h:44
Template class for maps that can move between processes.
Definition: MovablePointerContainer.h:43
FEM_ObjectBroker is is an object broker class for the finite element method.
Definition: FEM_ObjectBroker.h:151
T * getBrokedObject(const int &, const int &, const Communicator &)
Returns an empty object of the class identified by classTag.
Definition: MovablePointerContainer.h:75
int recvSelf(const Communicator &)
Receives object through the communicator argument.
Definition: MovablePointerContainer.h:94
MovablePointerContainer(const int &, T *(FEM_ObjectBroker::*pF)(int))
Constructor.
Definition: MovablePointerContainer.h:61
int receiveIdData(DbTagData &, const int &) const
Receives el miembro data through the communicator argument.
Definition: Communicator.cc:415
DbTagData & getDbTagData(void) const
Returns a vector to store the dbTags of the class members.
Definition: MovablePointerContainer.h:67
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
void inicComm(const int &dataSize) const
Initializes communication.
Definition: DistributedBase.cc:61
int getDbTag(void) const
Return the object identifier in the database.
Definition: MovableObject.cpp:99
int sendSelf(Communicator &)
Send the object through the communicator argument.
Definition: MovablePointerContainer.h:80