MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SharedFinfo.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2003-2010 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 #include "header.h"
10 
16 SharedFinfo::SharedFinfo( const string& name, const string& doc,
17  Finfo** entries, unsigned int numEntries )
18  : Finfo( name, doc )
19 {
20  for ( unsigned int i = 0; i < numEntries; ++i )
21  {
22  Finfo* foo = entries[i];
23  SrcFinfo* s = dynamic_cast< SrcFinfo* >( foo );
24  // SrcFinfo* s = dynamic_cast< SrcFinfo* >( entries[i] );
25  if ( s != 0 )
26  src_.push_back( s );
27  else
28  dest_.push_back( entries[i] );
29  }
30 }
31 
33 {
34  for( vector< SrcFinfo* >::iterator i =
35  src_.begin(); i != src_.end(); ++i)
36  c->registerFinfo( *i );
37  for( vector< Finfo* >::iterator i =
38  dest_.begin(); i != dest_.end(); ++i)
39  c->registerFinfo( *i );
40 }
41 
43  const Eref& tgt, const string& field, const string& arg ) const
44 {
45  return 0;
46 }
47 
49  const Eref& tgt, const string& field, string& returnValue ) const
50 {
51  return 0;
52 }
53 
60 /*
61 void SharedFinfo::registerOpFuncs(
62  map< string, FuncId >& fnames, vector< OpFunc* >& funcs )
63 {
64  for ( unsigned int i = 0; i < dest_.size(); ++i )
65  dest_[i]->registerOpFuncs( fnames, funcs );
66 }
67 
68 BindIndex SharedFinfo::registerBindIndex( BindIndex current )
69 {
70  return current;
71 }
72 */
73 
74 bool SharedFinfo::checkTarget( const Finfo* target ) const
75 {
76  const SharedFinfo* tgt = dynamic_cast< const SharedFinfo* >( target );
77  if ( tgt ) {
78  if ( src_.size() != tgt->dest_.size() &&
79  dest_.size() != tgt->src_.size() )
80  return 0;
81  for ( unsigned int i = 0; i < src_.size(); ++i ) {
82  if ( !src_[i]->checkTarget( tgt->dest_[i] ) )
83  return 0;
84  }
85  for ( unsigned int i = 0; i < tgt->src_.size(); ++i ) {
86  if ( !tgt->src_[i]->checkTarget( dest_[i] ) )
87  return 0;
88  }
89 
90  return 1;
91  }
92  return 0;
93 }
94 
95 bool SharedFinfo::addMsg( const Finfo* target, ObjId mid,
96  Element* srcElm ) const
97 {
98  if ( !checkTarget( target ) )
99  return 0;
100  const SharedFinfo* tgt = dynamic_cast< const SharedFinfo* >( target );
101 
102  // We have a problem if the src and dest elms (e1 and e2) are the
103  // same, because this messes up the logic to assign the isForward flag.
104  // This is an issue only if the target Finfo wants to send data back.
105  // In other words, there are dest_ finfos on this SharedFinfo.
106  // Report this problem.
107  const Msg* m = Msg::getMsg( mid );
108  assert( m->e1() == srcElm );
109  Element* destElm = m->e2();
110  if ( srcElm == destElm && srcElm->id() != Id() ) {
111  if ( dest_.size() > 0 ) {
112  cout << "Error: SharedFinfo::addMsg: MessageId " << mid <<
113  endl <<
114  "Source Element == DestElement == " << srcElm->getName() <<
115  endl << "Recommend that you individually set up messages for" <<
116  " the components of the SharedFinfo, to ensure that the " <<
117  "direction of messaging is consistent.\n";
118  return 0;
119  }
120  }
121 
122 
123  for ( unsigned int i = 0; i < src_.size(); ++i ) {
124  if ( !src_[i]->addMsg( tgt->dest_[i], mid, srcElm ) ) {
125  // Should never happen. The checkTarget should preclude this.
126  cerr << "Error:SharedFinfo::addMsg: Failed on MessageId " <<
127  mid << ", unrecoverable\n";
128  exit(0);
129  }
130  }
131 
132 
133  for ( unsigned int i = 0; i < tgt->src_.size(); ++i ) {
134  if ( !tgt->src_[i]->addMsg( dest_[i], mid, destElm ) ) {
135  // Should never happen. The checkTarget should preclude this.
136  cerr << "Error:SharedFinfo::addMsg: Failed on MessageId " <<
137  mid << ", unrecoverable\n";
138  exit( 0 );
139  }
140  }
141  return 1;
142 }
143 
144 const vector< SrcFinfo* >& SharedFinfo::src() const
145 {
146  return src_;
147 }
148 
149 
150 const vector< Finfo* >& SharedFinfo::dest() const
151 {
152  return dest_;
153 }
154 
156 // overridden default virtual funcs for internal set/get names
158 vector< string > SharedFinfo::innerSrc() const
159 {
160  vector< string > ret;
161  for ( vector< SrcFinfo* >::const_iterator i = src_.begin();
162  i != src_.end(); ++i )
163  ret.push_back( (*i)->name() );
164  return ret;
165 }
166 
167 vector< string > SharedFinfo::innerDest() const
168 {
169  vector< string > ret;
170  for ( vector< Finfo* >::const_iterator i = dest_.begin();
171  i != dest_.end(); ++i )
172  ret.push_back( (*i)->name() );
173  return ret;
174 }
175 
176 string SharedFinfo::rttiType() const
177 {
178  return "void";
179 }
Element * e2() const
Definition: Msg.h:68
string rttiType() const
This always returns void. We need to check the subsidiary Finfos.
const vector< Finfo * > & dest() const
bool addMsg(const Finfo *target, ObjId mid, Element *src) const
Definition: SharedFinfo.cpp:95
const vector< SrcFinfo * > & src() const
vector< string > innerDest() const
Definition: ObjId.h:20
const int numEntries
Definition: proc.cpp:60
vector< string > innerSrc() const
Id id() const
Definition: Element.cpp:71
void registerFinfo(Cinfo *c)
Definition: SharedFinfo.cpp:32
void registerFinfo(Finfo *f)
Definition: Cinfo.cpp:114
bool strSet(const Eref &tgt, const string &field, const string &arg) const
Definition: SharedFinfo.cpp:42
Definition: Eref.h:26
Definition: Msg.h:18
Element * e1() const
Definition: Msg.h:61
vector< SrcFinfo * > src_
Definition: SharedFinfo.h:59
static char name[]
Definition: mfield.cpp:401
SharedFinfo(const string &name, const string &doc, Finfo **entries, unsigned int numEntries)
Definition: SharedFinfo.cpp:16
Definition: Id.h:17
bool checkTarget(const Finfo *target) const
Definition: SharedFinfo.cpp:74
static const Msg * getMsg(ObjId m)
Definition: Msg.cpp:59
bool strGet(const Eref &tgt, const string &field, string &returnValue) const
Definition: SharedFinfo.cpp:48
vector< Finfo * > dest_
Definition: SharedFinfo.h:60
const string & getName() const
Definition: Element.cpp:56
Definition: Cinfo.h:18
Definition: Finfo.h:12