Pointwise Plugin SDK
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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_
Format &quot;%*e&quot;.
FormatType
Formatted output types for floating point values.
Format &quot;%.*g&quot;.
unsigned int PWP_UINT32
32-bit unsigned integer
Definition: apiPWP.h:210
The abstract PwpFileWriter class.
PwpFile & file_
The file being written.
Format &quot;%*g&quot;.
Pointwise Plugin API (PWP-API)
virtual void setFmtFieldDouble(const int width, const int prec)
default implementation.
#define PwpWriterInterface_PUREVIRTUAL
Definition: PwpFileWriter.h:57
virtual ~PwpWriterInterface()
Destructor.
int fmtPrecDouble_
Double precision format decimals.
virtual ~PwpFileWriter()
Destructor.
virtual bool beginRecord()
NOP default implementation.
Format &quot;%*.*g&quot;.
virtual void getFmtFieldSingle(int &width, int &prec) const
default implementation.
virtual FormatType getFmtType() const
default implementation.
virtual void setFmtType(FormatType type)
default implementation.
bool writefImpl(PWP_INT size, char pad, const char *fmt, va_list &args)
Implementation to write a formatted string value.
Format &quot;%g&quot;.
Format &quot;%*f&quot;.
Format &quot;%.*f&quot;.
virtual void getFmtFieldDouble(int &width, int &prec) const
default implementation.
Writes solver files.
Definition: PwpFile.h:110
bool writef(const char *fmt,...)
Writes a formatted string value.
Format &quot;%.*e&quot;.
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.
int fmtFieldWdDouble_
Double precision format field width.
Format &quot;%*.*e&quot;.
int fmtFieldWdSingle_
Single precision format field width.
PwpFileWriter & operator=(const PwpFileWriter &)=delete
FormatType fmtType_
Formatting flags.
The abstract PwpWriterInterface class.
virtual bool endRecord()
NOP default implementation.
int fmtPrecSingle_
Single precision format decimals.
bool writef(PWP_INT size, char pad, const char *fmt,...)
Writes a formatted string value.
virtual void setFmtFieldSingle(const int width, const int prec)
default implementation.
Format &quot;%e&quot;.
PWP_INT32 PWP_INT
integer same size as void*
Definition: apiPWP.h:282
PwpFileWriter(PwpFile &file)
PwpFile constructor.
virtual bool beginRecord(PWP_UINT32, PWP_UINT32=1)
NOP default implementation.
Format &quot;%f&quot;.
Format &quot;%*.*f&quot;.