MOOSE - Multiscale Object Oriented Simulation Environment
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FieldElementFinfo.h
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-2013 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 
23 #ifndef _FIELD_ELEMENT_FINFO_H
24 #define _FIELD_ELEMENT_FINFO_H
25 
27 {
28 public:
30  const string& name,
31  const string& doc,
32  const Cinfo* fieldCinfo,
33  bool deferCreate
34  )
35  : Finfo( name, doc),
36  setNum_( 0 ),
37  getNum_( 0 ),
38  fieldCinfo_( fieldCinfo ),
39  deferCreate_( deferCreate )
40  {
41  ;
42  }
43 
45  {
46  if ( setNum_ )
47  delete setNum_;
48  if ( getNum_ )
49  delete getNum_;
50  }
51 
52  void registerFinfo( Cinfo* c )
53  {
54  c->registerFinfo( setNum_ );
55  c->registerFinfo( getNum_ );
56  c->registerPostCreationFinfo( this );
57  }
58 
59  bool strSet( const Eref& tgt, const string& field,
60  const string& arg ) const
61  {
62  return 0; // always fails
63  }
64 
65  bool strGet( const Eref& tgt, const string& field,
66  string& returnValue ) const
67  {
68  return 0; // always fails
69  }
70 
74  void postCreationFunc( Id parent, Element* parentElm ) const;
75 
81  virtual char* lookupField( char* parent,
82  unsigned int fieldIndex ) const = 0;
83 
85  virtual void setNumField( char* parent, unsigned int num )
86  const = 0;
87 
89  virtual unsigned int getNumField( const char* parent )
90  const = 0;
91 
92  // Virtual function to look up type of FieldElementFinfo, not
93  // defined here.
94  // virtual string rttiType() const = 0;
95 
96 protected:
101 };
102 
103 template < class T, class F >
105 {
106 public:
108  const string& name,
109  const string& doc,
110  const Cinfo* fieldCinfo,
111  F* ( T::*lookupField )( unsigned int ),
112  void( T::*setNumField )( unsigned int num ),
113  unsigned int ( T::*getNumField )() const,
114  bool deferCreate = 0
115  )
116  : FieldElementFinfoBase( name, doc, fieldCinfo, deferCreate ),
117  lookupField_( lookupField ),
118  setNumField_( setNumField ),
119  getNumField_( getNumField )
120  {
121  string setname = "setNum" + name;
122  setname[6] = std::toupper( setname[6] );
123  // setNumField is a tricky operation, because it may require
124  // cross-node rescaling of the
125  // FieldDataHandler::fieldDimension. To acheive this we
126  // wrap the setNumField in something more interesting
127  // than a simple OpFunc.
128  setNum_ = new DestFinfo(
129  setname,
130  "Assigns number of field entries in field array.",
131  new OpFunc1< T, unsigned int >( setNumField ) );
132 
133  string getname = "getNum" + name;
134  getname[6] = std::toupper( getname[6] );
135  getNum_ = new DestFinfo(
136  getname,
137  "Requests number of field entries in field array."
138  "The requesting Element must "
139  "provide a handler for the returned value.",
140  new GetOpFunc< T, unsigned int >( getNumField ) );
141  }
142 
148  char* lookupField( char* parent, unsigned int fieldIndex ) const
149  {
150  T* pa = reinterpret_cast< T* >( parent );
151  if ( fieldIndex < ( pa->*getNumField_ )() )
152  {
153  F* self = ( pa->*lookupField_ )( fieldIndex );
154  return reinterpret_cast< char* >( self );
155  }
156  return 0;
157  }
158 
160  void setNumField( char* parent, unsigned int num ) const
161  {
162  T* pa = reinterpret_cast< T* >( parent );
163  ( pa->*setNumField_ )( num );
164  }
165 
167  unsigned int getNumField( const char* parent ) const
168  {
169  const T* pa = reinterpret_cast< const T* >( parent );
170  return ( pa->*getNumField_ )();
171  }
172 
173 
174 
176  string rttiType() const
177  {
178  return Conv<F>::rttiType();
179  }
180 
181 private:
182  F* ( T::*lookupField_ )( unsigned int );
183  void( T::*setNumField_ )( unsigned int num );
184  unsigned int ( T::*getNumField_ )() const;
185 };
186 
187 #endif // _FIELD_ELEMENT_FINFO_H
bool strSet(const Eref &tgt, const string &field, const string &arg) const
string rttiType() const
Virtual function to look up type of FieldElementFinfo.
virtual void setNumField(char *parent, unsigned int num) const =0
virtual func to resize Field array, using char* for parent
const string & name() const
Definition: Finfo.cpp:80
virtual unsigned int getNumField(const char *parent) const =0
virtual func to get size of Field array, using char* for parent
unsigned int getNumField(const char *parent) const
virtual func to get size of Field array, using char* for parent
FieldElementFinfo(const string &name, const string &doc, const Cinfo *fieldCinfo, F *(T::*lookupField)(unsigned int), void(T::*setNumField)(unsigned int num), unsigned int(T::*getNumField)() const, bool deferCreate=0)
char * lookupField(char *parent, unsigned int fieldIndex) const
void registerFinfo(Finfo *f)
Definition: Cinfo.cpp:114
bool strGet(const Eref &tgt, const string &field, string &returnValue) const
Definition: OpFunc.h:27
Definition: Eref.h:26
void registerFinfo(Cinfo *c)
void postCreationFunc(Id parent, Element *parentElm) const
void(T::* setNumField_)(unsigned int num)
F *(T::* lookupField_)(unsigned int)
static string rttiType()
Definition: Conv.h:82
Definition: Id.h:17
void registerPostCreationFinfo(const Finfo *f)
Definition: Cinfo.cpp:138
void setNumField(char *parent, unsigned int num) const
virtual func to resize Field array, using char* for parent
FieldElementFinfoBase(const string &name, const string &doc, const Cinfo *fieldCinfo, bool deferCreate)
Definition: Cinfo.h:18
unsigned int(T::* getNumField_)() const
virtual char * lookupField(char *parent, unsigned int fieldIndex) const =0
Definition: Finfo.h:12