MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ObjId.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment,
4 ** also known as GENESIS 3 base code.
5 ** copyright (C) 2003-2006 Upinder S. Bhalla. and NCBS
6 ** It is made available under the terms of the
7 ** GNU Lesser General Public License version 2.1
8 ** See the file COPYING.LIB for the full notice.
9 **********************************************************************/
10 
11 #include "header.h"
12 #include "../shell/Shell.h"
14 // ObjId I/O
16 
17 // Doesn't know how to deal with off-node bad fields.
18 bool ObjId::bad() const
19 {
20  Element* elm = id.element();
21  return ( elm == 0 ||
22  dataIndex == BADINDEX ||
23  fieldIndex == BADINDEX ||
24  dataIndex >= elm->numData()
25  /*
26  * We have a bit of a problem here. The FieldElement can exist
27  * with zero fields, and is invalid for field lookups but valid
28  * for the element level lookups. I should rather not create the
29  * FieldElements this way.
30  || (
31  elm->getNode( dataIndex ) == Shell::myNode() &&
32  fieldIndex >= elm->numField( dataIndex - elm->localDataStart() )
33  )
34  */
35  );
36 }
37 
38 ostream& operator <<( ostream& s, const ObjId& i )
39 {
40  if ( i.dataIndex == 0 && i.fieldIndex == 0 )
41  s << i.id;
42  else if ( i.fieldIndex == 0 )
43  s << i.id << "[" << i.dataIndex << "]";
44  else
45  s << i.id << "[" << i.dataIndex << "][" << i.fieldIndex << "]";
46  return s;
47 }
48 
52 istream& operator >>( istream& s, ObjId& i )
53 {
54  s >> i.id;
55  return s;
56 }
57 
59 ObjId::ObjId( const string& path )
60 {
61  Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
62  assert( shell );
63  *this = shell->doFind( path );
64 }
65 
67 {
68  return Eref( id.element(), dataIndex, fieldIndex );
69 }
70 
71 bool ObjId::operator==( const ObjId& other ) const
72 {
73  return ( id == other.id && dataIndex == other.dataIndex &&
74  fieldIndex == other.fieldIndex );
75 }
76 
77 bool ObjId::operator!=( const ObjId& other ) const
78 {
79  return ( id != other.id || dataIndex != other.dataIndex ||
80  fieldIndex != other.fieldIndex );
81 }
82 
83 bool ObjId::operator<( const ObjId& other ) const
84 {
85  return ( id < other.id ||
86  (id == other.id && (
87  dataIndex < other.dataIndex ||
88  ( dataIndex == other.dataIndex &&
89  fieldIndex < other.fieldIndex )
90  )
91  )
92  );
93 }
94 
95 bool ObjId::isDataHere() const
96 {
97  return ( id.element()->getNode( dataIndex ) == Shell::myNode() );
98 }
99 
100 bool ObjId::isGlobal() const
101 {
102  return ( id.element()->isGlobal() );
103 }
104 
105 bool ObjId::isOffNode() const
106 {
107  return ( Shell::numNodes() > 1 &&
108  ( id.element()->isGlobal() ||
109  id.element()->getNode( dataIndex ) != Shell::myNode() )
110  );
111 }
112 
113 char* ObjId::data() const
114 {
115  return id.element()->data( id.element()->rawIndex( dataIndex ),
116  fieldIndex );
117 }
118 
119 string ObjId::path() const
120 {
121  return Neutral::path( eref() );
122 }
123 
125 {
126  return id.element();
127 }
bool operator!=(const ObjId &other) const
Definition: ObjId.cpp:77
char * data() const
Definition: Eref.cpp:41
char * data() const
Definition: ObjId.cpp:113
unsigned int fieldIndex
Definition: ObjId.h:100
bool bad() const
Definition: ObjId.cpp:18
Id id
Definition: ObjId.h:98
ostream & operator<<(ostream &s, const ObjId &i)
Definition: ObjId.cpp:38
bool operator==(const ObjId &other) const
Definition: ObjId.cpp:71
istream & operator>>(istream &s, ObjId &i)
Definition: ObjId.cpp:52
bool operator<(const ObjId &other) const
Definition: ObjId.cpp:83
Definition: ObjId.h:20
Eref eref() const
Definition: Id.cpp:125
ObjId doFind(const string &path) const
Definition: Shell.cpp:549
bool isDataHere() const
Definition: ObjId.cpp:95
static string path(const Eref &e)
Definition: Neutral.cpp:725
bool isGlobal() const
Returns true if the Element is global.
Definition: ObjId.cpp:100
bool isOffNode() const
Returns true if we need to go off-node for calling operations.
Definition: ObjId.cpp:105
string path() const
Definition: ObjId.cpp:119
Definition: Eref.h:26
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
Element * element() const
Definition: ObjId.cpp:124
ObjId()
Definition: ObjId.h:31
Eref eref() const
Definition: ObjId.cpp:66
Definition: Id.h:17
static unsigned int myNode()
static unsigned int numNodes()
const unsigned int BADINDEX
Used by ObjId and Eref.
Definition: consts.cpp:25
static char path[]
Definition: mfield.cpp:403
Definition: Shell.h:43
unsigned int dataIndex
Definition: ObjId.h:99