forked from BhallaLab/moose-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetGet.cpp
93 lines (86 loc) · 3.12 KB
/
SetGet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**********************************************************************
** This program is part of 'MOOSE', the
** Messaging Object Oriented Simulation Environment.
** Copyright (C) 2003-2009 Upinder S. Bhalla. and NCBS
** It is made available under the terms of the
** GNU Lesser General Public License version 2.1
** See the file COPYING.LIB for the full notice.
**********************************************************************/
#include "header.h"
#include "SetGet.h"
#include "../shell/Shell.h"
#include "../shell/Neutral.h"
const OpFunc* SetGet::checkSet( const string& field, ObjId& tgt, FuncId& fid )
{
// string field = "set_" + destField;
const Finfo* f = tgt.element()->cinfo()->findFinfo( field );
if ( !f ) // Could be a child element? Note that field name will
{
// change from set_<name> to just <name>
string f2 = field.substr( 3 );
Id child = Neutral::child( tgt.eref(), f2 );
if ( child == Id() )
{
cout << "Error: SetGet:checkSet:: No field or child named '" <<
field << "' was found on\n" << tgt.id.path() << endl;
}
else
{
if ( field.substr( 0, 3 ) == "set" )
f = child.element()->cinfo()->findFinfo( "setThis" );
else if ( field.substr( 0, 3 ) == "get" )
f = child.element()->cinfo()->findFinfo( "getThis" );
assert( f ); // should always work as Neutral has the field.
if ( child.element()->numData() == tgt.element()->numData() )
{
tgt = ObjId( child, tgt.dataIndex, tgt.fieldIndex );
if ( !tgt.isDataHere() )
return 0;
}
else if ( child.element()->numData() <= 1 )
{
tgt = ObjId( child, 0 );
if ( !tgt.isDataHere() )
return 0;
}
else
{
cout << "SetGet::checkSet: child index mismatch\n";
return 0;
}
}
}
const DestFinfo* df = dynamic_cast< const DestFinfo* >( f );
if ( !df )
return 0;
fid = df->getFid();
const OpFunc* func = df->getOpFunc();
assert( func );
return func;
}
/////////////////////////////////////////////////////////////////////////
// Static function
bool SetGet::strGet( const ObjId& tgt, const string& field, string& ret )
{
const Finfo* f = tgt.element()->cinfo()->findFinfo( field );
if ( !f )
{
cout << Shell::myNode() << ": Error: SetGet::strGet: Field " <<
field << " not found on Element " << tgt.element()->getName() <<
endl;
return 0;
}
return f->strGet( tgt.eref(), field, ret );
}
bool SetGet::strSet( const ObjId& tgt, const string& field, const string& v)
{
const Finfo* f = tgt.element()->cinfo()->findFinfo( field );
if ( !f )
{
cout << Shell::myNode() << ": Error: SetGet::strSet: Field " <<
field << " not found on Element " << tgt.element()->getName() <<
endl;
return 0;
}
return f->strSet( tgt.eref(), field, v );
}