MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
bufmod.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  BufCast
 
class  TBufCast< T >
 
class  TBufCastHToN< T >
 

Typedefs

typedef std::map< std::string,
bool
TypeMap_t
 

Functions

template<typename T >
static T mbswap (const T in)
 
template<int8_t >
static int8_t mbswap (const int8_t in)
 
template<uint8_t >
static uint8_t mbswap (const uint8_t in)
 
void ReadBufCast (HighParser &HP, std::vector< BufCast * > &data)
 
bool bIsLittleEndian (void)
 
void SwapMapInit (TypeMap_t &swapmap)
 

Typedef Documentation

typedef std::map<std::string, bool> TypeMap_t

Definition at line 37 of file bufmod.h.

Function Documentation

bool bIsLittleEndian ( void  )

Definition at line 259 of file bufmod.cc.

Referenced by buildFGBufCast(), and ReadBufCast().

260 {
261  const int i = 1;
262  return (*(char *)&i) != 0;
263 }
template<typename T >
static T mbswap ( const T  in)
static

Definition at line 91 of file bufmod.h.

92 {
93  const char *pin = (const char *)&in;
94  T out;
95  char *pout = (char *)&out;
96 
97  for (unsigned int i = 0; i < sizeof(T)/2; i++) {
98  pout[i] = pin[sizeof(T) - 1 - i];
99  pout[sizeof(T) - 1 - i] = pin[i];
100  }
101 
102  return out;
103 }
template<int8_t >
static int8_t mbswap ( const int8_t  in)
static

Definition at line 107 of file bufmod.h.

108 {
109  return in;
110 }
template<uint8_t >
static uint8_t mbswap ( const uint8_t  in)
static

Definition at line 114 of file bufmod.h.

115 {
116  return in;
117 }
void ReadBufCast ( HighParser HP,
std::vector< BufCast * > &  data 
)

Definition at line 287 of file bufmod.cc.

References bIsLittleEndian(), BufCast::copy(), HighParser::GetYesNoOrBool(), HighParser::IsKeyWord(), HighParser::IsWord(), ReadOneBufCast(), and SwapMapInit().

Referenced by ReadStreamContentModifier(), and ReadStreamDriveModifier().

288 {
289  TypeMap_t swapmap;
290  SwapMapInit(swapmap);
291 
292  if (HP.IsKeyWord("swap")) {
293  TypeWordSet_t typewordset(swapmap);
294  const char *s = HP.IsWord(typewordset);
295  if (s != 0) {
296  do {
297  TypeMap_t::iterator i = swapmap.find(std::string(s));
298  i->second = true;
299  } while ((s = HP.IsWord(typewordset)) != 0);
300 
301  } else {
302  bool bSwap(false);
303  if (HP.IsKeyWord("detect")) {
304  bSwap = bIsLittleEndian();
305 
306  } else {
307  bSwap = HP.GetYesNoOrBool();
308  }
309 
310  if (bSwap) {
311  for (TypeMap_t::iterator i = swapmap.begin(); i != swapmap.end(); ++i) {
312  i->second = true;
313  }
314  }
315  }
316  }
317 
318  if (HP.IsKeyWord("all")) {
319  size_t size(0), offset(0);
320  BufCast *pBC = 0;
321  pBC = ReadOneBufCast(HP, size, swapmap, true);
322 
323  data[0] = pBC;
324  for (size_t i = 1; i < data.size(); i++) {
325  offset += size;
326  data[i] = data[i - 1]->copy(offset);
327  }
328 
329  } else {
330  size_t offset(0);
331  for (size_t i = 0; i < data.size(); i++) {
332 retry:;
333  BufCast *pBC = 0;
334  pBC = ReadOneBufCast(HP, offset, swapmap);
335 
336  if (pBC == 0) {
337  // got skip
338  goto retry;
339  }
340  data[i] = pBC;
341  }
342  }
343 }
void SwapMapInit(TypeMap_t &swapmap)
Definition: bufmod.cc:266
virtual const char * IsWord(const HighParser::WordSet &ws)
Definition: parser.cc:977
static BufCast * ReadOneBufCast(HighParser &HP, size_t &offset, TypeMap_t &swapmap, bool bNoSkip=false)
Definition: bufmod.cc:146
bool bIsLittleEndian(void)
Definition: bufmod.cc:259
virtual bool GetYesNoOrBool(bool bDefval=false)
Definition: parser.cc:1038
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
std::map< std::string, bool > TypeMap_t
Definition: bufmod.h:37
virtual BufCast * copy(size_t offset) const =0
Definition: bufmod.h:42

Here is the call graph for this function:

void SwapMapInit ( TypeMap_t swapmap)

Definition at line 266 of file bufmod.cc.

Referenced by buildFGBufCast(), and ReadBufCast().

267 {
268  swapmap.insert(TypeMap_t::value_type(typeid(int8_t).name(), false));
269  swapmap.insert(TypeMap_t::value_type(typeid(uint8_t).name(), false));
270  swapmap.insert(TypeMap_t::value_type(typeid(int16_t).name(), false));
271  swapmap.insert(TypeMap_t::value_type(typeid(uint16_t).name(), false));
272  swapmap.insert(TypeMap_t::value_type(typeid(int32_t).name(), false));
273  swapmap.insert(TypeMap_t::value_type(typeid(uint32_t).name(), false));
274  swapmap.insert(TypeMap_t::value_type(typeid(float).name(), false));
275  swapmap.insert(TypeMap_t::value_type(typeid(double).name(), false));
276 }