Pointwise Plugin SDK
PwpFileWriter.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * class PwpWriterInterface
4  * class PwpFileWriter
5  *
6  * (C) 2021 Cadence Design Systems, Inc. All rights reserved worldwide.
7  *
8  ***************************************************************************/
9 
10 #ifndef _PWPFILEWRITER_H_
11 #define _PWPFILEWRITER_H_
12 
13 #include <stdio.h>
14 #include <stdarg.h>
15 
16 extern "C" {
17 
18 #include "apiPWP.h"
19 
20 } /* extern "C" */
21 
22 class PwpFile;
23 
24 
25 #define PwpWriterInterface_METHODS(sfx) \
26  virtual bool beginRecord() sfx \
27  virtual bool beginRecord(PWP_UINT32 bytes, PWP_UINT32 count = 1) sfx \
28  virtual bool endRecord() sfx \
29  virtual bool write(PWP_INT64 val, const char * suffix = 0, \
30  const char * prefix = 0) sfx \
31  virtual bool write(PWP_INT32 val, const char * suffix = 0, \
32  const char * prefix = 0) sfx \
33  virtual bool write(PWP_INT16 val, const char * suffix = 0, \
34  const char * prefix = 0) sfx \
35  virtual bool write(PWP_INT8 val, const char * suffix = 0, \
36  const char * prefix = 0) sfx \
37  virtual bool write(PWP_UINT64 val, const char * suffix = 0, \
38  const char * prefix = 0) sfx \
39  virtual bool write(PWP_UINT32 val, const char * suffix = 0, \
40  const char * prefix = 0) sfx \
41  virtual bool write(PWP_UINT16 val, const char * suffix = 0, \
42  const char * prefix = 0) sfx \
43  virtual bool write(PWP_UINT8 val, const char * suffix = 0, \
44  const char * prefix = 0) sfx \
45  virtual bool write(PWP_FLOAT val, const char * suffix = 0, \
46  const char * prefix = 0) sfx \
47  virtual bool write(PWP_REAL val, const char * suffix = 0, \
48  const char * prefix = 0) sfx \
49  virtual void setFmtFieldSingle(const int width, const int prec) sfx \
50  virtual void getFmtFieldSingle(int &width, int &prec) const sfx \
51  virtual void setFmtFieldDouble(const int width, const int prec) sfx \
52  virtual void getFmtFieldDouble(int &width, int &prec) const sfx \
53  virtual void setFmtType(FormatType type) sfx \
54  virtual FormatType getFmtType() const sfx \
55  virtual bool write(const char * val, PWP_INT size = -1, char pad = 0) sfx
56 
57 #define PwpWriterInterface_PUREVIRTUAL PwpWriterInterface_METHODS(=0;)
58 #define PwpWriterInterface_SUBCLASS PwpWriterInterface_METHODS(;)
59 
60 
266 protected:
267 
269  enum {
270  G_ = 0x00,
271  F_ = 0x01,
272  E_ = 0x02,
273  GFEMask_ = 0x0F,
274 
275  Wd_ = 0x10,
276  Prec_ = 0x20,
278  WPMask_ = 0xF0,
279  };
280 
281 
282 public:
283 
286  enum FormatType {
291 
296 
301  };
302 
303 
304 public:
305 
308  {
309  }
310 
312 
314  /*
315  \param size The number of characters to write. If -1, the entire string
316  is written.
317  \param pad If size > string's length, the pad value will be used to
318  fill the remaining characters.
319  \param fmt The format string (same format as printf).
320  \return true on success.
321  \note The resulting string is limited to 2048 characters.
322  \note The resulting string is written using write(const char*).
323  \note For pwpUnformatted mode, the record byte count is incremented by
324  the number of characters written.
325  */
326  bool
327  writef(PWP_INT size, char pad, const char *fmt, ...)
328  {
329  va_list args;
330  va_start(args, fmt);
331  bool ret = writefImpl(size, pad, fmt, args);
332  va_end(args);
333  return ret;
334  }
335 
336 
338  /*
339  \param fmt The format string (same format as printf).
340  \return true on success.
341  \note The resulting string is limited to 2048 characters.
342  \note The resulting string is written using write(const char*).
343  \note For pwpUnformatted mode, the record byte count is incremented by
344  the number of characters written.
345  */
346  bool
347  writef(const char *fmt, ...)
348  {
349  va_list args;
350  va_start(args, fmt);
351  bool ret = writefImpl(-1L, '\0', fmt, args);
352  va_end(args);
353  return ret;
354  }
355 
356 
357 private:
358 
360  bool
361  writefImpl(PWP_INT size, char pad, const char *fmt, va_list &args)
362  {
363  char msg[2048];
364  int ret = vsnprintf(msg, sizeof(msg), fmt, args);
365  return (0 < ret) && this->write(msg, size, pad);
366  }
367 };
368 
369 
378 public:
380 
386  fmtFieldWdSingle_(13),
387  fmtPrecSingle_(8),
388  fmtFieldWdDouble_(21),
389  fmtPrecDouble_(16),
390  file_(file)
391  {
392  }
393 
395  virtual ~PwpFileWriter() {
396  }
397 
399 
407  virtual void setFmtFieldSingle(const int width, const int prec) {
409  fmtFieldWdSingle_ = width;
410  fmtPrecSingle_ = prec; }
411 
412  virtual void getFmtFieldSingle(int &width, int &prec) const {
413  width = fmtFieldWdSingle_;
414  prec = fmtPrecSingle_; }
415 
416  virtual void setFmtFieldDouble(const int width, const int prec) {
417  fmtFieldWdDouble_ = width;
418  fmtPrecDouble_ = prec; }
419 
420  virtual void getFmtFieldDouble(int &width, int &prec) const {
421  width = fmtFieldWdDouble_;
422  prec = fmtPrecDouble_; }
424 
426 
431  virtual void setFmtType(FormatType type) {
432  fmtType_ = type; }
433 
435 
438  virtual FormatType getFmtType() const {
439  return fmtType_; }
440 
441 
443 
447  virtual bool beginRecord() {
449  return true;
450  }
451 
452  virtual bool beginRecord(PWP_UINT32 /*bytes*/, PWP_UINT32 /*count*/ = 1) {
453  return true;
454  }
455 
456  virtual bool endRecord() {
457  return true;
458  }
460 
461 
462 private:
463 
464  PwpFileWriter & operator=(const PwpFileWriter & /*rhs*/) = delete;
465 
466 
467 protected:
468 
475 };
476 
477 #endif // _PWPFILEWRITER_H_
PwpWriterInterface::FormatWdPrecF
@ FormatWdPrecF
Format "%*.*f".
Definition: PwpFileWriter.h:293
PwpFileWriter::endRecord
virtual bool endRecord()
NOP default implementation.
Definition: PwpFileWriter.h:456
PwpWriterInterface::Prec_
@ Prec_
Definition: PwpFileWriter.h:276
PwpFileWriter::getFmtFieldDouble
virtual void getFmtFieldDouble(int &width, int &prec) const
default implementation.
Definition: PwpFileWriter.h:420
PwpWriterInterface::WdPrec_
@ WdPrec_
Definition: PwpFileWriter.h:277
PwpFileWriter::PwpFileWriter
PwpFileWriter(PwpFile &file)
PwpFile constructor.
Definition: PwpFileWriter.h:384
PWP_UINT32
unsigned int PWP_UINT32
32-bit unsigned integer
Definition: apiPWP.h:210
PwpWriterInterface::G_
@ G_
Definition: PwpFileWriter.h:270
PwpFileWriter::fmtFieldWdSingle_
int fmtFieldWdSingle_
Single precision format field width.
Definition: PwpFileWriter.h:470
PwpWriterInterface::Wd_
@ Wd_
Definition: PwpFileWriter.h:275
PwpWriterInterface::WPMask_
@ WPMask_
Definition: PwpFileWriter.h:278
PwpFileWriter::~PwpFileWriter
virtual ~PwpFileWriter()
Destructor.
Definition: PwpFileWriter.h:395
PwpWriterInterface::writefImpl
bool writefImpl(PWP_INT size, char pad, const char *fmt, va_list &args)
Implementation to write a formatted string value.
Definition: PwpFileWriter.h:361
PwpFileWriter::beginRecord
virtual bool beginRecord()
NOP default implementation.
Definition: PwpFileWriter.h:448
PwpWriterInterface::FormatWdPrecG
@ FormatWdPrecG
Format "%*.*g".
Definition: PwpFileWriter.h:288
PwpWriterInterface::F_
@ F_
Definition: PwpFileWriter.h:271
PwpWriterInterface::FormatWdF
@ FormatWdF
Format "%*f".
Definition: PwpFileWriter.h:294
PwpWriterInterface::E_
@ E_
Definition: PwpFileWriter.h:272
PwpFileWriter::file_
PwpFile & file_
The file being written.
Definition: PwpFileWriter.h:474
PwpFileWriter::setFmtFieldDouble
virtual void setFmtFieldDouble(const int width, const int prec)
default implementation.
Definition: PwpFileWriter.h:416
PwpFileWriter::getFmtType
virtual FormatType getFmtType() const
default implementation.
Definition: PwpFileWriter.h:438
PwpWriterInterface_PUREVIRTUAL
#define PwpWriterInterface_PUREVIRTUAL
Definition: PwpFileWriter.h:57
PwpWriterInterface::FormatG
@ FormatG
Format "%g".
Definition: PwpFileWriter.h:287
PwpWriterInterface::FormatWdE
@ FormatWdE
Format "%*e".
Definition: PwpFileWriter.h:299
PwpFileWriter::fmtFieldWdDouble_
int fmtFieldWdDouble_
Double precision format field width.
Definition: PwpFileWriter.h:472
PwpWriterInterface::FormatPrecG
@ FormatPrecG
Format "%.*g".
Definition: PwpFileWriter.h:290
PwpWriterInterface::FormatPrecE
@ FormatPrecE
Format "%.*e".
Definition: PwpFileWriter.h:300
PwpWriterInterface::FormatF
@ FormatF
Format "%f".
Definition: PwpFileWriter.h:292
PwpWriterInterface::FormatWdPrecE
@ FormatWdPrecE
Format "%*.*e".
Definition: PwpFileWriter.h:298
PwpFileWriter
The abstract PwpFileWriter class.
Definition: PwpFileWriter.h:377
PwpFileWriter::operator=
PwpFileWriter & operator=(const PwpFileWriter &)=delete
PwpWriterInterface::FormatWdG
@ FormatWdG
Format "%*g".
Definition: PwpFileWriter.h:289
PwpFileWriter::getFmtFieldSingle
virtual void getFmtFieldSingle(int &width, int &prec) const
default implementation.
Definition: PwpFileWriter.h:412
PwpFileWriter::fmtPrecSingle_
int fmtPrecSingle_
Single precision format decimals.
Definition: PwpFileWriter.h:471
PwpWriterInterface::writef
bool writef(PWP_INT size, char pad, const char *fmt,...)
Writes a formatted string value.
Definition: PwpFileWriter.h:327
PWP_INT
PWP_INT32 PWP_INT
integer same size as void*
Definition: apiPWP.h:282
PwpWriterInterface::~PwpWriterInterface
virtual ~PwpWriterInterface()
Destructor.
Definition: PwpFileWriter.h:307
PwpFileWriter::setFmtType
virtual void setFmtType(FormatType type)
default implementation.
Definition: PwpFileWriter.h:431
PwpFileWriter::fmtPrecDouble_
int fmtPrecDouble_
Double precision format decimals.
Definition: PwpFileWriter.h:473
PwpFileWriter::fmtType_
FormatType fmtType_
Formatting flags.
Definition: PwpFileWriter.h:469
PwpWriterInterface::write
virtual bool write(PWP_INT64 val, const char *suffix=0, const char *prefix=0)=0
Writes a integer value with proper encoding and byte order.
PwpFile
Writes solver files.
Definition: PwpFile.h:110
apiPWP.h
Pointwise Plugin API (PWP-API)
PwpWriterInterface::GFEMask_
@ GFEMask_
Definition: PwpFileWriter.h:273
PwpWriterInterface::FormatType
FormatType
Formatted output types for floating point values.
Definition: PwpFileWriter.h:286
PwpWriterInterface::FormatE
@ FormatE
Format "%e".
Definition: PwpFileWriter.h:297
PwpFileWriter::setFmtFieldSingle
virtual void setFmtFieldSingle(const int width, const int prec)
default implementation.
Definition: PwpFileWriter.h:408
PwpWriterInterface::FormatPrecF
@ FormatPrecF
Format "%.*f".
Definition: PwpFileWriter.h:295
PwpWriterInterface::writef
bool writef(const char *fmt,...)
Writes a formatted string value.
Definition: PwpFileWriter.h:347
PwpFileWriter::beginRecord
virtual bool beginRecord(PWP_UINT32, PWP_UINT32=1)
NOP default implementation.
Definition: PwpFileWriter.h:452
PwpWriterInterface
The abstract PwpWriterInterface class.
Definition: PwpFileWriter.h:265