MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PrepackedBuffer Class Reference

#include <PrepackedBuffer.h>

+ Collaboration diagram for PrepackedBuffer:

Public Member Functions

unsigned int conv2buf (char *buf) const
 
const char * data () const
 
unsigned int dataSize () const
 
bool isVector () const
 
unsigned int numEntries () const
 
const char * operator[] (unsigned int index) const
 
 PrepackedBuffer (const char *data, unsigned int dataSize, unsigned int numEntries=0)
 
 PrepackedBuffer (const PrepackedBuffer &other)
 
 PrepackedBuffer (const char *buf)
 
 PrepackedBuffer ()
 
unsigned int size () const
 
 ~PrepackedBuffer ()
 

Private Attributes

char * data_
 
unsigned int dataSize_
 
unsigned int individualDataSize_
 
unsigned int numEntries_
 

Detailed Description

this class is used to take data that has already been converted into a buffer by one or more Conv<> operations, and send it between nodes. Useful when one doesn't know the data type being transferred.

Definition at line 15 of file PrepackedBuffer.h.

Constructor & Destructor Documentation

PrepackedBuffer::PrepackedBuffer ( const char *  data,
unsigned int  dataSize,
unsigned int  numEntries = 0 
)

Constructor. Here data is a pointer to the entire data block. dataSize is the size of the entire data block to be transferred, dataSize = individualDataSize * numEntries. numEntries is the # of array entries. For non-arrays it defaults to 0.

Definition at line 13 of file PrepackedBuffer.cpp.

References data_, dataSize(), dataSize_, individualDataSize_, and numEntries_.

16 {
17  if ( numEntries == 0 )
19  else
21 
22  data_ = new char[ dataSize ];
23  memcpy( data_, data, dataSize );
24 }
unsigned int numEntries_
const char * data() const
unsigned int numEntries() const
unsigned int dataSize_
unsigned int individualDataSize_
unsigned int dataSize() const

+ Here is the call graph for this function:

PrepackedBuffer::PrepackedBuffer ( const PrepackedBuffer other)

Definition at line 26 of file PrepackedBuffer.cpp.

References data_, dataSize_, individualDataSize_, and numEntries_.

27  : dataSize_( other.dataSize_ ),
28  numEntries_( other.numEntries_ )
29 {
30  if ( numEntries_ == 0 )
32  else
34  data_ = new char[ dataSize_ ];
35  memcpy( data_, other.data_, dataSize_ );
36 }
unsigned int numEntries_
unsigned int dataSize_
unsigned int individualDataSize_
PrepackedBuffer::PrepackedBuffer ( const char *  buf)

Constructor Here the char buffer is a serialized version of the Prepacked buffer

Definition at line 38 of file PrepackedBuffer.cpp.

References data_, dataSize_, individualDataSize_, and numEntries_.

39  : dataSize_( *reinterpret_cast< const unsigned int * >( buf ) ),
40  numEntries_( *reinterpret_cast< const unsigned int * >(
41  buf + sizeof( unsigned int ) ) )
42 {
43  if ( numEntries_ == 0 )
45  else
47  data_ = new char[ dataSize_ ];
48  memcpy( data_, buf + 2 * sizeof( unsigned int ), dataSize_ );
49 }
unsigned int numEntries_
unsigned int dataSize_
unsigned int individualDataSize_
PrepackedBuffer::PrepackedBuffer ( )

Definition at line 51 of file PrepackedBuffer.cpp.

References data_.

52  : dataSize_( 0 ), numEntries_( 0 ), individualDataSize_( 0 )
53 {
54  data_ = new char[1];
55  data_[0] = '\0';
56 }
unsigned int numEntries_
unsigned int dataSize_
unsigned int individualDataSize_
PrepackedBuffer::~PrepackedBuffer ( )

Definition at line 58 of file PrepackedBuffer.cpp.

References data_.

59 {
60  delete[] data_;
61 }

Member Function Documentation

unsigned int PrepackedBuffer::conv2buf ( char *  buf) const

Converts to a buffer. Buf must be preallocated.

Definition at line 70 of file PrepackedBuffer.cpp.

References data_, dataSize_, numEntries_, and size().

71 {
72  *reinterpret_cast< unsigned int* >( buf ) = dataSize_;
73  buf += sizeof( unsigned int );
74  *reinterpret_cast< unsigned int* >( buf ) = numEntries_;
75  buf += sizeof( unsigned int );
76  memcpy( buf, data_, dataSize_ );
77  return size();
78 }
unsigned int numEntries_
unsigned int size() const
unsigned int dataSize_

+ Here is the call graph for this function:

const char* PrepackedBuffer::data ( ) const
inline

Definition at line 42 of file PrepackedBuffer.h.

References data_.

42  {
43  return data_;
44  }
unsigned int PrepackedBuffer::dataSize ( ) const
inline

Returns the size of the data contents.

Definition at line 56 of file PrepackedBuffer.h.

References dataSize_.

Referenced by PrepackedBuffer().

56  {
57  return dataSize_;
58  }
unsigned int dataSize_

+ Here is the caller graph for this function:

bool PrepackedBuffer::isVector ( ) const
inline

Flag: is the data type a single value or a vector?

Definition at line 82 of file PrepackedBuffer.h.

References numEntries_.

82  {
83  return numEntries_ > 0;
84  }
unsigned int numEntries_
unsigned int PrepackedBuffer::numEntries ( ) const
inline

Returns number of data entries: size of transferred array.

Definition at line 75 of file PrepackedBuffer.h.

References numEntries_.

75  {
76  return numEntries_;
77  }
unsigned int numEntries_
const char * PrepackedBuffer::operator[] ( unsigned int  index) const

looks up entry. If index exceeds numEntries_, then goes back to beginning. Lets us tile the target with repeating sequences. Most commonly just repeat one entry.

Definition at line 63 of file PrepackedBuffer.cpp.

References data_, individualDataSize_, and numEntries_.

64 {
65  if ( numEntries_ == 0 )
66  return data_ ;
67  return data_ + ( index % numEntries_ ) * individualDataSize_;
68 }
unsigned int numEntries_
unsigned int individualDataSize_
unsigned int PrepackedBuffer::size ( ) const
inline

Returns the size of the entire PrepackedBuffer converted to char*

Definition at line 63 of file PrepackedBuffer.h.

References dataSize_.

Referenced by conv2buf().

63  {
64  return dataSize_ + 2 * sizeof( unsigned int );
65  }
unsigned int dataSize_

+ Here is the caller graph for this function:

Member Data Documentation

char* PrepackedBuffer::data_
private

Definition at line 89 of file PrepackedBuffer.h.

Referenced by conv2buf(), data(), operator[](), PrepackedBuffer(), and ~PrepackedBuffer().

unsigned int PrepackedBuffer::dataSize_
private

Definition at line 86 of file PrepackedBuffer.h.

Referenced by conv2buf(), dataSize(), PrepackedBuffer(), and size().

unsigned int PrepackedBuffer::individualDataSize_
private

Definition at line 88 of file PrepackedBuffer.h.

Referenced by operator[](), and PrepackedBuffer().

unsigned int PrepackedBuffer::numEntries_
private

Definition at line 87 of file PrepackedBuffer.h.

Referenced by conv2buf(), isVector(), numEntries(), operator[](), and PrepackedBuffer().


The documentation for this class was generated from the following files: