Pointwise Plugin SDK
PwpFile.cxx
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * class PwpFile
4  *
5  * Proprietary software product of Pointwise, Inc.
6  * Copyright (c) 1995-2018 Pointwise, Inc.
7  * All rights reserved.
8  *
9  ***************************************************************************/
10 
11 #include "PwpFile.h"
12 #include "PwpFileWriter.h"
13 #include "pwpPlatform.h"
14 
15 #include <cctype>
16 #include <cstring>
17 #include <cstdio>
18 
19 
20 // readOrdered(), writeOrdered() max number of swappable buffer bytes
21 enum {
23 };
24 
25 
26 //***************************************************************************
27 //***************************************************************************
28 //***************************************************************************
29 
30 class PwpAsciiWriter : public PwpFileWriter {
31 public:
32 
34  PwpFileWriter(file)
35  {
36  }
37 
38 
39  virtual ~PwpAsciiWriter()
40  {
41  }
42 
43 
44  virtual bool write(PWP_INT val, const char *suffix = 0,
45  const char *prefix = 0)
46  {
47  return 0 <= fprintf(file_.fp(), "%s%ld%s", (prefix ? prefix : ""),
48  (long)val, (suffix ? suffix : ""));
49  }
50 
51 
52  virtual bool write(PWP_INT64 val, const char *suffix = 0,
53  const char *prefix = 0)
54  {
55  return 0 <= fprintf(file_.fp(), "%s%lld%s", (prefix ? prefix : ""),
56  val, (suffix ? suffix : ""));
57  }
58 
59 
60  virtual bool write(PWP_INT32 val, const char *suffix = 0,
61  const char *prefix = 0)
62  {
63  return 0 <= fprintf(file_.fp(), "%s%ld%s", (prefix ? prefix : ""),
64  (long)val, (suffix ? suffix : ""));
65  }
66 
67 
68  virtual bool write(PWP_INT16 val, const char *suffix = 0,
69  const char *prefix = 0)
70  {
71  return 0 <= fprintf(file_.fp(), "%s%ld%s", (prefix ? prefix : ""),
72  (long)val, (suffix ? suffix : ""));
73  }
74 
75 
76  virtual bool write(PWP_INT8 val, const char *suffix = 0,
77  const char *prefix = 0)
78  {
79  return 0 <= fprintf(file_.fp(), "%s%ld%s", (prefix ? prefix : ""),
80  (long)val, (suffix ? suffix : ""));
81  }
82 
83 
84  virtual bool write(PWP_UINT val, const char *suffix = 0,
85  const char *prefix = 0)
86  {
87  return 0 <= fprintf(file_.fp(), "%s%lu%s", (prefix ? prefix : ""),
88  (unsigned long)val, (suffix ? suffix : ""));
89  }
90 
91 
92  virtual bool write(PWP_UINT64 val, const char *suffix = 0,
93  const char *prefix = 0)
94  {
95  return 0 <= fprintf(file_.fp(), "%s%llu%s", (prefix ? prefix : ""),
96  (unsigned long long)val, (suffix ? suffix : ""));
97  }
98 
99 
100  virtual bool write(PWP_UINT32 val, const char *suffix = 0,
101  const char *prefix = 0)
102  {
103  return 0 <= fprintf(file_.fp(), "%s%lu%s", (prefix ? prefix : ""),
104  (unsigned long)val, (suffix ? suffix : ""));
105  }
106 
107 
108  virtual bool write(PWP_UINT16 val, const char *suffix = 0,
109  const char *prefix = 0)
110  {
111  return 0 <= fprintf(file_.fp(), "%s%lu%s", (prefix ? prefix : ""),
112  (unsigned long)val, (suffix ? suffix : ""));
113  }
114 
115 
116  virtual bool write(PWP_UINT8 val, const char *suffix = 0,
117  const char *prefix = 0)
118  {
119  return 0 <= fprintf(file_.fp(), "%s%lu%s", (prefix ? prefix : ""),
120  (unsigned long)val, (suffix ? suffix : ""));
121  }
122 
123 
124  virtual bool write(PWP_FLOAT val, const char *suffix = 0,
125  const char *prefix = 0)
126  {
127  return file_.isDouble() ?
129  (suffix ? suffix : ""), (prefix ? prefix : "")) :
131  (suffix ? suffix : ""), (prefix ? prefix : ""));
132  }
133 
134 
135  virtual bool write(PWP_REAL val, const char *suffix = 0,
136  const char *prefix = 0)
137  {
138  return file_.isSingle() ?
140  (suffix ? suffix : ""), (prefix ? prefix : "")) :
142  (suffix ? suffix : ""), (prefix ? prefix : ""));
143  }
144 
145 
146  virtual bool write(const char * val, PWP_INT size = -1, char /*pad*/ = 0)
147  {
148  if (-1 == size) {
149  size = (PWP_INT)strlen(val);
150  }
151  return 0 <= fprintf(file_.fp(), "%*.*s", (int)size, (int)size, val);
152  }
153 
154 
155 private:
156 
157  bool writeWdPrec(PWP_REAL val, int wd, int prec, const char *sfx,
158  const char *pfx)
159  {
160  switch (fmtType_) {
161  case FormatG:
162  return 0 <= fprintf(file_.fp(), "%s%g%s", pfx, val, sfx);
163  case FormatWdPrecG:
164  return 0 <= fprintf(file_.fp(), "%s%*.*g%s", pfx, wd, prec, val, sfx);
165  case FormatWdG:
166  return 0 <= fprintf(file_.fp(), "%s%*g%s", pfx, wd, val, sfx);
167  case FormatPrecG:
168  return 0 <= fprintf(file_.fp(), "%s%.*g%s", pfx, prec, val, sfx);
169 
170  case FormatF:
171  return 0 <= fprintf(file_.fp(), "%s%f%s", pfx, val, sfx);
172  case FormatWdPrecF:
173  return 0 <= fprintf(file_.fp(), "%s%*.*f%s", pfx, wd, prec, val, sfx);
174  case FormatWdF:
175  return 0 <= fprintf(file_.fp(), "%s%*f%s", pfx, wd, val, sfx);
176  case FormatPrecF:
177  return 0 <= fprintf(file_.fp(), "%s%.*f%s", pfx, prec, val, sfx);
178 
179  case FormatE:
180  return 0 <= fprintf(file_.fp(), "%s%e%s", pfx, val, sfx);
181  case FormatWdPrecE:
182  return 0 <= fprintf(file_.fp(), "%s%*.*e%s", pfx, wd, prec, val, sfx);
183  case FormatWdE:
184  return 0 <= fprintf(file_.fp(), "%s%*e%s", pfx, wd, val, sfx);
185  case FormatPrecE:
186  return 0 <= fprintf(file_.fp(), "%s%.*e%s", pfx, prec, val, sfx);
187  }
188  return false;
189  }
190 };
191 
192 
193 //***************************************************************************
194 //***************************************************************************
195 //***************************************************************************
196 
198 
199  template< typename T >
200  bool writeOrdered(T val) {
201  return writeOrdered(&val, sizeof(T));
202  }
203 
204 public:
205 
207  PwpFileWriter(file)
208  {
209  }
210 
211 
213  {
214  }
215 
216 
217  virtual bool write(PWP_INT val, const char *suffix = 0,
218  const char *prefix = 0)
219  {
220  (void)prefix, (void)suffix;
221  return writeOrdered(val);
222  }
223 
224 
225  virtual bool write(PWP_INT64 val, const char *suffix = 0,
226  const char *prefix = 0)
227  {
228  (void)prefix, (void)suffix;
229  return writeOrdered(val);
230  }
231 
232 
233  virtual bool write(PWP_INT32 val, const char *suffix = 0,
234  const char *prefix = 0)
235  {
236  (void)prefix, (void)suffix;
237  return writeOrdered(val);
238  }
239 
240 
241  virtual bool write(PWP_INT16 val, const char *suffix = 0,
242  const char *prefix = 0)
243  {
244  (void)prefix, (void)suffix;
245  return writeOrdered(val);
246  }
247 
248 
249  virtual bool write(PWP_INT8 val, const char *suffix = 0,
250  const char *prefix = 0)
251  {
252  (void)prefix, (void)suffix;
253  return writeOrdered(val);
254  }
255 
256 
257  virtual bool write(PWP_UINT val, const char *suffix = 0,
258  const char *prefix = 0)
259  {
260  (void)prefix, (void)suffix;
261  return writeOrdered(val);
262  }
263 
264 
265  virtual bool write(PWP_UINT64 val, const char *suffix = 0,
266  const char *prefix = 0)
267  {
268  (void)prefix, (void)suffix;
269  return writeOrdered(val);
270  }
271 
272 
273  virtual bool write(PWP_UINT32 val, const char *suffix = 0,
274  const char *prefix = 0)
275  {
276  (void)prefix, (void)suffix;
277  return writeOrdered(val);
278  }
279 
280 
281  virtual bool write(PWP_UINT16 val, const char *suffix = 0,
282  const char *prefix = 0)
283  {
284  (void)prefix, (void)suffix;
285  return writeOrdered(val);
286  }
287 
288 
289  virtual bool write(PWP_UINT8 val, const char *suffix = 0,
290  const char *prefix = 0)
291  {
292  (void)prefix, (void)suffix;
293  return writeOrdered(val);
294  }
295 
296 
297  virtual bool write(PWP_FLOAT val, const char *suffix = 0,
298  const char *prefix = 0)
299  {
300  (void)prefix, (void)suffix;
301  if (file_.isDouble()) {
302  return writeOrdered((PWP_REAL)val);
303  }
304  return writeOrdered(val);
305  }
306 
307 
308  virtual bool write(PWP_REAL val, const char *suffix = 0,
309  const char *prefix = 0)
310  {
311  (void)prefix, (void)suffix;
312  if (file_.isSingle()) {
313  return writeOrdered((PWP_FLOAT)val);
314  }
315  return writeOrdered(val);
316  }
317 
318 
319  virtual bool write(const char * val, PWP_INT size = -1, char pad = 0)
320  {
321  bool ret = false;
322  if (0 != val) {
323  PWP_INT len = (PWP_INT)strlen(val);
324  if (-1 == size) {
325  size = len;
326  }
327  if (len >= size) {
328  // no padding needed
329  ret = (1 == pwpFileWrite(val, size, 1, file_.fp()));
330  }
331  else if (1 == pwpFileWrite(val, len, 1, file_.fp())) {
332  // str already written, now write pad chars
333  ret = true;
334  const size_t bufSz = 512;
335  char padBuf[bufSz] = { '\0' }; // compiler fills all with zeros
336  if (0 != pad) {
337  memset(padBuf, pad, bufSz);
338  }
339  size -= len; // reduce size by # chars already written
340  while (ret && (bufSz < size)) {
341  ret = (1 == pwpFileWrite(padBuf, bufSz, 1, file_.fp()));
342  size -= bufSz;
343  }
344  // write final partial buffer (size == 0 is okay)
345  ret = ret && (1 == pwpFileWrite(padBuf, size, 1, file_.fp()));
346  }
347  }
348  return ret;
349  }
350 
351 private:
352 
353  bool
354  writeOrdered(const void *buf, size_t size)
355  {
356  bool ret = false;
357  FILE *fp = file_.fp();
358  if (0 == buf) {
359  // bad
360  }
361  else if (1 == size) {
362  ret = (1 == pwpFileWrite(buf, size, 1, fp));
363  }
364  else if (!(size & 0x1) && (ORDERED_MAXSIZE >= size)) {
365  static unsigned char tmpBuf[ORDERED_MAXSIZE];
366  if (file_.needByteSwap()) {
367  const char *cbuf = (const char *)buf;
368  size_t hNdx = 0;
369  size_t tNdx = size - 1;
370  while (hNdx < tNdx) {
371  tmpBuf[hNdx] = cbuf[tNdx];
372  tmpBuf[tNdx--] = cbuf[hNdx++];
373  }
374  buf = tmpBuf; // write tmpBuf instead
375  }
376  ret = (1 == pwpFileWrite(buf, size, 1, fp));
377  }
378  return ret;
379  }
380 };
381 
382 
383 //***************************************************************************
384 //***************************************************************************
385 //***************************************************************************
386 
388 public:
389 
391  PwpFileWriter(file)
392  {
394  }
395 
396 
398  {
400  }
401 
402 
403  virtual bool beginRecord() {
404  endRecord();
406  return 0 != PwuUnfRecBegin(&file_.unfData());
407  }
408 
409 
410  virtual bool beginRecord(PWP_UINT32 bytes, PWP_UINT32 count = 1) {
411  endRecord();
413  return 0 != PwuUnfRecBeginFixed(&file_.unfData(), bytes, count);
414  }
415 
416 
417  virtual bool endRecord() {
418  return 0 != PwuUnfRecEnd(&file_.unfData());
419  }
420 
421 
422  virtual bool write(PWP_INT val, const char *suffix = 0,
423  const char *prefix = 0)
424  {
425  (void)prefix, (void)suffix;
426  return 0 != PwuUnfRecWriteINT(&file_.unfData(), val);
427  }
428 
429 
430  virtual bool write(PWP_INT64 val, const char *suffix = 0,
431  const char *prefix = 0)
432  {
433  (void)prefix, (void)suffix;
434  return 0 != PwuUnfRecWriteINT64(&file_.unfData(), val);
435  }
436 
437 
438  virtual bool write(PWP_INT32 val, const char *suffix = 0,
439  const char *prefix = 0)
440  {
441  (void)prefix, (void)suffix;
442  return 0 != PwuUnfRecWriteINT32(&file_.unfData(), val);
443  }
444 
445 
446  virtual bool write(PWP_INT16 val, const char *suffix = 0,
447  const char *prefix = 0)
448  {
449  (void)prefix, (void)suffix;
450  return 0 != PwuUnfRecWriteINT16(&file_.unfData(), val);
451  }
452 
453 
454  virtual bool write(PWP_INT8 val, const char *suffix = 0,
455  const char *prefix = 0)
456  {
457  (void)prefix, (void)suffix;
458  return 0 != PwuUnfRecWriteINT8(&file_.unfData(), val);
459  }
460 
461 
462  virtual bool write(PWP_UINT val, const char *suffix = 0,
463  const char *prefix = 0)
464  {
465  (void)prefix, (void)suffix;
466  return 0 != PwuUnfRecWriteUINT(&file_.unfData(), val);
467  }
468 
469 
470  virtual bool write(PWP_UINT64 val, const char *suffix = 0,
471  const char *prefix = 0)
472  {
473  (void)prefix, (void)suffix;
474  return 0 != PwuUnfRecWriteUINT64(&file_.unfData(), val);
475  }
476 
477 
478  virtual bool write(PWP_UINT32 val, const char *suffix = 0,
479  const char *prefix = 0)
480  {
481  (void)prefix, (void)suffix;
482  return 0 != PwuUnfRecWriteUINT32(&file_.unfData(), val);
483  }
484 
485 
486  virtual bool write(PWP_UINT16 val, const char *suffix = 0,
487  const char *prefix = 0)
488  {
489  (void)prefix, (void)suffix;
490  return 0 != PwuUnfRecWriteUINT16(&file_.unfData(), val);
491  }
492 
493 
494  virtual bool write(PWP_UINT8 val, const char *suffix = 0,
495  const char *prefix = 0)
496  {
497  (void)prefix, (void)suffix;
498  return 0 != PwuUnfRecWriteUINT8(&file_.unfData(), val);
499  }
500 
501 
502  virtual bool write(PWP_FLOAT val, const char *suffix = 0,
503  const char *prefix = 0)
504  {
505  (void)prefix, (void)suffix;
506  if (file_.isDouble()) {
507  return 0 != PwuUnfRecWriteREAL(&file_.unfData(), (PWP_REAL)val);
508  }
509  return 0 != PwuUnfRecWriteFLOAT(&file_.unfData(), val);
510  }
511 
512 
513  virtual bool write(PWP_REAL val, const char *suffix = 0,
514  const char *prefix = 0)
515  {
516  (void)prefix, (void)suffix;
517  if (file_.isSingle()) {
518  return 0 != PwuUnfRecWriteFLOAT(&file_.unfData(), (PWP_FLOAT)val);
519  }
520  return 0 != PwuUnfRecWriteREAL(&file_.unfData(), val);
521  }
522 
523 
524  virtual bool write(const char * val, PWP_INT size = -1, char pad = 0)
525  {
526  bool ret = false;
527  if (0 != val) {
528  PWP_INT len = (PWP_INT)strlen(val);
529  if (-1 == size) {
530  size = len;
531  }
532  if (len >= size) {
533  // no padding needed
534  ret = (0 != PwuUnfRecWriteBuf(&file_.unfData(), val, size));
535  }
536  else if (0 != PwuUnfRecWriteBuf(&file_.unfData(), val, len)) {
537  // str already written, now write pad chars
538  ret = true;
539  const size_t bufSz = 512;
540  char padBuf[bufSz] = { '\0' }; // compiler fills all with zeros
541  if (0 != pad) {
542  memset(padBuf, pad, bufSz);
543  }
544  size -= len; // reduce size by # chars already written
545  while (ret && (bufSz < size)) {
546  ret = (0 != PwuUnfRecWriteBuf(&file_.unfData(), padBuf,
547  bufSz));
548  size -= bufSz;
549  }
550  // write final partial buffer (size == 0 is okay)
551  ret = ret && (0 != PwuUnfRecWriteBuf(&file_.unfData(), padBuf,
552  size));
553  }
554  }
555  return ret;
556  }
557 };
558 
559 
560 //***************************************************************************
561 //***************************************************************************
562 //***************************************************************************
563 
564 PwpFile::PwpFile(FILE *fp, std::string filename, int mode) :
565  fp_(0),
566  mode_(0),
567  filename_(),
568  byteOrder_(PWP_ENDIAN_NATIVE),
569  precision_(PWP_PRECISION_DOUBLE),
570  ud_(),
571  writer_(0)
572 {
573  wrap(fp, filename, mode);
574 }
575 
576 
577 PwpFile::PwpFile(std::string filename, int mode) :
578  fp_(0),
579  mode_(0),
580  filename_(),
581  byteOrder_(PWP_ENDIAN_NATIVE),
582  precision_(PWP_PRECISION_DOUBLE),
583  ud_(),
584  writer_(0)
585 {
586  open(filename, mode);
587 }
588 
589 
591 {
592  close();
593 }
594 
595 
596 bool
597 PwpFile::wrap(FILE *fp, std::string filename, int mode)
598 {
599  close();
600  fp_ = fp;
601  if (0 != fp_) {
602  filename_ = filename;
603  mode_ = mode;
604  if (isAscii()) {
605  writer_ = new PwpAsciiWriter(*this);
606  }
607  else if (isBinary()) {
608  writer_ = new PwpBinaryWriter(*this);
609  }
610  else if (isUnformatted()) {
611  writer_ = new PwpUnformattedWriter(*this);
612  }
613  if (0 == writer_) {
614  close(); // bad error
615  }
616  }
617  return 0 != fp_;
618 }
619 
620 
621 bool
622 PwpFile::open(std::string filename, int mode)
623 {
624  return wrap(pwpFileOpen(filename.c_str(), mode), filename, mode);
625 }
626 
627 
628 bool
630 {
631  return 0 != fp_;
632 }
633 
634 
635 bool
637 {
638  // delete writer_ BEFORE closing file so dtor has a chance to use file.
639  delete writer_;
640  writer_ = 0;
641  bool ret = (0 == pwpFileClose(fp_));
642  fp_ = 0;
643  filename_.clear();
644  mode_ = 0;
645  return ret;
646 }
647 
648 
651 {
653  byteOrder_ = byteOrder;
654  return ret;
655 }
656 
657 
659 PwpFile::getByteOrder(bool mapBigLittle) const
660 {
661  return mapBigLittle ? mapToBigLittle(byteOrder_) : byteOrder_;
662 }
663 
664 
667 {
669  precision_ = precision;
670  return ret;
671 }
672 
673 
676 {
677  return precision_;
678 }
679 
680 
681 bool
683 {
684  return 0 != (mode_ & pwpRead);
685 }
686 
687 
688 bool
690 {
691  return 0 != (mode_ & pwpWrite);
692 }
693 
694 
695 bool
697 {
699 }
700 
701 
702 bool
704 {
706 }
707 
708 
709 bool
711 {
712  return 0 != (mode_ & (pwpAscii | pwpFormatted));
713 }
714 
715 
716 bool
718 {
719  return 0 != (mode_ & pwpBinary);
720 }
721 
722 
723 bool
725 {
726  return 0 != (mode_ & pwpUnformatted);
727 }
728 
729 
730 bool
732 {
733  return 0 != pwpFileEof(fp_);
734 }
735 
736 
737 bool
739 {
740  return 0 == pwpFileFlush(fp_);
741 }
742 
743 
744 bool
746 {
747  return 0 == pwpFileGetpos(fp_, &pos);
748 }
749 
750 
751 bool
753 {
754  return 0 == pwpFileSetpos(fp_, &pos);
755 }
756 
757 
758 bool
760 {
762  return 0 != fp_;
763 }
764 
765 
766 bool
768 {
769  size_t sz;
770  return (0 == pwpFileGetSize(fp_, &sz)) ?
771  ((size = (PWP_UINT64)sz), true) :
772  false;
773 }
774 
775 
776 bool
777 PwpFile::getSize(const char *filename, PWP_UINT64 &size)
778 {
779  size_t sz;
780  return (0 == pwpFilenameGetSize(filename, &sz)) ?
781  ((size = (PWP_UINT64)sz), true) :
782  false;
783 }
784 
785 
786 void
787 PwpFile::setName(std::string filename)
788 {
789  filename_ = filename;
790 }
791 
792 
793 const char *
795 {
796  return filename_.c_str();
797 }
798 
799 
800 bool
801 PwpFile::read(void *buf, size_t size, size_t count)
802 {
803  return count == pwpFileRead(buf, size, count, fp_);
804 }
805 
806 
807 bool
809 {
810  int c;
811  while (1) {
812  if (!getcNotEOF(c)) {
813  return false;
814  }
815  if (!std::isspace(c)) {
816  break;
817  }
818  }
819  // put back non-whitespace char
820  return ungetc(c);
821 }
822 
823 
824 bool
825 PwpFile::readToken(std::string &tok)
826 {
827  tok.clear();
828  if (wspaceSkip()) {
829  tok.reserve(DefReserve);
830  while (1) {
831  const int c = ::fgetc(fp_);
832  if (EOF == c) {
833  break;
834  }
835  if (!std::isspace(c)) {
836  tok += static_cast<char>(c);
837  continue;
838  }
839  // found trailing white space char, put it back and stop
840  ::ungetc(c, fp_);
841  break;
842  }
843  }
844  return !tok.empty();
845 }
846 
847 
848 bool
849 PwpFile::readAlphaToken(std::string &tok)
850 {
851  tok.clear();
852  if (wspaceSkip()) {
853  tok.reserve(DefReserve);
854  while (1) {
855  const int c = ::fgetc(fp_);
856  if (EOF == c) {
857  break;
858  }
859  if (std::isalpha(c)) {
860  tok += static_cast<char>(c);
861  continue;
862  }
863  // found non-alpha char put it back
864  ::ungetc(c, fp_);
865  break;
866  }
867  }
868  return !tok.empty();
869 }
870 
871 
872 bool
873 PwpFile::readUntil(std::string &str, const int stopC, int maxLen,
874  const bool doTrim)
875 {
876  if (0 == maxLen) {
877  maxLen = 2048; // sanity check
878  }
879  str.clear();
880  str.reserve(DefReserve);
881  int len = 0;
882  while (len <= maxLen) {
883  const int c = ::fgetc(fp_);
884  // check this first to support stopC == EOF
885  if (stopC == c) {
886  if (doTrim) {
887  trim(str);
888  }
889  return true;
890  }
891  if (EOF == c) {
892  break;
893  }
894  str += static_cast<char>(c);
895  ++len;
896  }
897  return false;
898 }
899 
900 
901 bool
903 {
904  (void)base;
905  while (cnt--) {
906  if (1 != fscanf(*this, "%lf", v++)) {
907  return false;
908  }
909  }
910  return true;
911 }
912 
913 
914 bool
916 {
917  (void)base;
918  while (cnt--) {
919  if (1 != fscanf(*this, "%f", v++)) {
920  return false;
921  }
922  }
923  return true;
924 }
925 
926 
927 bool
929 {
930  (void)base;
931  while (cnt--) {
932  if (1 != fscanf(*this, "%u", (unsigned int*)v++)) {
933  return false;
934  }
935  }
936  return true;
937 }
938 
939 
940 bool
941 PwpFile::readAscVal(char *v, PWP_UINT32 cnt, const PWP_UINT32 base)
942 {
943  (void)base;
944  while (cnt--) {
945  if (1 != fscanf(*this, "%c", v++)) {
946  return false;
947  }
948  }
949  return true;
950 }
951 
952 
953 bool
955  PWP_UINT32 maxDigits)
956 {
957  if (0 == maxDigits) {
958  maxDigits = PWP_UINT32_MAX;
959  }
960  std::string tok;
961  if (wspaceSkip()) {
962  tok.reserve(DefReserve);
963  while (0 != maxDigits) {
964  const int c = ::fgetc(fp_);
965  if (EOF == c) {
966  return false;
967  }
968  if (10 == base) {
969  if (std::isdigit(c)) {
970  tok += static_cast<char>(c);
971  --maxDigits;
972  continue;
973  }
974  }
975  else if (16 == base) {
976  if (std::isxdigit(c)) {
977  tok += static_cast<char>(c);
978  --maxDigits;
979  continue;
980  }
981  }
982  else if (8 == base) {
983  if ((c >= '0') && (c <= '7')) {
984  tok += static_cast<char>(c);
985  --maxDigits;
986  continue;
987  }
988  }
989  else if (!std::isspace(c)) {
990  // other base - this is not complete
991  tok += static_cast<char>(c);
992  --maxDigits;
993  continue;
994  }
995  // found non-int char put it back
996  ::ungetc(c, fp_);
997  break;
998  }
999  }
1000  return tok.empty() ? false :
1001  ((val = std::strtoul(tok.c_str(), 0, int(base))), true);
1002 }
1003 
1004 
1005 bool
1007 {
1008  //char *endPtr;
1009  //val = std::strtod(toks.at(0).c_str(), &endPtr);
1010  //return ret;
1011  if (0 == maxDigits) {
1012  maxDigits = PWP_UINT32_MAX;
1013  }
1014  std::string tok;
1015  if (wspaceSkip()) {
1016  tok.reserve(DefReserve);
1017  while (1) {
1018  const int c = ::fgetc(fp_);
1019  if (EOF == c) {
1020  return false;
1021  }
1022  if (std::isdigit(c)) {
1023  tok += static_cast<char>(c);
1024  continue;
1025  }
1026  // found non-alpha char put it back
1027  ::ungetc(c, fp_);
1028  break;
1029  }
1030  }
1031  return tok.empty() ? false :
1032  ((val = std::strtoul(tok.c_str(), 0, 10)), true);
1033 }
1034 
1035 bool
1036 PwpFile::unlink(const char *filename)
1037 {
1038  return 0 == pwpFileDelete(filename);
1039 }
1040 
1041 
1044 {
1046 }
1047 
1048 
1051 {
1052  PWP_ENDIANNESS ret = byteOrder;
1053  switch (byteOrder) {
1054  case PWP_ENDIAN_NATIVE:
1055  ret = getOsByteOrder();
1056  break;
1057  case PWP_ENDIAN_FOREIGN:
1059  PWP_ENDIAN_BIG);
1060  break;
1061  case PWP_ENDIAN_BIG:
1062  case PWP_ENDIAN_LITTLE:
1063  break; // already set above
1064  default:
1065  ret = PWP_ENDIAN_ERROR;
1066  break;
1067  }
1068  return ret;
1069 }
1070 
1071 
1072 bool
1074 {
1075  return getOsByteOrder() != mapToBigLittle(byteOrder);
1076 }
1077 
1078 
1079 bool
1081  return writer_ && writer_->beginRecord();
1082 }
1083 
1084 
1085 bool
1087  return writer_ && writer_->beginRecord(bytes, count);
1088 }
1089 
1090 
1091 bool
1093  return writer_ && writer_->endRecord();
1094 }
1095 
1096 
1097 bool
1098 PwpFile::write(PWP_INT val, const char *suffix,
1099  const char *prefix)
1100 {
1101  return writer_ && writer_->write(val, suffix, prefix);
1102 }
1103 
1104 
1105 bool
1106 PwpFile::write(PWP_INT64 val, const char *suffix,
1107  const char *prefix)
1108 {
1109  return writer_ && writer_->write(val, suffix, prefix);
1110 }
1111 
1112 
1113 bool
1114 PwpFile::write(PWP_INT32 val, const char *suffix,
1115  const char *prefix)
1116 {
1117  return writer_ && writer_->write(val, suffix, prefix);
1118 }
1119 
1120 
1121 bool
1122 PwpFile::write(PWP_INT16 val, const char *suffix,
1123  const char *prefix)
1124 {
1125  return writer_ && writer_->write(val, suffix, prefix);
1126 }
1127 
1128 
1129 bool
1130 PwpFile::write(PWP_INT8 val, const char *suffix,
1131  const char *prefix)
1132 {
1133  return writer_ && writer_->write(val, suffix, prefix);
1134 }
1135 
1136 
1137 bool
1138 PwpFile::write(PWP_UINT val, const char *suffix,
1139  const char *prefix)
1140 {
1141  return writer_ && writer_->write(val, suffix, prefix);
1142 }
1143 
1144 
1145 bool
1146 PwpFile::write(PWP_UINT64 val, const char *suffix,
1147  const char *prefix)
1148 {
1149  return writer_ && writer_->write(val, suffix, prefix);
1150 }
1151 
1152 
1153 bool
1154 PwpFile::write(PWP_UINT32 val, const char *suffix,
1155  const char *prefix)
1156 {
1157  return writer_ && writer_->write(val, suffix, prefix);
1158 }
1159 
1160 
1161 bool
1162 PwpFile::write(PWP_UINT16 val, const char *suffix,
1163  const char *prefix)
1164 {
1165  return writer_ && writer_->write(val, suffix, prefix);
1166 }
1167 
1168 
1169 bool
1170 PwpFile::write(PWP_UINT8 val, const char *suffix,
1171  const char *prefix)
1172 {
1173  return writer_ && writer_->write(val, suffix, prefix);
1174 }
1175 
1176 
1177 bool
1178 PwpFile::write(PWP_FLOAT val, const char *suffix,
1179  const char *prefix)
1180 {
1181  return writer_ && writer_->write(val, suffix, prefix);
1182 }
1183 
1184 
1185 bool
1186 PwpFile::write(PWP_REAL val, const char *suffix,
1187  const char *prefix)
1188 {
1189  return writer_ && writer_->write(val, suffix, prefix);
1190 }
1191 
1192 
1193 void
1194 PwpFile::setFmtFieldSingle(const int width, const int prec)
1195 {
1196  if (0 != writer_) {
1197  writer_->setFmtFieldSingle(width, prec);
1198  }
1199 }
1200 
1201 
1202 void
1203 PwpFile::getFmtFieldSingle(int &width, int &prec) const
1204 {
1205  if (0 != writer_) {
1206  writer_->getFmtFieldSingle(width, prec);
1207  }
1208 }
1209 
1210 
1211 void
1212 PwpFile::setFmtFieldDouble(const int width, const int prec)
1213 {
1214  if (0 != writer_) {
1215  writer_->setFmtFieldDouble(width, prec);
1216  }
1217 }
1218 
1219 
1220 void
1221 PwpFile::getFmtFieldDouble(int &width, int &prec) const
1222 {
1223  if (0 != writer_) {
1224  writer_->getFmtFieldDouble(width, prec);
1225  }
1226 }
1227 
1228 
1229 
1230 void
1232 {
1233  if (0 != writer_) {
1234  writer_->setFmtType(type);
1235  }
1236 }
1237 
1238 
1241 {
1243 }
1244 
1245 
1246 bool
1247 PwpFile::write(const char * val, PWP_INT size, char pad)
1248 {
1249  return writer_ && writer_->write(val, size, pad);
1250 }
1251 
1252 
1253 //***************************************************************************
1254 //***************************************************************************
1255 //***************************************************************************
1256 
1257 PwpFileRecord::PwpFileRecord(PwpFile &file, bool doBeginRecord) :
1258  file_(file)
1259 {
1260  if (doBeginRecord) {
1261  beginRecord();
1262  }
1263 }
1264 
1265 
1267  file_(file)
1268 {
1269  beginRecord(bytes, count);
1270 }
1271 
1272 
1274 {
1275  if (file_.isOpen()) {
1276  endRecord();
1277  }
1278 }
1279 
1280 
1281 bool
1283  return file_.beginRecord();
1284 }
1285 
1286 
1287 bool
1289  return file_.beginRecord(bytes, count);
1290 }
1291 
1292 
1293 bool
1295  return file_.endRecord();
1296 }
1297 
1298 
1299 bool
1300 PwpFileRecord::write(PWP_INT val, const char *suffix,
1301  const char *prefix)
1302 {
1303  return file_.write(val, suffix, prefix);
1304 }
1305 
1306 
1307 bool
1308 PwpFileRecord::write(PWP_INT64 val, const char *suffix,
1309  const char *prefix)
1310 {
1311  return file_.write(val, suffix, prefix);
1312 }
1313 
1314 
1315 bool
1316 PwpFileRecord::write(PWP_INT32 val, const char *suffix,
1317  const char *prefix)
1318 {
1319  return file_.write(val, suffix, prefix);
1320 }
1321 
1322 
1323 bool
1324 PwpFileRecord::write(PWP_INT16 val, const char *suffix,
1325  const char *prefix)
1326 {
1327  return file_.write(val, suffix, prefix);
1328 }
1329 
1330 
1331 bool
1332 PwpFileRecord::write(PWP_INT8 val, const char *suffix,
1333  const char *prefix)
1334 {
1335  return file_.write(val, suffix, prefix);
1336 }
1337 
1338 
1339 bool
1340 PwpFileRecord::write(PWP_UINT val, const char *suffix,
1341  const char *prefix)
1342 {
1343  return file_.write(val, suffix, prefix);
1344 }
1345 
1346 
1347 bool
1348 PwpFileRecord::write(PWP_UINT64 val, const char *suffix,
1349  const char *prefix)
1350 {
1351  return file_.write(val, suffix, prefix);
1352 }
1353 
1354 
1355 bool
1356 PwpFileRecord::write(PWP_UINT32 val, const char *suffix,
1357  const char *prefix)
1358 {
1359  return file_.write(val, suffix, prefix);
1360 }
1361 
1362 
1363 bool
1364 PwpFileRecord::write(PWP_UINT16 val, const char *suffix,
1365  const char *prefix)
1366 {
1367  return file_.write(val, suffix, prefix);
1368 }
1369 
1370 
1371 bool
1372 PwpFileRecord::write(PWP_UINT8 val, const char *suffix,
1373  const char *prefix)
1374 {
1375  return file_.write(val, suffix, prefix);
1376 }
1377 
1378 
1379 bool
1380 PwpFileRecord::write(PWP_FLOAT val, const char *suffix,
1381  const char *prefix)
1382 {
1383  return file_.write(val, suffix, prefix);
1384 }
1385 
1386 
1387 bool
1388 PwpFileRecord::write(PWP_REAL val, const char *suffix,
1389  const char *prefix)
1390 {
1391  return file_.write(val, suffix, prefix);
1392 }
1393 
1394 
1395 void
1396 PwpFileRecord::setFmtFieldSingle(const int width, const int prec)
1397 {
1398  file_.setFmtFieldSingle(width, prec);
1399 }
1400 
1401 
1402 void
1403 PwpFileRecord::getFmtFieldSingle(int &width, int &prec) const
1404 {
1405  file_.getFmtFieldSingle(width, prec);
1406 }
1407 
1408 
1409 void
1410 PwpFileRecord::setFmtFieldDouble(const int width, const int prec)
1411 {
1412  file_.setFmtFieldDouble(width, prec);
1413 }
1414 
1415 
1416 void
1417 PwpFileRecord::getFmtFieldDouble(int &width, int &prec) const
1418 {
1419  file_.getFmtFieldDouble(width, prec);
1420 }
1421 
1422 
1423 
1424 void
1426 {
1427  file_.setFmtType(type);
1428 }
1429 
1430 
1433 {
1434  return file_.getFmtType();
1435 }
1436 
1437 
1438 bool
1439 PwpFileRecord::write(const char * val, PWP_INT size, char pad)
1440 {
1441  return file_.write(val, size, pad);
1442 }
unsigned char PWP_UINT8
8-bit unsigned integer
Definition: apiPWP.h:170
PWP_BOOL PwuUnfRecBeginFixed(PWU_UNFDATA *pUData, PWP_UINT32 bytes, PWP_UINT32 count)
Prepares a PWU_UNFDATA block for writing a new unformatted data record when the amount of data being ...
virtual bool write(PWP_UINT8 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:289
static std::string & trim(std::string &s)
Definition: PwpFile.h:620
bool readUntil(std::string &str, const int stopC, int maxLen=0, const bool doTrim=false)
Reads up to maxLen chars until the specified stop char is encountered.
Definition: PwpFile.cxx:873
FormatType
Formatted output types for floating point values.
bool writeOrdered(const void *buf, size_t size)
Definition: PwpFile.cxx:354
PWP_ENDIANNESS getByteOrder(bool mapBigLittle=false) const
Get the byte order used for writes.
Definition: PwpFile.cxx:659
PWP_BOOL PwuUnfRecWriteUINT16(PWU_UNFDATA *pUData, PWP_UINT16 val)
Write a PWP_UINT16 value to the current record with endian order applied.
bool wrap(FILE *fp, std::string filename=std::string(), int mode=0)
Take ownership of fp opened using pwpFileOpen(filename, mode).
Definition: PwpFile.cxx:597
PwpAsciiWriter(PwpFile &file)
Definition: PwpFile.cxx:33
virtual void getFmtFieldSingle(int &width, int &prec) const
Definition: PwpFile.cxx:1203
unsigned long long PWP_UINT64
64-bit unsigned integer
Definition: apiPWP.h:206
virtual bool write(PWP_UINT val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:462
virtual void getFmtFieldSingle(int &width, int &prec) const
Definition: PwpFile.cxx:1403
virtual bool write(PWP_INT32 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:60
unsigned int PWP_UINT32
32-bit unsigned integer
Definition: apiPWP.h:194
virtual void setFmtFieldDouble(const int width, const int prec)
Definition: PwpFile.cxx:1212
virtual bool write(PWP_UINT64 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:470
virtual void getFmtFieldSingle(int &width, int &prec) const
default implementation.
virtual ~PwpFileRecord()
Destructor.
Definition: PwpFile.cxx:1273
int pwpFileEof(FILE *fp)
Queries end-of-file status.
The abstract PwpFileWriter class.
PwpFile & file_
The file being written.
virtual bool beginRecord()
Starts an unformatted record.
Definition: PwpFile.cxx:1080
virtual bool write(PWP_INT val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:1300
bool setPos(const sysFILEPOS &pos)
Set the current file position.
Definition: PwpFile.cxx:752
virtual FormatType getFmtType() const
Definition: PwpFile.cxx:1432
bool isUnformatted() const
Determines if file was opened with pwpUnformatted mode flag.
Definition: PwpFile.cxx:724
virtual void setFmtFieldDouble(const int width, const int prec)
default implementation.
PWP_ENDIANNESS setByteOrder(PWP_ENDIANNESS order)
Set the byte order used for writes.
Definition: PwpFile.cxx:650
virtual bool beginRecord()
Starts an unformatted record.
Definition: PwpFile.cxx:1282
virtual bool write(PWP_UINT16 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:108
virtual void setFmtType(FormatType type)
Definition: PwpFile.cxx:1231
unsigned long PWP_UINT
unsigned integer same size as void*
Definition: apiPWP.h:158
virtual bool write(PWP_INT val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:422
virtual bool write(PWP_UINT val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:84
PWP_BOOL PwuUnfRecWriteBuf(PWU_UNFDATA *pUData, const void *buf, size_t size)
Write a data buffer to the current record.
virtual bool write(PWP_REAL val, const char *suffix=0, const char *prefix=0)
Writes a floating point value with proper precision, encoding and byte order.
Definition: PwpFile.cxx:135
int pwpFileClose(FILE *fp)
Closes a file opened with pwpFileOpen().
int fmtPrecDouble_
Double precision format decimals.
virtual bool write(PWP_UINT val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:257
PWP_ENUM_PRECISION
File precision values.
Definition: apiPWP.h:718
static PWP_ENDIANNESS getOsByteOrder()
Get the OS&#39;s native byte ordering.
Definition: PwpFile.cxx:1043
PWP_ENDIANNESS PwuUnfFileSetEndianness(PWU_UNFDATA *pUData, PWP_ENDIANNESS endianness)
Set the output endianness.
FILE * fp_
The FILE pointer.
Definition: PwpFile.h:715
int pwpFileSetpos(FILE *fp, const sysFILEPOS *pos)
Set the current file position.
FILE * pwpFileOpen(const char *filename, int mode)
Opens a file for I/O.
bool rewind()
Reset position to the beginning of the file.
Definition: PwpFile.cxx:759
virtual bool write(PWP_UINT64 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:92
virtual bool write(PWP_INT64 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:52
size_t pwpFileRead(void *buf, size_t size, size_t count, FILE *fp)
Read an collection of data items from a file.
PWP_BOOL PwuUnfFileBegin(FILE *fp, PWU_UNFDATA *pUData)
Prepares a PWU_UNFDATA block for a new unformatted file I/O session.
bool isWritable() const
Determines if file suports write operations.
Definition: PwpFile.cxx:689
bool writeWdPrec(PWP_REAL val, int wd, int prec, const char *sfx, const char *pfx)
Definition: PwpFile.cxx:157
virtual bool write(const char *val, PWP_INT size=-1, char pad=0)
Writes a string value.
Definition: PwpFile.cxx:524
PWP_BOOL PwuUnfRecWriteINT(PWU_UNFDATA *pUData, PWP_INT val)
Write a PWP_INT value to the current record with endian order applied.
bool writeOrdered(T val)
Definition: PwpFile.cxx:200
PWP_BOOL PwuUnfFileEnd(PWU_UNFDATA *pUData)
Finalize an unformatted file I/O session.
bool isReadable() const
Determines if file suports read operations.
Definition: PwpFile.cxx:682
static bool unlink(const char *filename)
Delete a file.
Definition: PwpFile.cxx:1036
fpos_t sysFILEPOS
File position data type.
Definition: pwpPlatform.h:53
virtual bool beginRecord()
NOP default implementation.
virtual void getFmtFieldDouble(int &width, int &prec) const
Definition: PwpFile.cxx:1221
bool readToken(std::string &tok)
Reads a whitespace delimited token (word).
Definition: PwpFile.cxx:825
bool read(void *buf, size_t size, size_t count)
Read a collection of data items.
Definition: PwpFile.cxx:801
virtual bool write(PWP_INT val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:1098
bool isEof() const
Get the end-of-file status.
Definition: PwpFile.cxx:731
virtual bool write(PWP_INT16 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:446
virtual bool write(PWP_UINT32 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:273
PWP_ENUM_PRECISION precision_
The file&#39;s floating point precision.
Definition: PwpFile.h:719
bool isDouble() const
Determines if floating point precision is PWP_PRECISION_DOUBLE.
Definition: PwpFile.cxx:703
virtual void setFmtType(FormatType type)
default implementation.
bool readDouble(PWP_REAL &v, PWP_UINT32 maxDigits=0)
Reads a single PWP_REAL value.
Definition: PwpFile.cxx:1006
bool needByteSwap() const
Determine if byte swapping is needed for this file.
Definition: PwpFile.h:654
float PWP_FLOAT
32-bit real
Definition: apiPWP.h:215
Cross Platform Functions.
PwpFile(FILE *fp=0, std::string filename=std::string(), int mode=0)
Default constructor.
Definition: PwpFile.cxx:564
PWP_BOOL PwuUnfRecWriteUINT(PWU_UNFDATA *pUData, PWP_UINT val)
Write a PWP_UINT value to the current record with endian order applied.
virtual bool endRecord()
NOP default implementation.
Definition: PwpFile.cxx:417
const char * getName() const
Get the file&#39;s associated filename.
Definition: PwpFile.cxx:794
virtual FormatType getFmtType() const
Definition: PwpFile.cxx:1240
virtual bool endRecord()
Ends an unformatted record.
Definition: PwpFile.cxx:1092
unsigned short PWP_UINT16
16-bit unsigned integer
Definition: apiPWP.h:182
bool readAscVal(PWP_REAL *v, PWP_UINT32 cnt, const PWP_UINT32 base=10)
Reads an array of cnt PWP_REAL values from an ascii file.
Definition: PwpFile.cxx:902
virtual void setFmtFieldDouble(const int width, const int prec)
Definition: PwpFile.cxx:1410
PwpFile & file_
Definition: PwpFile.h:845
virtual ~PwpAsciiWriter()
Definition: PwpFile.cxx:39
virtual bool write(PWP_REAL val, const char *suffix=0, const char *prefix=0)
Writes a floating point value with proper precision, encoding and byte order.
Definition: PwpFile.cxx:308
virtual void setFmtFieldSingle(const int width, const int prec)
Definition: PwpFile.cxx:1396
bool readInt(PWP_UINT32 &v, const PWP_UINT32 base=10, PWP_UINT32 maxDigits=0)
Reads a single PWP_UINT32 value.
Definition: PwpFile.cxx:954
PWP_BOOL PwuUnfRecWriteREAL(PWU_UNFDATA *pUData, PWP_REAL val)
Write a PWP_REAL value to the current record with endian order applied.
Writes solver files.
Definition: PwpFile.h:111
PWP_BOOL PwuUnfRecWriteINT32(PWU_UNFDATA *pUData, PWP_INT32 val)
Write a PWP_INT32 value to the current record with endian order applied.
virtual bool write(PWP_INT val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:217
virtual bool write(PWP_INT16 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:68
PWP_BOOL PwuUnfRecWriteUINT32(PWU_UNFDATA *pUData, PWP_UINT32 val)
Write a PWP_UINT32 value to the current record with endian order applied.
short PWP_INT16
16-bit integer
Definition: apiPWP.h:179
PWP_BOOL PwuUnfRecEnd(PWU_UNFDATA *pUData)
Finalize the current record write.
bool readAlphaToken(std::string &tok)
Reads a whitespace delimited token (word).
Definition: PwpFile.cxx:849
virtual bool write(PWP_INT64 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:225
virtual FormatType getFmtType() const
default implementation.
virtual bool write(PWP_UINT64 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:265
virtual bool write(PWP_UINT16 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:486
virtual ~PwpFile()
Destructor.
Definition: PwpFile.cxx:590
bool isAscii() const
Determines if file was opened with either the pwpAscii or pwpFormatted mode flag. ...
Definition: PwpFile.cxx:710
int pwpFileFlush(FILE *fp)
Flush a file to disk.
virtual bool write(const char *val, PWP_INT size=-1, char pad=0)
Writes a string value.
Definition: PwpFile.cxx:319
PWU_UNFDATA & unfData()
Get the file&#39;s unformatted data buffer.
Definition: PwpFile.h:640
signed char PWP_INT8
8-bit integer
Definition: apiPWP.h:167
virtual bool write(PWP_INT32 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:438
virtual bool write(PWP_UINT8 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:116
long long PWP_INT64
64-bit integer
Definition: apiPWP.h:203
int pwpFileGetpos(FILE *fp, sysFILEPOS *pos)
Query the current file position.
bool getPos(sysFILEPOS &pos) const
Get the current file position.
Definition: PwpFile.cxx:745
virtual bool write(PWP_INT16 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:241
bool isOpen() const
Determines a file&#39;s status.
Definition: PwpFile.cxx:629
PWP_ENUM_PRECISION setPrecision(PWP_ENUM_PRECISION precision)
Set the floating point precision used for writes.
Definition: PwpFile.cxx:666
virtual bool write(PWP_INT8 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:454
PWP_BOOL PwuUnfRecWriteINT16(PWU_UNFDATA *pUData, PWP_INT16 val)
Write a PWP_INT16 value to the current record with endian order applied.
virtual bool write(PWP_UINT32 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:478
virtual bool write(const char *val, PWP_INT size=-1, char=0)
Writes a string value.
Definition: PwpFile.cxx:146
virtual ~PwpBinaryWriter()
Definition: PwpFile.cxx:212
int fmtFieldWdDouble_
Double precision format field width.
bool isSingle() const
Determines if floating point precision is PWP_PRECISION_SINGLE.
Definition: PwpFile.cxx:696
long PWP_INT
integer same size as void*
Definition: apiPWP.h:155
virtual void setFmtType(FormatType type)
Definition: PwpFile.cxx:1425
int fmtFieldWdSingle_
Single precision format field width.
size_t pwpFileWrite(const void *buf, size_t size, size_t count, FILE *fp)
Write an collection of data items to a file.
virtual bool write(PWP_INT val, const char *suffix=0, const char *prefix=0)=0
Writes a integer value with proper encoding and byte order.
FILE * fp() const
Get the FILE pointer.
Definition: PwpFile.h:628
bool wspaceSkip()
Reads and discards consecutive whitespace bytes.
Definition: PwpFile.cxx:808
virtual bool beginRecord()
NOP default implementation.
Definition: PwpFile.cxx:403
bool isBinary() const
Determines if file was opened with pwpBinary mode flag.
Definition: PwpFile.cxx:717
bool getcNotEOF(int &c)
Reads a single byte value.
Definition: PwpFile.h:529
virtual bool write(PWP_FLOAT val, const char *suffix=0, const char *prefix=0)
Writes a floating point value with proper precision, encoding and byte order.
Definition: PwpFile.cxx:124
PwpFileWriter * writer_
The file writer implementation.
Definition: PwpFile.h:721
void pwpFileRewind(FILE *fp)
Reset position to the beginning of the file.
std::string filename_
The file name.
Definition: PwpFile.h:717
virtual bool write(PWP_FLOAT val, const char *suffix=0, const char *prefix=0)
Writes a floating point value with proper precision, encoding and byte order.
Definition: PwpFile.cxx:297
FormatType fmtType_
Formatting flags.
int pwpFileDelete(const char *filename)
Delete a file.
virtual bool beginRecord(PWP_UINT32 bytes, PWP_UINT32 count=1)
NOP default implementation.
Definition: PwpFile.cxx:410
virtual bool endRecord()
NOP default implementation.
int fmtPrecSingle_
Single precision format decimals.
PwpBinaryWriter(PwpFile &file)
Definition: PwpFile.cxx:206
PWP_BOOL PwuUnfRecBegin(PWU_UNFDATA *pUData)
Prepares a PWU_UNFDATA block for writing a new unformatted data record.
PWP_BOOL PwuUnfRecWriteUINT64(PWU_UNFDATA *pUData, PWP_UINT64 val)
Write a PWP_UINT64 value to the current record with endian order applied.
virtual void setFmtFieldSingle(const int width, const int prec)
Definition: PwpFile.cxx:1194
virtual bool write(PWP_INT64 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:430
virtual bool write(PWP_INT8 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:76
bool flush()
Flush file to disk.
Definition: PwpFile.cxx:738
PWP_BOOL PwuUnfRecWriteFLOAT(PWU_UNFDATA *pUData, PWP_FLOAT val)
Write a PWP_FLOAT value to the current record with endian order applied.
PWP_ENDIANNESS byteOrder_
The file&#39;s byte order.
Definition: PwpFile.h:718
PWP_ENDIANNESS
Flags used to indicate endianness or control endian behaviors in functions.
Definition: apiPWP.h:738
virtual void setFmtFieldSingle(const int width, const int prec)
default implementation.
virtual bool write(PWP_UINT16 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:281
virtual bool write(PWP_INT32 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:233
int pwpFilenameGetSize(const char *filename, size_t *size)
Get the file&#39;s size in bytes.
void setName(std::string filename)
Set the file&#39;s associated filename.
Definition: PwpFile.cxx:787
virtual bool write(PWP_INT8 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:249
bool ungetc(const int c)
Return a byte value to the file.
Definition: PwpFile.h:538
int mode_
The mode.
Definition: PwpFile.h:716
PwpFileRecord(PwpFile &file, bool doBeginRecord=true)
Constructor.
Definition: PwpFile.cxx:1257
bool close()
Explicitly close the file object.
Definition: PwpFile.cxx:636
virtual bool write(PWP_FLOAT val, const char *suffix=0, const char *prefix=0)
Writes a floating point value with proper precision, encoding and byte order.
Definition: PwpFile.cxx:502
#define PWP_UINT32_MAX
maximum valid PWP_UINT32 value
Definition: apiPWP.h:197
virtual bool write(PWP_UINT32 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:100
virtual ~PwpUnformattedWriter()
Definition: PwpFile.cxx:397
bool getSize(PWP_UINT64 &size) const
Get the size of the file managed by this object.
Definition: PwpFile.cxx:767
PWP_ENDIANNESS PwuGetOsEndianness(void)
Query the OS&#39;s native endianness.
PWP_BOOL PwuUnfRecWriteUINT8(PWU_UNFDATA *pUData, PWP_UINT8 val)
Write a PWP_UINT8 value to the current record with endian order applied.
virtual bool write(PWP_REAL val, const char *suffix=0, const char *prefix=0)
Writes a floating point value with proper precision, encoding and byte order.
Definition: PwpFile.cxx:513
PwpUnformattedWriter(PwpFile &file)
Definition: PwpFile.cxx:390
virtual bool write(PWP_INT val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:44
virtual bool endRecord()
Ends an unformatted record.
Definition: PwpFile.cxx:1294
virtual bool write(PWP_UINT8 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
Definition: PwpFile.cxx:494
PWP_BOOL PwuUnfRecWriteINT8(PWU_UNFDATA *pUData, PWP_INT8 val)
Write a PWP_INT8 value to the current record with endian order applied.
PWP_ENUM_PRECISION getPrecision() const
Get the floating point precision used for writes.
Definition: PwpFile.cxx:675
double PWP_REAL
64-bit real
Definition: apiPWP.h:218
bool open(std::string filename, int mode)
Opens a file with the given filename and mode.
Definition: PwpFile.cxx:622
static PWP_ENDIANNESS mapToBigLittle(PWP_ENDIANNESS byteOrder)
Map a byte ordering value to PWP_ENDIAN_BIG or PWP_ENDIAN_LITTLE based on getOsByteOrder().
Definition: PwpFile.cxx:1050
PWP_BOOL PwuUnfRecWriteINT64(PWU_UNFDATA *pUData, PWP_INT64 val)
Write a PWP_INT64 value to the current record with endian order applied.
int pwpFileGetSize(FILE *fp, size_t *size)
Get the file&#39;s size in bytes.
int PWP_INT32
32-bit integer
Definition: apiPWP.h:191
virtual void getFmtFieldDouble(int &width, int &prec) const
Definition: PwpFile.cxx:1417
virtual void getFmtFieldDouble(int &width, int &prec) const
default implementation.