MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
IO Class Reference
Collaboration diagram for IO:

Public Member Functions

 IO (void)
 
 IO (int argc, char *argv[])
 
 ~IO (void)
 
int nMeasures (void) const
 
int nControls (void) const
 
int Parse (int argc, char *argv[])
 
int Setup (int argc, char *argv[])
 
const std::vector< double > & Measures (void) const
 
std::vector< double > & Controls (void)
 
int ReadMeasures (void)
 
int SendControls (void)
 

Private Attributes

s2s_t s2s_measures
 
BasicIOmeasures
 
s2s_t s2s_controls
 
BasicIOcontrols
 

Detailed Description

Definition at line 159 of file trim.cc.

Constructor & Destructor Documentation

IO::IO ( void  )
inline

Definition at line 167 of file trim.cc.

BasicIO & measures
Definition: trim.cc:162
BasicIO & controls
Definition: trim.cc:164
static StreamBasicIO stream_basic_IO
Definition: trim.cc:84
IO::IO ( int  argc,
char *  argv[] 
)

Definition at line 184 of file trim.cc.

References Setup().

186 {
187  if (Setup(argc, argv) == EXIT_FAILURE) {
188  throw;
189  }
190 }
int Setup(int argc, char *argv[])
Definition: trim.cc:275
BasicIO & measures
Definition: trim.cc:162
BasicIO & controls
Definition: trim.cc:164
static StreamBasicIO stream_basic_IO
Definition: trim.cc:84

Here is the call graph for this function:

IO::~IO ( void  )
inline

Definition at line 169 of file trim.cc.

169 {};

Member Function Documentation

std::vector<double>& IO::Controls ( void  )
inline

Definition at line 178 of file trim.cc.

References s2s_t::dbuf, and s2s_controls.

Referenced by NRTrim::DoTrim(), and TrimEval::FuncEval().

178 { return s2s_controls.dbuf; };
std::vector< double > dbuf
Definition: s2s.h:69
s2s_t s2s_controls
Definition: trim.cc:163
const std::vector<double>& IO::Measures ( void  ) const
inline

Definition at line 177 of file trim.cc.

References s2s_t::dbuf, and s2s_measures.

Referenced by NRTrim::DoTrim(), and TrimEval::FuncEval().

177 { return s2s_measures.dbuf; };
std::vector< double > dbuf
Definition: s2s.h:69
s2s_t s2s_measures
Definition: trim.cc:161
int IO::nControls ( void  ) const
inline

Definition at line 172 of file trim.cc.

References s2s_t::nChannels, and s2s_controls.

Referenced by main().

172 { return s2s_controls.nChannels; };
int nChannels
Definition: s2s.h:56
s2s_t s2s_controls
Definition: trim.cc:163
int IO::nMeasures ( void  ) const
inline

Definition at line 171 of file trim.cc.

References s2s_t::nChannels, and s2s_measures.

171 { return s2s_measures.nChannels; };
int nChannels
Definition: s2s.h:56
s2s_t s2s_measures
Definition: trim.cc:161
int IO::Parse ( int  argc,
char *  argv[] 
)

Definition at line 193 of file trim.cc.

References getopt(), s2s_t::host, s2s_t::nChannels, optarg, s2s_t::path, s2s_controls, s2s_measures, and STRLENOF.

Referenced by Setup().

194 {
195  while (true) {
196  int opt = getopt(argc, argv, "c:f:H:m:");
197  if (opt == EOF) {
198  break;
199  }
200 
201  s2s_t *s2s = 0;
202 
203  switch (opt) {
204  case 'H':
205  if (strncasecmp(optarg, "measures:", STRLENOF("measures:")) == 0) {
206  optarg += STRLENOF("measures:");
207  s2s = &s2s_measures;
208 
209  } else if (strncasecmp(optarg, "controls:", STRLENOF("controls:")) == 0) {
210  optarg += STRLENOF("controls:");
211  s2s = &s2s_controls;
212 
213  } else {
214  silent_cerr("unknown value \"" << optarg << "\" for -H switch" << std::endl);
215  throw;
216  }
217 
218  if (strncasecmp(optarg, "inet:", STRLENOF("inet:")) == 0) {
219  optarg += STRLENOF("inet:");
220  s2s->host = optarg;
221 
222  } else if (strncasecmp(optarg, "path:", STRLENOF("path:")) == 0) {
223  optarg += STRLENOF("path:");
224  s2s->path = optarg;
225 
226  } else if (strcasecmp(optarg, "stdin") == 0) {
227  if (s2s != &s2s_measures) {
228  silent_cerr("invalid value \"" << optarg << "\" for -H switch" << std::endl);
229  throw;
230  }
231  break;
232 
233  } else if (strcasecmp(optarg, "stdout") == 0) {
234  if (s2s != &s2s_controls) {
235  silent_cerr("invalid value \"" << optarg << "\" for -H switch" << std::endl);
236  throw;
237  }
238  break;
239 
240  } else {
241  silent_cerr("unknown value \"" << optarg << "\" for -H switch" << std::endl);
242  throw;
243  }
244 
245  break;
246 
247  case 'c': {
248  char *next;
249 
250  s2s_controls.nChannels = strtoul(optarg, &next, 10);
251 
252  if (next == NULL || next[0] != '\0') {
253  silent_cerr("invalid value \"" << optarg << "\" for -c switch" << std::endl);
254  throw;
255  }
256  } break;
257 
258  case 'm': {
259  char *next;
260 
261  s2s_measures.nChannels = strtoul(optarg, &next, 10);
262 
263  if (next == NULL || next[0] != '\0') {
264  silent_cerr("invalid value \"" << optarg << "\" for -m switch" << std::endl);
265  throw;
266  }
267  } break;
268  }
269  }
270 
271  return 0;
272 }
int nChannels
Definition: s2s.h:56
s2s_t s2s_controls
Definition: trim.cc:163
const char * path
Definition: s2s.h:57
s2s_t s2s_measures
Definition: trim.cc:161
int getopt(int argc, char *const argv[], const char *opts)
Definition: getopt.c:93
#define STRLENOF(s)
Definition: mbdyn.h:166
const char * host
Definition: s2s.h:59
Definition: s2s.h:54
char * optarg
Definition: getopt.c:74

