Fortran SFF API to data I/O streams in C++

◆ setwid2() [2/2]

void fapidxx::WID2container::setwid2 ( char *  fstring,
ftnlen  slen 
)

fill data fields from a character string

set WID2 data from a Fortran character sequence

This function sets the data in WID2container::wid2 from an input character sequence. If encode uses a binary form to encode WID2 data, this function has to distinguish between both possible representations of WID2 data. This is not yet implemented.

Parameters
fstringWID2 line character squence to set WID2 data in WID2container::wid2 (input value of function)
slenlength of character array fstring

Definition at line 75 of file wid2container.cc.

References fapidxx::WID2container::WID2struct::encodeID, FAPIDXX_assert, fapidxx::WID2container::WID2struct::get(), fapidxx::WID2container::WID2struct::ID, fapidxx::WID2container::WID2struct::idlen, setwid2(), fapidxx::stringfromfstring(), wasascii, and wid2.

76  {
77  /*
78  * copy content immediately such that we do not rely on the ID string
79  * being placed at byte offset 0 in WID2container::WID2struct
80  */
81  int w2size=sizeof(WID2container::WID2struct);
82  FAPIDXX_assert(w2size<=slen,
83  "WID2container::setwid2: string is too short");
84  WID2container::WID2struct* ws=new WID2container::WID2struct;
85  std::memcpy(ws, fstring, w2size);
86  // check for special ID, expect ASCII encoding if not ID does not match
87  if (std::strncmp(ws->ID, WID2container::WID2struct::encodeID,
89  {
90  this->setwid2(stringfromfstring(fstring, slen));
91  this->wasascii=true;
92  }
93  else
94  {
95  /*
96  * The byte sequence fstring points to is the content of a
97  * WID2container::WID2struct struct. Create a WID2container::WID2struct
98  * in memory, copy the memory contents fstring points to into
99  * this struct and read the WID2 data from it.
100  */
101  this->wid2=ws->get();
102  this->wasascii=false;
103  }
104  delete ws;
105  } // void WID2container::setwid2(char *fstring, ftnlen slen)
void setwid2(const std::string &line)
fill data fields from a conventional WID2 line
sff::WID2 wid2
WID2 data.
static const char * encodeID
ID indicating the WID2 is encoded in binary form in the WID2 line.
bool wasascii
true, if original data was ASCII encoded
#define FAPIDXX_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:157
std::string stringfromfstring(char *fstring, ftnlen slen)
create a C++ string from a Fortran string
Definition: helper.cc:51
static const unsigned short idlen
Here is the call graph for this function: