Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Attribute.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Attribute.h,v 1.18 2008/12/06 08:43:24 mtcampbe Exp $
24 
29 /* Author: Xiangmin Jiao */
30 
31 #ifndef __ROCCOM_ATTRIBUTE_H__
32 #define __ROCCOM_ATTRIBUTE_H__
33 
34 #include <string>
35 #include "roccom_exception.h"
36 
37 COM_BEGIN_NAME_SPACE
38 
39 class Pane;
40 class Window;
41 
45 
51 class Attribute {
52 public:
53  typedef unsigned char Shorter_size;
54  typedef unsigned int Size;
55 
59  Attribute()
61  : _pane(NULL), _parent(NULL), _id(-1), _loc(0), _ncomp(0), _type(0),
63  _ptr(NULL), _strd(0), _nbytes_strd(0), _cap(0) {}
64 
65 protected:
67  Attribute( Pane *pane, int i)
68  : _pane(pane), _parent(NULL), _name( _keywords[i]), _id(i),
70  _unit( i<=COM_NC3?"m":""), _nitems(0), _ngitems(0), _gap(0),
72  _nbytes_strd(0), _cap(0) {}
73 public:
83  Attribute( Pane *pane, const std::string &name, int id,
84  Shorter_size loc, int type, const int ncomp,
85  const std::string &unit)
86  : _pane(pane), _parent(NULL), _name( name), _id(id), _loc(loc),
87  _ncomp(ncomp), _type(type), _unit(unit), _nitems(-1), _ngitems(0),
89  _nbytes_strd(0), _cap(0) {}
90 
98  const std::string &name, int id);
99 
102  if (!_parent) deallocate();
103  _pane=NULL; _parent=NULL; _id=-1; _loc=0; _ncomp=0; _type=0;
105  _strd=0; _nbytes_strd=0; _cap=0;
106  }
107  //\}
108 
112  const std::string &name() const { return _name; }
114 
117  std::string fullname() const;
118 
120  int id() const { return _id; }
121 
125  Attribute *parent() { return _parent; }
126  const Attribute *parent() const { return _parent; }
127 
135  Attribute *a=this;
136  while ( a->_parent) a=a->_parent;
137  return a;
138  }
139  const Attribute *root() const {
140  const Attribute *a=this;
141  while ( a->_parent) a=a->_parent;
142  return a;
143  }
144  //\}
145 
149  const void *pointer() const { return _status?_ptr:root()->_ptr; }
152  void *pointer() throw(COM_exception) {
153  if ( is_const()) throw COM_exception( COM_ERR_ATTRIBUTE_CONST);
154  return _status?_ptr:root()->_ptr;
155  }
156 
160  const void *get_addr( int i, int j=0) const throw(COM_exception);
161 
162  void *get_addr( int i, int j=0) throw(COM_exception) {
163  if ( is_const()) throw COM_exception( COM_ERR_ATTRIBUTE_CONST);
164  return (void*)(((const Attribute*)this)->get_addr(i,j));
165  }
166  //\}
167 
171  const Pane *pane() const { return _pane; }
174  Pane *pane() { return _pane; }
175 
177  const Window *window() const;
179  Window *window();
180 
186  Shorter_size location() const { return _loc; }
188  bool is_windowed() const { return _loc == 'w'; }
190  bool is_panel() const { return _loc == 'p'; }
192  bool is_elemental() const { return _loc == 'e'; }
194  bool is_nodal() const { return _loc == 'n'; }
195 
197  COM_Type data_type() const { return _type; }
198 
200  const std::string &unit() const { return _unit; }
201 
203  int size_of_components() const { return _ncomp; }
204 
206  int size_of_items() const;
207 
210  int maxsize_of_items() const;
211 
213  int size_of_ghost_items() const;
214 
217  int maxsize_of_ghost_items() const;
218 
220  int size_of_real_items() const;
221 
224  int maxsize_of_real_items() const;
225 
227  bool empty() const { return root()->_nitems<= 0; }
228 
230  int capacity() const { return _status?_cap:root()->_cap; }
231 
233  int stride() const { return _status?_strd:root()->_strd; }
234 
236  int stride_in_bytes() const
237  { return _status?_nbytes_strd:root()->_nbytes_strd; }
238 
240  int status() const
241  { if ( _parent) return STATUS_USE; else return _status; }
242 
244  bool initialized() const { return _status||root()->_status; }
245 
247  bool size_set() const;
248 
250  bool allocated() const { return _status==STATUS_ALLOCATED; }
251 
253  bool is_const() const { return root()->_status==STATUS_SET_CONST; }
254 
257  // a pane/node/element are not stored in consecutive memory space.
258  bool is_staggered() const { return stride()!=size_of_components(); }
259 
260  static int get_sizeof( COM_Type type, int count=1);
261 
262  static bool compatible_types( COM_Type t1, COM_Type t2);
263 
264  static bool is_digit( char c) { return c>='0' && c<='9'; }
265  //\}
266 
269  void set_size( int nitems, int ngitems=0) throw(COM_exception);
270 
274  void *allocate( int strd, int cap, bool force) throw(COM_exception);
275 
278  int deallocate() throw(COM_exception);
279 
281  // Copy n _ncomp-vectors from "buf" to the array if direction is COPY_IN
282  // or copy to "buf" if direction is COPY_OUT.
283  void copy_array( void *buf, int strd, int nitem,
284  int offset=0, int direction=COPY_IN) throw(COM_exception);
285 
286  // Append n _ncomp-vectors from "from" to the array.
287  void append_array( const void *from, int strd, int nitem) throw(COM_exception);
288 
289 protected:
291  void set_pointer( void *p, int strd, int cap,
292  int offset, bool is_const) throw(COM_exception);
293 
295  void inherit( Attribute *a, bool clone, bool withghost, int depth=0) throw(COM_exception);
296 
297 protected:
300 
301  std::string _name;
302  int _id;
304 
308  int _ncomp;
310  std::string _unit;
311 
312  int _nitems;
313  int _ngitems;
314  int _gap;
315 
319 
320  void *_ptr;
321  int _strd;
323  int _cap;
324 
325  static const char *_keywords[COM_NUM_KEYWORDS];
326  static const char _keylocs[COM_NUM_KEYWORDS];
328  static const int _keysizes[COM_NUM_KEYWORDS];
329 
330 private:
332  Attribute( const Attribute &a);
333  Attribute &operator=( const Attribute&);
334 };
335 
336 COM_END_NAME_SPACE
337 
338 #endif
339 
340 
341 
342 
343 
344 
void inherit(Attribute *a, bool clone, bool withghost, int depth=0)
Inherit from parent. If depth&gt;0, then the procedure is for the subcomponents.
Definition: Attribute.C:426
Attribute * _parent
Parent attribute being used.
Definition: Attribute.h:299
int COM_Type
Indices for derived data types.
Definition: roccom_basic.h:122
int _ngitems
Size of ghost items.
Definition: Attribute.h:313
A Pane object contains a mesh, pane attribute, and field variables.
Definition: Pane.h:43
bool size_set() const
Returns whether the size for the attribute has been set.
Definition: Attribute.C:99
bool initialized() const
Returns whether the array for the attribute has been set or allocated.
Definition: Attribute.h:244
int _nbytes_strd
Number of bytes of the stride.
Definition: Attribute.h:322
int maxsize_of_real_items() const
Obtain the maximum allowed number of real items in the attribute.
Definition: Attribute.C:179
int _strd
Stride.
Definition: Attribute.h:321
void set_pointer(void *p, int strd, int cap, int offset, bool is_const)
Set the physical address of the attribute values.
Definition: Attribute.C:208
An Attribute object is a data member of a window.
Definition: Attribute.h:51
static bool compatible_types(COM_Type t1, COM_Type t2)
Definition: Attribute.C:531
static bool is_digit(char c)
Definition: Attribute.h:264
Shorter_size _status
Indicating whether it has been initialized.
Definition: Attribute.h:318
const void * get_addr(int i, int j=0) const
Obtain the address of the jth component of the ith item, where 0&lt;=i&lt;size_of_items.
Definition: Attribute.C:85
bool is_windowed() const
Checks whether the attribute is associated with the window.
Definition: Attribute.h:188
A Window object contains multiple panes and multiple data attributes.
Definition: Window.h:42
static const int _keysizes[COM_NUM_KEYWORDS]
Default sizes.
Definition: Attribute.h:328
int status() const
Obtain the status of the attribute.
Definition: Attribute.h:240
Pane * pane()
Obtain a modifiable pointer to the owner pane of the attribute.
Definition: Attribute.h:174
Attribute * parent()
Parent attribute used by this object.
Definition: Attribute.h:125
~Attribute()
Destructors.
Definition: Attribute.h:101
real *8 function offset(vNorm, x2, y2, z2)
Definition: PlaneNorm.f90:211
const Window * window() const
Obtain a constant pointer to the parent window of the attribute.
Definition: Attribute.C:80
int maxsize_of_items() const
Obtain the maximum allowed number of items in the attribute.
Definition: Attribute.C:125
Shorter_size location() const
Obtain the location of the attribute.
Definition: Attribute.h:186
Encapsulates the states of an exception.
int deallocate()
Deallocate memory if it was allocated by allocate().
Definition: Attribute.C:473
const std::string & unit() const
Obtain the unit of the attribute.
Definition: Attribute.h:200
static const COM_Type _keytypes[COM_NUM_KEYWORDS]
Default data types.
Definition: Attribute.h:327
int capacity() const
Obtain the capacity of the array.
Definition: Attribute.h:230
Attribute * root()
Root of use-inheritance.
Definition: Attribute.h:134
unsigned int Size
Unsighed int.
Definition: Attribute.h:54
const void * pointer() const
Obtain a constant pointer to the physical address.
Definition: Attribute.h:150
int stride_in_bytes() const
Obtain the stride of the attribute in bytes.
Definition: Attribute.h:236
Attribute()
Default constructor.
Definition: Attribute.h:60
std::string _unit
Unit of the attribute.
Definition: Attribute.h:310
int size_of_ghost_items() const
Obtain the number of ghost items in the attribute.
Definition: Attribute.C:139
COM_Keywords
Definition: Attribute.h:42
Pane * _pane
Pointer to its owner pane.
Definition: Attribute.h:298
void * _ptr
Physical address of the attribute.
Definition: Attribute.h:320
Shorter_size _loc
Location.
Definition: Attribute.h:303
const std::string & name() const
Obtain the name of the attribute.
Definition: Attribute.h:113
blockLoc i
Definition: read.cpp:79
int _gap
Gap between the IDs of real and ghost items.
Definition: Attribute.h:314
std::string _name
Name of the attribute.
Definition: Attribute.h:301
bool allocated() const
Returns whether the array for the attribute has been set or allocated.
Definition: Attribute.h:250
int _id
Id field data.
Definition: Attribute.h:302
Attribute(Pane *pane, int i)
Constructor for keywords. The default nitems for keywords is 0.
Definition: Attribute.h:67
int stride() const
Obtain the stride of the attribute in base datatype.
Definition: Attribute.h:233
bool is_nodal() const
Checks whether the attribute is associated with a node.
Definition: Attribute.h:194
int maxsize_of_ghost_items() const
Obtain the maximum allowed number of items in the attribute.
Definition: Attribute.C:153
void set_size(int nitems, int ngitems=0)
Set the size of items and ghost items.
Definition: Attribute.C:191
int size_of_real_items() const
Obtain the number of real items in the attribute.
Definition: Attribute.C:167
void * pointer()
Obtain a modifiable pointer to the physical address.
Definition: Attribute.h:152
const Pane * pane() const
Obtain a constant pointer to the owner pane of the attribute.
Definition: Attribute.h:172
const Attribute * parent() const
Definition: Attribute.h:126
bool is_staggered() const
Check how the attribute values are organized.
Definition: Attribute.h:258
j indices j
Definition: Indexing.h:6
COM_Type _type
Base data type of the attribute.
Definition: Attribute.h:309
int _ncomp
Number of components.
Definition: Attribute.h:308
void * allocate(int strd, int cap, bool force)
Allocate memory for the attribute.
Definition: Attribute.C:345
bool is_panel() const
Checks whether the attribute is associated with a pane.
Definition: Attribute.h:190
Attribute(Pane *pane, const std::string &name, int id, Shorter_size loc, int type, const int ncomp, const std::string &unit)
Create an attribute with name n in window w.
Definition: Attribute.h:83
int _nitems
Size of total items. Default value is -1.
Definition: Attribute.h:312
void copy_array(void *buf, int strd, int nitem, int offset=0, int direction=COPY_IN)
Definition: Attribute.C:249
Attribute & operator=(const Attribute &)
static const char _keylocs[COM_NUM_KEYWORDS]
Default locations.
Definition: Attribute.h:326
unsigned char Shorter_size
One byte unsighed int.
Definition: Attribute.h:53
COM_Type data_type() const
Obtain the data type of each component of the attribute.
Definition: Attribute.h:197
int id() const
Obtain the id (or index) of the attribute.
Definition: Attribute.h:120
static const char * _keywords[COM_NUM_KEYWORDS]
List of keywords.
Definition: Attribute.h:325
bool empty() const
Check whether the number of items of the attribute is zero.
Definition: Attribute.h:227
bool is_const() const
Returns whether the array is set to be read-only.
Definition: Attribute.h:253
bool is_elemental() const
Checks whether the attribute is associated with an element.
Definition: Attribute.h:192
int _cap
Capacity.
Definition: Attribute.h:323
int size_of_items() const
Obtain the number of items in the attribute.
Definition: Attribute.C:111
std::string fullname() const
Obtain the full name of the attribute including window name suitable for printing out error messages...
Definition: Attribute.C:82
static int get_sizeof(COM_Type type, int count=1)
Definition: Attribute.C:488
const Attribute * root() const
Definition: Attribute.h:139
int size_of_components() const
Obtain the number of components in the attribute.
Definition: Attribute.h:203
void append_array(const void *from, int strd, int nitem)
Definition: Attribute.C:334