MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
bufmod.cc File Reference
#include "mbconfig.h"
#include "parser.h"
#include "bufmod.h"
Include dependency graph for bufmod.cc:

Go to the source code of this file.

Classes

struct  TypeWordSet_t
 

Functions

static BufCastReadOneBufCast (HighParser &HP, size_t &offset, TypeMap_t &swapmap, bool bNoSkip=false)
 
bool bIsLittleEndian (void)
 
void SwapMapInit (TypeMap_t &swapmap)
 
void ReadBufCast (HighParser &HP, std::vector< BufCast * > &data)
 

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 }
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:

static BufCast* ReadOneBufCast ( HighParser HP,
size_t &  offset,
TypeMap_t swapmap,
bool  bNoSkip = false 
)
static

Definition at line 146 of file bufmod.cc.

References ASSERT, HighParser::GetInt(), HighParser::GetLineData(), HighParser::IsKeyWord(), and MBDYN_EXCEPT_ARGS.

Referenced by ReadBufCast().

147 {
148  BufCast *pBC(0);
149 
150  if (HP.IsKeyWord("int8_t")) {
151  TypeMap_t::const_iterator i = swapmap.find(typeid(int8_t).name());
152  if (i->second) {
153  pBC = new TBufCastHToN<int8_t>(offset);
154 
155  } else {
156  pBC = new TBufCast<int8_t>(offset);
157  }
158  offset += sizeof(int8_t);
159 
160  } else if (HP.IsKeyWord("uint8_t")) {
161  TypeMap_t::const_iterator i = swapmap.find(typeid(uint8_t).name());
162  if (i->second) {
163  pBC = new TBufCastHToN<uint8_t>(offset);
164 
165  } else {
166  pBC = new TBufCast<uint8_t>(offset);
167  }
168  offset += sizeof(uint8_t);
169 
170  } else if (HP.IsKeyWord("int16_t")) {
171  TypeMap_t::const_iterator i = swapmap.find(typeid(int16_t).name());
172  if (i->second) {
173  pBC = new TBufCastHToN<int16_t>(offset);
174 
175  } else {
176  pBC = new TBufCast<int16_t>(offset);
177  }
178  offset += sizeof(int16_t);
179 
180  } else if (HP.IsKeyWord("uint16_t")) {
181  TypeMap_t::const_iterator i = swapmap.find(typeid(uint16_t).name());
182  if (i->second) {
183  pBC = new TBufCastHToN<uint16_t>(offset);
184 
185  } else {
186  pBC = new TBufCast<uint16_t>(offset);
187  }
188  offset += sizeof(uint16_t);
189 
190  } else if (HP.IsKeyWord("int32_t")) {
191  TypeMap_t::const_iterator i = swapmap.find(typeid(int32_t).name());
192  if (i->second) {
193  pBC = new TBufCastHToN<int32_t>(offset);
194 
195  } else {
196  pBC = new TBufCast<int32_t>(offset);
197  }
198  offset += sizeof(int32_t);
199 
200  } else if (HP.IsKeyWord("uint32_t")) {
201  TypeMap_t::const_iterator i = swapmap.find(typeid(uint32_t).name());
202  if (i->second) {
203  pBC = new TBufCastHToN<uint32_t>(offset);
204 
205  } else {
206  pBC = new TBufCast<uint32_t>(offset);
207  }
208  offset += sizeof(uint32_t);
209 
210  } else if (HP.IsKeyWord("float")) {
211  TypeMap_t::const_iterator i = swapmap.find(typeid(float).name());
212  if (i->second) {
213  pBC = new TBufCastHToN<float>(offset);
214 
215  } else {
216  pBC = new TBufCast<float>(offset);
217  }
218  offset += sizeof(float);
219 
220  } else if (HP.IsKeyWord("double")) {
221  TypeMap_t::const_iterator i = swapmap.find(typeid(double).name());
222  if (i->second) {
223  pBC = new TBufCastHToN<double>(offset);
224 
225  } else {
226  pBC = new TBufCast<double>(offset);
227  }
228  offset += sizeof(double);
229 
230  } else if (HP.IsKeyWord("skip") && !bNoSkip) {
231  integer skip = HP.GetInt();
232  if (skip < 0) {
233  silent_cerr("ReadOneBufCast: invalid number of bytes " << skip
234  << " to be skipped at line " << HP.GetLineData() << std::endl);
236  }
237  offset += skip;
238 
239 #if 0
240  } else if (HP.IsKeyWord("offset")) {
241  integer ioffset = HP.GetInt();
242  if (ioffset < 0) {
243  silent_cerr("ReadOneBufCast: invalid number of bytes " << ioffset
244  << " as offset at line " << HP.GetLineData() << std::endl);
246  }
247  offset = ioffset;
248 #endif
249 
250  } else {
251  ASSERT(0);
253  }
254 
255  return pBC;
256 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual integer GetInt(integer iDefval=0)
Definition: parser.cc:1050
virtual HighParser::ErrOut GetLineData(void) const
Definition: parser.cc:681
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
#define ASSERT(expression)
Definition: colamd.c:977
long int integer
Definition: colamd.c:51
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 }