Here is the call graph for this function:

int IO::ReadMeasures ( void  )
inline

Definition at line 180 of file trim.cc.

References measures, BasicIO::ReadMeasures(), and s2s_measures.

Referenced by TrimEval::FuncEval().

180 { return measures.ReadMeasures(s2s_measures); };
BasicIO & measures
Definition: trim.cc:162
s2s_t s2s_measures
Definition: trim.cc:161
virtual int ReadMeasures(s2s_t &s2s)=0

Here is the call graph for this function:

int IO::SendControls ( void  )
inline

Definition at line 181 of file trim.cc.

References controls, s2s_controls, and BasicIO::SendControls().

Referenced by TrimEval::FuncEval().

181 { return controls.SendControls(s2s_controls); };
BasicIO & controls
Definition: trim.cc:164
s2s_t s2s_controls
Definition: trim.cc:163
virtual int SendControls(s2s_t &s2s)=0

Here is the call graph for this function:

int IO::Setup ( int  argc,
char *  argv[] 
)

Definition at line 275 of file trim.cc.

References buf, controls, s2s_t::dbuf, s2s_t::host, measures, s2s_t::nChannels, Parse(), s2s_t::path, s2s_t::prepare(), s2s_controls, s2s_measures, s2s_t::sock, socket_basic_IO, and stream_basic_IO.

Referenced by IO().

276 {
277  try {
278  Parse(argc, argv);
279 
280  } catch (...) {
281  return EXIT_FAILURE;
282  }
283 
285  try {
287 
288  } catch (...) {
289  return EXIT_FAILURE;
290  }
291  }
292 
294  try {
296 
297  } catch (...) {
298  return EXIT_FAILURE;
299  }
300  }
301 
302  if (s2s_measures.sock == -1) {
304 
305  if (s2s_measures.nChannels == 0) {
306  std::string buf;
307  std::getline(std::cin, buf);
308 
309  std::istringstream str(buf);
310 
311  for (;; s2s_measures.nChannels++) {
312  double d;
313 
314  str >> d;
315 
316  if (!str) {
317  break;
318  }
319 
320  s2s_measures.dbuf.insert(s2s_measures.dbuf.end(), d);
321  }
322 
323  } else {
325  }
326 
327  } else {
329 
330  if (s2s_measures.nChannels == 0) {
331  silent_cerr("number of measures required in socket mode" << std::endl);
332  return EXIT_FAILURE;
333  }
334 
336  }
337 
338  if (s2s_controls.sock == -1) {
340 
341  } else {
343  }
344 
345  if (s2s_controls.nChannels == 0) {
346  silent_cerr("number of controls required" << std::endl);
347  return EXIT_FAILURE;
348  }
349 
351 
352 
353  return EXIT_SUCCESS;
354 
355 }
int Parse(int argc, char *argv[])
Definition: trim.cc:193
BasicIO & measures
Definition: trim.cc:162
BasicIO & controls
Definition: trim.cc:164
void prepare(void)
int nChannels
Definition: s2s.h:56
static StreamBasicIO stream_basic_IO
Definition: trim.cc:84
std::vector< double > dbuf
Definition: s2s.h:69
int sock
Definition: s2s.h:66
s2s_t s2s_controls
Definition: trim.cc:163
const char * path
Definition: s2s.h:57
static SocketBasicIO socket_basic_IO
Definition: trim.cc:76
s2s_t s2s_measures
Definition: trim.cc:161
const char * host
Definition: s2s.h:59
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333

Here is the call graph for this function:

Member Data Documentation

BasicIO& IO::controls
private

Definition at line 164 of file trim.cc.

Referenced by SendControls(), and Setup().

BasicIO& IO::measures
private

Definition at line 162 of file trim.cc.

Referenced by ReadMeasures(), and Setup().

s2s_t IO::s2s_controls
private

Definition at line 163 of file trim.cc.

Referenced by Controls(), nControls(), Parse(), SendControls(), and Setup().

s2s_t IO::s2s_measures
private

Definition at line 161 of file trim.cc.

Referenced by Measures(), nMeasures(), Parse(), ReadMeasures(), and Setup().


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