MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SetGet.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-2009 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 
10 #include "header.h"
11 #include "SetGet.h"
12 #include "../shell/Shell.h"
13 #include "../shell/Neutral.h"
14 
16  const string& field, ObjId& tgt, FuncId& fid )
17 {
18  // string field = "set_" + destField;
19  const Finfo* f = tgt.element()->cinfo()->findFinfo( field );
20  if ( !f ) { // Could be a child element? Note that field name will
21  // change from set_<name> to just <name>
22  string f2 = field.substr( 3 );
23  Id child = Neutral::child( tgt.eref(), f2 );
24  if ( child == Id() ) {
25  cout << "Error: SetGet:checkSet:: No field or child named '" <<
26  field << "' was found on\n" << tgt.id.path() << endl;
27  } else {
28  if ( field.substr( 0, 3 ) == "set" )
29  f = child.element()->cinfo()->findFinfo( "setThis" );
30  else if ( field.substr( 0, 3 ) == "get" )
31  f = child.element()->cinfo()->findFinfo( "getThis" );
32  assert( f ); // should always work as Neutral has the field.
33  if ( child.element()->numData() == tgt.element()->numData() ) {
34  tgt = ObjId( child, tgt.dataIndex, tgt.fieldIndex );
35  if ( !tgt.isDataHere() )
36  return 0;
37  } else if ( child.element()->numData() <= 1 ) {
38  tgt = ObjId( child, 0 );
39  if ( !tgt.isDataHere() )
40  return 0;
41  } else {
42  cout << "SetGet::checkSet: child index mismatch\n";
43  return 0;
44  }
45  }
46  }
47 
48  const DestFinfo* df = dynamic_cast< const DestFinfo* >( f );
49  if ( !df )
50  return 0;
51 
52  fid = df->getFid();
53  const OpFunc* func = df->getOpFunc();
54  assert( func );
55  return func;
56 
57  /*
58  // This is the crux of the function: typecheck for the field.
59  // if ( func->checkSet( this ) )
60  if ( checkOpClass( func ) ) {
61  return func;
62  } else {
63  cout << "set::Type mismatch" << oid_ << "." << field << endl;
64  return 0;
65  }
66  */
67 }
68 
70 
71 // Static function
72 bool SetGet::strGet( const ObjId& tgt, const string& field, string& ret )
73 {
74  const Finfo* f = tgt.element()->cinfo()->findFinfo( field );
75  if ( !f ) {
76  cout << Shell::myNode() << ": Error: SetGet::strGet: Field " <<
77  field << " not found on Element " << tgt.element()->getName() <<
78  endl;
79  return 0;
80  }
81  return f->strGet( tgt.eref(), field, ret );
82 }
83 
84 bool SetGet::strSet( const ObjId& tgt, const string& field, const string& v)
85 {
86  const Finfo* f = tgt.element()->cinfo()->findFinfo( field );
87  if ( !f ) {
88  cout << Shell::myNode() << ": Error: SetGet::strSet: Field " <<
89  field << " not found on Element " << tgt.element()->getName() <<
90  endl;
91  return 0;
92  }
93  return f->strSet( tgt.eref(), field, v );
94 }
virtual bool strGet(const Eref &tgt, const string &field, string &returnValue) const =0
static const OpFunc * checkSet(const string &field, ObjId &tgt, FuncId &fid)
Definition: SetGet.cpp:15
unsigned int fieldIndex
Definition: ObjId.h:100
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
std::string path(const std::string &separator="/") const
Definition: Id.cpp:76
Id id
Definition: ObjId.h:98
static Id child(const Eref &e, const string &name)
Definition: Neutral.cpp:665
Definition: ObjId.h:20
virtual bool strSet(const Eref &tgt, const string &field, const string &arg) const =0
bool isDataHere() const
Definition: ObjId.cpp:95
static bool strSet(const ObjId &dest, const string &field, const string &val)
Definition: SetGet.cpp:84
FuncId getFid() const
Definition: DestFinfo.cpp:45
static bool strGet(const ObjId &tgt, const string &field, string &ret)
Definition: SetGet.cpp:72
const Cinfo * cinfo() const
Definition: Element.cpp:66
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
const OpFunc * getOpFunc() const
Definition: DestFinfo.cpp:40
Element * element() const
Definition: ObjId.cpp:124
Eref eref() const
Definition: ObjId.cpp:66
Definition: Id.h:17
static unsigned int myNode()
unsigned int FuncId
Definition: header.h:42
const string & getName() const
Definition: Element.cpp:56
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224
unsigned int dataIndex
Definition: ObjId.h:99
Definition: Finfo.h:12