Pointwise Plugin SDK
Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members

Writes solver files. More...

#include <PwpFile.h>

+ Inheritance diagram for PwpFile:
+ Collaboration diagram for PwpFile:

Public Member Functions

virtual bool beginRecord ()
 Starts an unformatted record. More...
 
virtual bool beginRecord (PWP_UINT32 bytes, PWP_UINT32 count=1)
 Starts a fixed size unformatted record. More...
 
bool checkAscii () const
 Determins whether the file is Ascii by reading the contents of the file. More...
 
bool checkUnformatted (bool &swapped, std::vector< PWP_INT64 > *pRecSizes=0) const
 Determins unformatted type settings by reading the contents of the file. More...
 
bool close ()
 Explicitly close the file object. More...
 
virtual bool endRecord ()
 Ends an unformatted record. More...
 
bool fileEof () const
 Check for the end of file. More...
 
bool flush ()
 Flush file to disk. More...
 
FILE * fp () const
 Get the FILE pointer. More...
 
PWP_ENDIANNESS getByteOrder (bool mapBigLittle=false) const
 Get the byte order used for writes. More...
 
int getc ()
 Reads a single byte value. More...
 
bool getcNotEOF (int &c)
 Reads a single byte value. More...
 
virtual void getFmtFieldDouble (int &width, int &prec) const
 
virtual void getFmtFieldSingle (int &width, int &prec) const
 
virtual FormatType getFmtType () const
 
const char * getName () const
 Get the file's associated filename. More...
 
bool getPos (sysFILEPOS &pos) const
 Get the current file position. More...
 
PWP_INT64 getPos () const
 Get the current file position. More...
 
PWP_ENUM_PRECISION getPrecision () const
 Get the floating point precision used for writes. More...
 
bool getSize (PWP_UINT64 &size) const
 Get the size of the file managed by this object. More...
 
bool isAscii () const
 Determines if file was opened with either the pwpAscii or pwpFormatted mode flag. More...
 
bool isBinary () const
 Determines if file was opened with pwpBinary mode flag. More...
 
bool isDouble () const
 Determines if floating point precision is PWP_PRECISION_DOUBLE. More...
 
bool isEof () const
 Get the end-of-file status. More...
 
bool isOpen () const
 Determines a file's status. More...
 
bool isReadable () const
 Determines if file suports read operations. More...
 
bool isSingle () const
 Determines if floating point precision is PWP_PRECISION_SINGLE. More...
 
bool isUnformatted () const
 Determines if file was opened with pwpUnformatted mode flag. More...
 
bool isWritable () const
 Determines if file suports write operations. More...
 
bool needByteSwap () const
 Determine if byte swapping is needed for this file. More...
 
bool open (std::string filename, int mode)
 Opens a file with the given filename and mode. More...
 
 operator FILE * () const
 Get the FILE pointer. More...
 
PwpFileoperator= (const PwpFile &ref)
 Asssignment operator Does not copy the file position or unformatted data. More...
 
 PwpFile (FILE *fp=0, std::string filename=std::string(), int mode=0)
 Default constructor. More...
 
 PwpFile (std::string filename, int mode)
 File open constructor. More...
 
 PwpFile (const PwpFile &ref)
 Copy constructor Does not copy the file position or unformatted data. More...
 
bool read (void *buf, size_t size, size_t count)
 Read a collection of data items. More...
 
bool readAlphaToken (std::string &tok)
 Reads a whitespace delimited token (word). More...
 
bool readAlphaTokenIs (const char *tok)
 Read and compare an alpha token. More...
 
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. More...
 
bool readAscVal (PWP_FLOAT *v, PWP_UINT32 cnt, const PWP_UINT32 base=10)
 Reads an array of cnt PWP_FLOAT values from an ascii file. More...
 
bool readAscVal (PWP_UINT32 *v, PWP_UINT32 cnt, const PWP_UINT32 base=10)
 Reads an array of cnt PWP_UINT32 values from an ascii file. More...
 
bool readAscVal (char *v, PWP_UINT32 cnt, const PWP_UINT32 base=10)
 Reads an array of cnt characters from an ascii file. More...
 
bool readDouble (PWP_REAL &v, PWP_UINT32 maxDigits=0)
 Reads a single PWP_REAL value. More...
 
bool readHex (PWP_UINT32 &v, PWP_UINT32 maxDigits=0)
 Reads a single PWP_UINT32 hex value. More...
 
bool readInt (PWP_UINT32 &v, const PWP_UINT32 base=10, PWP_UINT32 maxDigits=0)
 Reads a single PWP_UINT32 value. More...
 
bool readOctal (PWP_UINT32 &v, PWP_UINT32 maxDigits=0)
 Reads a single PWP_UINT32 octal value. More...
 
bool readOptionalInt (PWP_UINT32 &v, const PWP_UINT32 defV, const PWP_UINT32 base=10, PWP_UINT32 maxDigits=0)
 Reads a single PWP_UINT32 value. More...
 
template<typename T >
bool readSwap (T &val, const bool swapbyte)
 Reads a single value of type T. More...
 
template<typename T >
readSwap (const bool swapbyte)
 Reads a single value of type T. More...
 
bool readToken (std::string &tok)
 Reads a whitespace delimited token (word). More...
 
bool readTokenIs (const char *tok)
 Read and compare a token. More...
 
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. More...
 
bool readUntil (PWP_UINT32 &v, const char stopC)
 Reads a stopC terminated PWP_UINT32 value. More...
 
bool readUntilTrim (std::string &str, const int stopC, int maxLen=0)
 Reads up to maxLen chars until the specified stop char is encountered. More...
 
template<typename T >
bool readVal (T &v, const PWP_UINT32 base=10)
 Reads a single value of type T. More...
 
template<typename T >
bool readVal (T *v, const PWP_UINT32 cnt, const PWP_UINT32 base=10)
 Reads an array of cnt values of type T. More...
 
bool rewind ()
 Reset position to the beginning of the file. More...
 
PWP_ENDIANNESS setByteOrder (PWP_ENDIANNESS order)
 Set the byte order used for writes. More...
 
virtual void setFmtFieldDouble (const int width, const int prec)
 
virtual void setFmtFieldSingle (const int width, const int prec)
 
virtual void setFmtType (FormatType type)
 
bool setIntPos (const PWP_INT64 &pos)
 Set the current file position. More...
 
void setName (std::string filename)
 Set the file's associated filename. More...
 
bool setPos (const sysFILEPOS &pos)
 Set the current file position. More...
 
PWP_ENUM_PRECISION setPrecision (PWP_ENUM_PRECISION precision)
 Set the floating point precision used for writes. More...
 
bool skipToChar (const int nextC)
 Skip all chars up to and including nextC. More...
 
PWU_UNFDATAunfData ()
 Get the file's unformatted data buffer. More...
 
const PWU_UNFDATAunfData () const
 Get the file's unformatted data buffer. More...
 
bool ungetc (const int c)
 Return a byte value to the file. More...
 
bool wrap (FILE *fp, std::string filename=std::string(), int mode=0)
 Take ownership of fp opened using pwpFileOpen(filename, mode). More...
 
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. More...
 
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. More...
 
virtual bool write (PWP_UINT16 val, const char *suffix=0, const char *prefix=0)
 Writes a integer value with proper encoding and byte order. More...
 
virtual bool write (PWP_INT64 val, const char *suffix=0, const char *prefix=0)
 Writes a integer value with proper encoding and byte order. More...
 
virtual bool write (const char *val, PWP_INT size=-1, char pad=0)
 Writes a string value. More...
 
virtual bool write (PWP_UINT8 val, const char *suffix=0, const char *prefix=0)
 Writes a integer value with proper encoding and byte order. More...
 
virtual bool write (PWP_INT8 val, const char *suffix=0, const char *prefix=0)
 Writes a integer value with proper encoding and byte order. More...
 
virtual bool write (PWP_UINT64 val, const char *suffix=0, const char *prefix=0)
 Writes a integer value with proper encoding and byte order. More...
 
virtual bool write (PWP_INT32 val, const char *suffix=0, const char *prefix=0)
 Writes a integer value with proper encoding and byte order. More...
 
virtual bool write (PWP_UINT32 val, const char *suffix=0, const char *prefix=0)
 Writes a integer value with proper encoding and byte order. More...
 
virtual bool write (PWP_INT16 val, const char *suffix=0, const char *prefix=0)
 Writes a integer value with proper encoding and byte order. More...
 
template<typename T >
bool writeAt (sysFILEPOS pos, const T &val, const char *suffix=0, const char *prefix=0)
 Writes an endian enforced value directly at a given file position. More...
 
bool wspaceSkip ()
 Reads and discards consecutive whitespace bytes. More...
 
bool wspaceSkipToChar (const int nextC)
 Skip whitespace and read the next char. More...
 
bool wspaceSkipToEOF ()
 Skip whitespace and read until EOF. More...
 
bool wspaceSkipToOneOf (const char *stopCs, char &theC)
 Skip whitespace and read the next char returning it in theC. More...
 
virtual ~PwpFile ()
 Destructor. More...
 
- Public Member Functions inherited from PwpWriterInterface
bool writef (PWP_INT size, char pad, const char *fmt,...)
 Writes a formatted string value. More...
 
bool writef (const char *fmt,...)
 Writes a formatted string value. More...
 
virtual ~PwpWriterInterface ()
 Destructor. More...
 

Static Public Member Functions

static PWP_ENDIANNESS getOsByteOrder ()
 Get the OS's native byte ordering. More...
 
static bool getSize (const char *filename, PWP_UINT64 &size)
 Get the file size for the given filename. More...
 
static std::string & ltrim (std::string &s)
 trim leading whitespace from s More...
 
static PWP_ENDIANNESS mapToBigLittle (PWP_ENDIANNESS byteOrder)
 Map a byte ordering value to PWP_ENDIAN_BIG or PWP_ENDIAN_LITTLE based on getOsByteOrder(). More...
 
static bool needByteSwap (PWP_ENDIANNESS byteOrder)
 Determine if byte swapping is needed for a given byte order. More...
 
static std::string & rtrim (std::string &s)
 trim trailing whitespace from s More...
 
template<typename T >
static void swap (T &val)
 swap() - (Importer-only function) Wrapper for function swapByteOrder(). More...
 
static const void * swapByteOrder (void *buf, size_t size)
 Performs an inplace byte swapping. More...
 
static std::string & trim (std::string &s)
 trim leading and trailing whitespace from s More...
 
static bool unlink (const char *filename)
 Delete a file. More...
 

Private Types

enum  { DefReserve = 128 }
 

Private Attributes

PWP_ENDIANNESS byteOrder_
 The file's byte order. More...
 
std::string filename_
 The file name. More...
 
FILE * fp_
 The FILE pointer. More...
 
int mode_
 The mode. More...
 
PWP_ENUM_PRECISION precision_
 The file's floating point precision. More...
 
PWU_UNFDATA ud_
 The file's unformatted data stats. More...
 
PwpFileWriterwriter_
 The file writer implementation. More...
 

Additional Inherited Members

- Public Types inherited from PwpWriterInterface
enum  FormatType {
  FormatG = G_,
  FormatWdPrecG = G_ | Wd_ | Prec_,
  FormatWdG = G_ | Wd_,
  FormatPrecG = G_ | Prec_,
  FormatF = F_,
  FormatWdPrecF = F_ | Wd_ | Prec_,
  FormatWdF = F_ | Wd_,
  FormatPrecF = F_ | Prec_,
  FormatE = E_,
  FormatWdPrecE = E_ | Wd_ | Prec_,
  FormatWdE = E_ | Wd_,
  FormatPrecE = E_ | Prec_
}
 Formatted output types for floating point values. More...
 
- Protected Types inherited from PwpWriterInterface
enum  {
  G_ = 0x00,
  F_ = 0x01,
  E_ = 0x02,
  GFEMask_ = 0x0F,
  Wd_ = 0x10,
  Prec_ = 0x20,
  WdPrec_ = Wd_ | Prec_,
  WPMask_ = 0xF0
}
 Bit flags use to build public FormatX enums. More...
 

Detailed Description

Writes solver files.

The PwpFile class is especially useful when a solver supports files of various encodings, precisions and byte orders.

Sample Usage:
#include "PwpFile.h"
static void
writeTestFile(const char *basename, int mode, PWP_ENDIANNESS order,
{
PWP_INT iVal = -255;
PWP_INT8 i8Val = -8;
PWP_INT16 i16Val = -16;
PWP_INT32 i32Val = -32;
PWP_UINT uVal = 255;
PWP_UINT8 u8Val = 8;
PWP_UINT16 u16Val = 16;
PWP_UINT32 u32Val = 32;
PWP_FLOAT fVal = (PWP_FLOAT)1.23456789;
PWP_REAL dVal = 1.234567890123456789;
char filename[512];
bool canSwap = true;
if (mode & pwpBinary) {
sprintf(filename, "%s.bin", basename);
}
else if (mode & pwpAscii || mode & pwpFormatted) {
sprintf(filename, "%s.asc", basename);
canSwap = false;
}
else if (mode & pwpUnformatted) {
sprintf(filename, "%s.unf", basename);
}
if (PWP_PRECISION_SINGLE == prec) {
strcat(filename, "-sgl");
}
else if (PWP_PRECISION_DOUBLE == prec) {
strcat(filename, "-dbl");
}
if (canSwap) {
strcat(filename, "-big");
}
else {
strcat(filename, "-lit");
}
}
PwpFile file(filename, pwpWrite | mode);
if (file.isOpen()) {
file.setByteOrder(order);
file.setPrecision(prec);
PwpFileRecord rec(file); // ctor calls beginRecord()
rec.write(iVal, "\n");
rec.write(i8Val, "\n");
rec.write(i16Val, "\n");
rec.write(i32Val, "\n");
rec.beginRecord(); // calls endRecord()
rec.write(uVal, "\n");
rec.write(u8Val, "\n");
rec.write(u16Val, "\n");
rec.write(u32Val, "\n");
rec.beginRecord(); // calls endRecord()
rec.write(fVal, "\n");
rec.write(dVal, "\n");
rec.beginRecord(); // calls endRecord()
rec.write("hello\n");
rec.write("hello", 10);
// rec.endRecord() called in dtor
}
// file.close() called in dtor
}

Definition at line 110 of file PwpFile.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
DefReserve 

Definition at line 111 of file PwpFile.h.

Constructor & Destructor Documentation

◆ PwpFile() [1/3]

PwpFile::PwpFile ( FILE *  fp = 0,
std::string  filename = std::string(),
int  mode = 0 
)

Default constructor.

Constructs a file object.

If provided, the file object will take ownership of a fp opened using pwpFileOpen(filename, mode). fp will be closed in this object's destructor.

Parameters
fpA FILE pointer returned from pwpFileOpen().
filenameThe filename passed to pwpFileOpen().
modeThe mode passed to pwpFileOpen().
See also
sysFILEMODE, pwpFileOpen()

Definition at line 515 of file PwpFile.cxx.

References fp(), and wrap().

◆ PwpFile() [2/3]

PwpFile::PwpFile ( std::string  filename,
int  mode 
)

File open constructor.

Constructs and opens a file object for the given filename and mode.

Parameters
filenameThe filename to open.
modeControls how the file is opened. This value is built from the bitwise OR of 2 sysFILEMODE flags.
See also
sysFILEMODE, pwpFileOpen()

Definition at line 528 of file PwpFile.cxx.

References open().

◆ PwpFile() [3/3]

PwpFile::PwpFile ( const PwpFile ref)

Copy constructor Does not copy the file position or unformatted data.

Definition at line 540 of file PwpFile.cxx.

References filename_, mode_, and open().

◆ ~PwpFile()

PwpFile::~PwpFile ( )
virtual

Destructor.

If needed, file will be closed.

Definition at line 552 of file PwpFile.cxx.

References close().

Member Function Documentation

◆ beginRecord() [1/2]

bool PwpFile::beginRecord ( )
virtual

Starts an unformatted record.

Starts an unformatted record. If a record is already active, it will be closed.

Returns
true on success.
Note
Records are ignored by all modes except pwpUnformatted.

Implements PwpWriterInterface.

Definition at line 1215 of file PwpFile.cxx.

References PwpFileWriter::beginRecord(), and writer_.

Referenced by PwpFileRecord::beginRecord().

◆ beginRecord() [2/2]

bool PwpFile::beginRecord ( PWP_UINT32  bytes,
PWP_UINT32  count = 1 
)
virtual

Starts a fixed size unformatted record.

Starts a fixed size unformatted record. If a record is already active, it will be closed.

Fixed size record I/O is significantly faster than variable sized records. Fixed size records should be used, if possible, when there are large numbers (> ~1e6) of records written to an export file.

The call to endRecord() will fail if the number of bytes written to the record is not equal to (bytes * count).

Returns
true on success.
Note
Records are ignored by all modes except pwpUnformatted.

Implements PwpWriterInterface.

Definition at line 1221 of file PwpFile.cxx.

References PwpFileWriter::beginRecord(), and writer_.

◆ checkAscii()

bool PwpFile::checkAscii ( ) const

Determins whether the file is Ascii by reading the contents of the file.

Uses the same method as used in GgFile::isAscii()

Returns
true if the file is Ascii

Definition at line 693 of file PwpFile.cxx.

References filename_, fp_, getSize(), pwpFileRead(), and setIntPos().

◆ checkUnformatted()

bool PwpFile::checkUnformatted ( bool &  swapped,
std::vector< PWP_INT64 > *  pRecSizes = 0 
) const

Determins unformatted type settings by reading the contents of the file.

Uses the same method as used in GgFile::isUnformatted()

Returns
true if the file is actualy unformatted

Definition at line 777 of file PwpFile.cxx.

References getPos(), getSize(), parseUnformattedRecord(), setPos(), and swap().

◆ close()

bool PwpFile::close ( )

Explicitly close the file object.

File will automatically be closed in the destructor.

Returns
true on success.

Definition at line 613 of file PwpFile.cxx.

References filename_, fp_, mode_, pwpFileClose(), and writer_.

Referenced by wrap(), and ~PwpFile().

◆ endRecord()

bool PwpFile::endRecord ( )
virtual

Ends an unformatted record.

Ends an active record for files opened with pwpUnformatted mode.

Returns
true on success.
Note
Records are ignored by all modes except pwpUnformatted.

Implements PwpWriterInterface.

Definition at line 1227 of file PwpFile.cxx.

References PwpFileWriter::endRecord(), and writer_.

Referenced by PwpFileRecord::endRecord().

◆ fileEof()

bool PwpFile::fileEof ( ) const

Check for the end of file.

Returns
true if it is not the end of file

Definition at line 606 of file PwpFile.cxx.

References fp_.

◆ flush()

bool PwpFile::flush ( )

Flush file to disk.

Returns
true on success.

Definition at line 842 of file PwpFile.cxx.

References fp_, and pwpFileFlush().

◆ fp()

FILE* PwpFile::fp ( ) const
inline

◆ getByteOrder()

PWP_ENDIANNESS PwpFile::getByteOrder ( bool  mapBigLittle = false) const

Get the byte order used for writes.

Parameters
mapBigLittleIf true, PWP_ENDIAN_FOREIGN or PWP_ENDIAN_NATIVE byte orders will be mapped to PWP_ENDIAN_BIG or PWP_ENDIAN_LITTLE based on getOsByteOrder().
Returns
The byte order.
Note
The byte order is mapped as:
  • PWP_ENDIAN_FOREIGN Opposite of getOsByteOrder()
  • PWP_ENDIAN_NATIVE Same as getOsByteOrder()
  • PWP_ENDIAN_BIG Always big endian
  • PWP_ENDIAN_LITTLE Always little endian

Definition at line 636 of file PwpFile.cxx.

References byteOrder_, and mapToBigLittle().

Referenced by PwpUnformattedWriter::beginRecord(), writeAt(), and PwpAnchoredFileValueWriter< ValType >::writeUnf().

◆ getc()

int PwpFile::getc ( )
inline

Reads a single byte value.

Returns
The byte value (0-255) or EOF as an int.

Definition at line 635 of file PwpFile.h.

References fp_.

◆ getcNotEOF()

bool PwpFile::getcNotEOF ( int &  c)
inline

Reads a single byte value.

Parameters
cThe byte value read or EOF.
Returns
true if c != EOF.

Definition at line 644 of file PwpFile.h.

References fp_.

Referenced by skipToChar(), and wspaceSkip().

◆ getFmtFieldDouble()

void PwpFile::getFmtFieldDouble ( int &  width,
int &  prec 
) const
virtual

Implements PwpWriterInterface.

Definition at line 1330 of file PwpFile.cxx.

References PwpFileWriter::getFmtFieldDouble(), and writer_.

Referenced by PwpFileRecord::getFmtFieldDouble().

◆ getFmtFieldSingle()

void PwpFile::getFmtFieldSingle ( int &  width,
int &  prec 
) const
virtual

Implements PwpWriterInterface.

Definition at line 1312 of file PwpFile.cxx.

References PwpFileWriter::getFmtFieldSingle(), and writer_.

Referenced by PwpFileRecord::getFmtFieldSingle().

◆ getFmtType()

PwpWriterInterface::FormatType PwpFile::getFmtType ( ) const
virtual

Implements PwpWriterInterface.

Definition at line 1349 of file PwpFile.cxx.

References PwpWriterInterface::FormatG, PwpFileWriter::getFmtType(), and writer_.

Referenced by PwpFileRecord::getFmtType().

◆ getName()

const char * PwpFile::getName ( ) const

Get the file's associated filename.

Returns
const pointer to filename.

Definition at line 922 of file PwpFile.cxx.

References filename_.

◆ getOsByteOrder()

PWP_ENDIANNESS PwpFile::getOsByteOrder ( )
static

Get the OS's native byte ordering.

Returns
The native byte ordering.

Definition at line 1178 of file PwpFile.cxx.

References PwuGetOsEndianness().

Referenced by mapToBigLittle(), and needByteSwap().

◆ getPos() [1/2]

bool PwpFile::getPos ( sysFILEPOS pos) const

Get the current file position.

Note
File position handling is only guaranteed to work for files opened as pwpBinary. Platform end-of-line differences may break getPos() and setPos() if the file is opened as pwpAscii.
Returns
true on success.

Definition at line 849 of file PwpFile.cxx.

References fp_, and pwpFileGetpos().

Referenced by PwpAnchoredFileValue< ValType, ValWriter >::anchor(), checkUnformatted(), PwpAnchoredFileValue< ValType, ValWriter >::commit(), PwpFileRecord::getPos(), and parseUnformattedRecord().

◆ getPos() [2/2]

PWP_INT64 PwpFile::getPos ( ) const

Get the current file position.

Note
File position handling is only guaranteed to work for files opened as pwpBinary. Platform end-of-line differences may break getPos() and setPos() if the file is opened as pwpAscii.
Returns
the current file position

Definition at line 855 of file PwpFile.cxx.

References fp_, and pwpFileGetpos().

Referenced by writeAt().

◆ getPrecision()

PWP_ENUM_PRECISION PwpFile::getPrecision ( ) const

Get the floating point precision used for writes.

Returns
The precision.

Definition at line 652 of file PwpFile.cxx.

References precision_.

◆ getSize() [1/2]

bool PwpFile::getSize ( PWP_UINT64 size) const

Get the size of the file managed by this object.

Returns
true on success.

Definition at line 895 of file PwpFile.cxx.

References fp_, and pwpFileGetSize().

Referenced by checkAscii(), checkUnformatted(), and parseUnformattedRecord().

◆ getSize() [2/2]

bool PwpFile::getSize ( const char *  filename,
PWP_UINT64 size 
)
static

Get the file size for the given filename.

Returns
true on success.

Definition at line 905 of file PwpFile.cxx.

References pwpFilenameGetSize().

◆ isAscii()

bool PwpFile::isAscii ( ) const

Determines if file was opened with either the pwpAscii or pwpFormatted mode flag.

Returns
true if file opened with pwpAscii or pwpFormatted mode flag.

Definition at line 687 of file PwpFile.cxx.

References mode_, pwpAscii, and pwpFormatted.

Referenced by wrap(), and PwpAnchoredFileValue< ValType, ValWriter >::write().

◆ isBinary()

bool PwpFile::isBinary ( ) const

Determines if file was opened with pwpBinary mode flag.

Returns
true if file was opened with pwpBinary mode flag.

Definition at line 821 of file PwpFile.cxx.

References mode_, and pwpBinary.

Referenced by readVal(), wrap(), and PwpAnchoredFileValue< ValType, ValWriter >::write().

◆ isDouble()

bool PwpFile::isDouble ( ) const

Determines if floating point precision is PWP_PRECISION_DOUBLE.

Returns
true if precision is PWP_PRECISION_DOUBLE.

Definition at line 680 of file PwpFile.cxx.

References precision_, and PWP_PRECISION_DOUBLE.

Referenced by PwpAsciiWriter::write(), PwpBinaryWriter::write(), and PwpUnformattedWriter::write().

◆ isEof()

bool PwpFile::isEof ( ) const

Get the end-of-file status.

Returns
true if at end-of-file.

Definition at line 835 of file PwpFile.cxx.

References fp_, and pwpFileEof().

◆ isOpen()

bool PwpFile::isOpen ( ) const

Determines a file's status.

Returns
true if the file is open.

Definition at line 600 of file PwpFile.cxx.

References fp_.

Referenced by PwpFileRecord::~PwpFileRecord().

◆ isReadable()

bool PwpFile::isReadable ( ) const

Determines if file suports read operations.

Returns
true if file is readable.

Definition at line 659 of file PwpFile.cxx.

References mode_, and pwpRead.

◆ isSingle()

bool PwpFile::isSingle ( ) const

Determines if floating point precision is PWP_PRECISION_SINGLE.

Returns
true if precision is PWP_PRECISION_SINGLE.

Definition at line 673 of file PwpFile.cxx.

References precision_, and PWP_PRECISION_SINGLE.

Referenced by PwpAsciiWriter::write(), PwpBinaryWriter::write(), and PwpUnformattedWriter::write().

◆ isUnformatted()

bool PwpFile::isUnformatted ( ) const

Determines if file was opened with pwpUnformatted mode flag.

Returns
true if file was opened with pwpUnformatted mode flag.

Definition at line 828 of file PwpFile.cxx.

References mode_, and pwpUnformatted.

Referenced by wrap(), PwpAnchoredFileValue< ValType, ValWriter >::write(), and writeAt().

◆ isWritable()

bool PwpFile::isWritable ( ) const

Determines if file suports write operations.

Returns
true if file is readable.

Definition at line 666 of file PwpFile.cxx.

References mode_, and pwpWrite.

◆ ltrim()

static std::string& PwpFile::ltrim ( std::string &  s)
inlinestatic

trim leading whitespace from s

Definition at line 732 of file PwpFile.h.

Referenced by trim().

◆ mapToBigLittle()

PWP_ENDIANNESS PwpFile::mapToBigLittle ( PWP_ENDIANNESS  byteOrder)
static

Map a byte ordering value to PWP_ENDIAN_BIG or PWP_ENDIAN_LITTLE based on getOsByteOrder().

Parameters
byteOrderThe byte order value to map.
Returns
The mapped byte order.
Note
The byte order is mapped as:
  • PWP_ENDIAN_FOREIGN Opposite of getOsByteOrder()
  • PWP_ENDIAN_NATIVE Same as getOsByteOrder()
  • PWP_ENDIAN_BIG Always big endian
  • PWP_ENDIAN_LITTLE Always little endian

Definition at line 1185 of file PwpFile.cxx.

References getOsByteOrder(), PWP_ENDIAN_BIG, PWP_ENDIAN_ERROR, PWP_ENDIAN_FOREIGN, PWP_ENDIAN_LITTLE, and PWP_ENDIAN_NATIVE.

Referenced by CaePlugin< MT >::byteOrder(), getByteOrder(), and needByteSwap().

◆ needByteSwap() [1/2]

bool PwpFile::needByteSwap ( ) const
inline

Determine if byte swapping is needed for this file.

Returns
true if byte swapping is needed.

Definition at line 792 of file PwpFile.h.

References byteOrder_.

Referenced by PwpBinaryWriter::writeOrdered().

◆ needByteSwap() [2/2]

bool PwpFile::needByteSwap ( PWP_ENDIANNESS  byteOrder)
static

Determine if byte swapping is needed for a given byte order.

Parameters
byteOrderThe byte order value to check.
Returns
true if byte swapping is needed.

Definition at line 1208 of file PwpFile.cxx.

References getOsByteOrder(), and mapToBigLittle().

◆ open()

bool PwpFile::open ( std::string  filename,
int  mode 
)

Opens a file with the given filename and mode.

If needed, file will be closed before opening.

Parameters
filenameThe filename to open.
modeControls how the file is opened. This value is built from the bitwise OR of 2 sysFILEMODE flags.
Returns
true on success.
See also
sysFILEMODE, pwpFileOpen()

Definition at line 593 of file PwpFile.cxx.

References pwpFileOpen(), and wrap().

Referenced by operator=(), and PwpFile().

◆ operator FILE *()

PwpFile::operator FILE * ( ) const
inline

Get the FILE pointer.

Returns
The FILE pointer.

Definition at line 772 of file PwpFile.h.

References fp_.

◆ operator=()

PwpFile & PwpFile::operator= ( const PwpFile ref)

Asssignment operator Does not copy the file position or unformatted data.

Definition at line 558 of file PwpFile.cxx.

References byteOrder_, filename_, mode_, open(), and precision_.

◆ read()

bool PwpFile::read ( void *  buf,
size_t  size,
size_t  count 
)

Read a collection of data items.

Parameters
bufPointer to the read buffer.
sizeThe size of each item.
countThe number of items to read.
Returns
true on success.

Definition at line 929 of file PwpFile.cxx.

References fp_, and pwpFileRead().

Referenced by readSwap(), and readVal().

◆ readAlphaToken()

bool PwpFile::readAlphaToken ( std::string &  tok)

Reads a whitespace delimited token (word).

Only isalpha() chars are considered valid token chars. Any leading whitespace is skipped.

Parameters
tokReceives the token.
Returns
false if EOF encountered before a token was found.

Definition at line 977 of file PwpFile.cxx.

References DefReserve, fp_, ungetc(), and wspaceSkip().

Referenced by readAlphaTokenIs().

◆ readAlphaTokenIs()

bool PwpFile::readAlphaTokenIs ( const char *  tok)
inline

Read and compare an alpha token.

Parameters
tokThe expected token.
Returns
true if an alpha token was read and it is equal to tok.

Definition at line 662 of file PwpFile.h.

References readAlphaToken().

◆ readAscVal() [1/4]

bool PwpFile::readAscVal ( PWP_REAL v,
PWP_UINT32  cnt,
const PWP_UINT32  base = 10 
)

Reads an array of cnt PWP_REAL values from an ascii file.

Parameters
vPtr to the array being filled.
cntThe number of values to read.
baseIgnored for floating point values. It is included to make its call signature the same as the integer overloads.
Returns
true if all values were read and converted correctly.

Definition at line 1030 of file PwpFile.cxx.

Referenced by readVal().

◆ readAscVal() [2/4]

bool PwpFile::readAscVal ( PWP_FLOAT v,
PWP_UINT32  cnt,
const PWP_UINT32  base = 10 
)

Reads an array of cnt PWP_FLOAT values from an ascii file.

Parameters
vPtr to the array being filled.
cntThe number of values to read.
baseIgnored for floating point values. It is included to make its call signature the same as the integer overloads.
Returns
true if all values were read and converted correctly.

Definition at line 1043 of file PwpFile.cxx.

◆ readAscVal() [3/4]

bool PwpFile::readAscVal ( PWP_UINT32 v,
PWP_UINT32  cnt,
const PWP_UINT32  base = 10 
)

Reads an array of cnt PWP_UINT32 values from an ascii file.

Parameters
vPtr to the array being filled.
cntThe number of values to read.
baseThe numeric base to use when converting the ascii value. Defaults to 10.
Returns
true if all values were read and converted correctly.

Definition at line 1056 of file PwpFile.cxx.

◆ readAscVal() [4/4]

bool PwpFile::readAscVal ( char *  v,
PWP_UINT32  cnt,
const PWP_UINT32  base = 10 
)

Reads an array of cnt characters from an ascii file.

Parameters
vPtr to the array being filled.
cntThe number of values to read.
baseThe numeric base to use when converting the ascii value. Defaults to 10.
Returns
true if all values were read and converted correctly.

Definition at line 1069 of file PwpFile.cxx.

◆ readDouble()

bool PwpFile::readDouble ( PWP_REAL v,
PWP_UINT32  maxDigits = 0 
)

Reads a single PWP_REAL value.

Parameters
vThe value being read.
maxDigitsThe maximum number of digits to read. Ignored by non-ascii files.
Returns
true if value was read and converted correctly.

Definition at line 1141 of file PwpFile.cxx.

References DefReserve, fp_, PWP_UINT32_MAX, ungetc(), and wspaceSkip().

◆ readHex()

bool PwpFile::readHex ( PWP_UINT32 v,
PWP_UINT32  maxDigits = 0 
)
inline

Reads a single PWP_UINT32 hex value.

For non-ascii files, this is the same as calling readInt().

Parameters
vThe value being read.
maxDigitsThe maximum number of digits to read. Ignored by non-ascii files.
Returns
true if value was read and converted correctly.

Definition at line 627 of file PwpFile.h.

References readInt().

◆ readInt()

bool PwpFile::readInt ( PWP_UINT32 v,
const PWP_UINT32  base = 10,
PWP_UINT32  maxDigits = 0 
)

Reads a single PWP_UINT32 value.

If file is ascii, the data will be interpreted using the given numeric base.

Parameters
vThe value being read.
baseThe numeric base to use when converting the ascii value. Defaults to 10. Ignored by non-ascii files.
maxDigitsThe maximum number of digits to read. Ignored by non-ascii files.
Returns
true if value was read and converted correctly.

Definition at line 1081 of file PwpFile.cxx.

References DefReserve, fp_, PWP_UINT32_MAX, ungetc(), and wspaceSkip().

Referenced by readHex(), readOctal(), readOptionalInt(), and readUntil().

◆ readOctal()

bool PwpFile::readOctal ( PWP_UINT32 v,
PWP_UINT32  maxDigits = 0 
)
inline

Reads a single PWP_UINT32 octal value.

For non-ascii files, this is the same as calling readInt().

Parameters
vThe value being read.
maxDigitsThe maximum number of digits to read. Ignored by non-ascii files.
Returns
true if value was read and converted correctly.

Definition at line 615 of file PwpFile.h.

References readInt().

◆ readOptionalInt()

bool PwpFile::readOptionalInt ( PWP_UINT32 v,
const PWP_UINT32  defV,
const PWP_UINT32  base = 10,
PWP_UINT32  maxDigits = 0 
)

Reads a single PWP_UINT32 value.

If file is ascii, the data will be interpreted using the given numeric base.

Parameters
vThe value being read.
defVThe value stored in v if not read from file.
baseThe numeric base to use when converting the ascii value. Defaults to 10. Ignored by non-ascii files.
maxDigitsThe maximum number of digits to read. Ignored by non-ascii files.
Returns
true if value was read and converted correctly. false if v is set to defV.

Definition at line 1133 of file PwpFile.cxx.

References readInt().

◆ readSwap() [1/2]

template<typename T >
bool PwpFile::readSwap ( T &  val,
const bool  swapbyte 
)
inline

Reads a single value of type T.

If file is ascii and T supports bases, the data will be interpreted using the given numeric base.

Parameters
valThe value read.
swapbyteIf true, swap the val's bytes after reading from the file.
Returns
true if value was read and converted correctly.

Definition at line 502 of file PwpFile.h.

References read(), and swap().

Referenced by parseUnformattedRecord().

◆ readSwap() [2/2]

template<typename T >
T PwpFile::readSwap ( const bool  swapbyte)
inline

Reads a single value of type T.

If file is ascii and T supports bases, the data will be interpreted using the given numeric base.

Parameters
swapbyteBool flag to swap the bytes read
Returns
The value read.

Definition at line 518 of file PwpFile.h.

References fp_, and swap().

◆ readToken()

bool PwpFile::readToken ( std::string &  tok)

Reads a whitespace delimited token (word).

All non-whitespace chars are considered valid token chars. Any leading whitespace is skipped.

Parameters
tokReceives the token.
Returns
false if EOF encountered before a token was found.

Definition at line 953 of file PwpFile.cxx.

References DefReserve, fp_, ungetc(), and wspaceSkip().

Referenced by readTokenIs().

◆ readTokenIs()

bool PwpFile::readTokenIs ( const char *  tok)
inline

Read and compare a token.

Parameters
tokThe expected token.
Returns
true if a token was read and it is equal to tok.

Definition at line 672 of file PwpFile.h.

References readToken().

Referenced by readUntil().

◆ readUntil() [1/2]

bool PwpFile::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.

The stopC char is consumed but not added to str.

Parameters
strReceives the chars read from the file.
stopCThe char on which to stop reading. EOF is a valid stopC.
maxLenThe max number of chars to read if stopC is not encountered. Set to zero for unlimited (the default).
doTrimIf true, trim(str) is called. Otherwise str contains all chars read prior to stopC.
Returns
true if stopC was found. false if EOF encountered or maxLen chars were read before stopC was found.

Definition at line 1001 of file PwpFile.cxx.

References DefReserve, fp_, and trim().

Referenced by readUntilTrim().

◆ readUntil() [2/2]

bool PwpFile::readUntil ( PWP_UINT32 v,
const char  stopC 
)
inline

Reads a stopC terminated PWP_UINT32 value.

Any leading whitespace or whitespace between the integer and stopC is ignored. The regex would be "\s*(\d+)\s*@" (where @ is stopC). The stopC char is consumed.

Parameters
vReceives the PWP_UINT32 read from the file.
stopCThe char on which to stop reading. EOF is a valid stopC.
Returns
true if stopC was found. false if EOF encountered before stopC.

Definition at line 413 of file PwpFile.h.

References readInt(), and readTokenIs().

◆ readUntilTrim()

bool PwpFile::readUntilTrim ( std::string &  str,
const int  stopC,
int  maxLen = 0 
)
inline

Reads up to maxLen chars until the specified stop char is encountered.

After which, trim(str) is called. The stopC char is consumed but not added to str.

Parameters
strReceives the chars read from the file after trim(str).
stopCThe char on which to stop reading. EOF is a valid stopC.
maxLenThe max number of chars to read if stopC is not encountered. Set to zero for unlimited (the default).
Returns
true if stopC was found. false if EOF encountered or maxLen chars were read before stopC was found.

Definition at line 428 of file PwpFile.h.

References readUntil().

◆ readVal() [1/2]

template<typename T >
bool PwpFile::readVal ( T &  v,
const PWP_UINT32  base = 10 
)
inline

Reads a single value of type T.

If file is ascii and T supports bases, the data will be interpreted using the given numeric base.

Parameters
vThe value being read.
baseThe numeric base to use when converting the ascii value. Defaults to 10.
Returns
true if value was read and converted correctly.

Definition at line 488 of file PwpFile.h.

References isBinary(), read(), and readAscVal().

◆ readVal() [2/2]

template<typename T >
bool PwpFile::readVal ( T *  v,
const PWP_UINT32  cnt,
const PWP_UINT32  base = 10 
)
inline

Reads an array of cnt values of type T.

If file is ascii and T supports bases, the data will be interpreted using the given numeric base.

Parameters
vPtr to the array being filled.
cntThe number of values to read.
baseThe numeric base to use when converting the ascii value. Defaults to 10.
Returns
true if all values were read and converted correctly.

Definition at line 538 of file PwpFile.h.

References isBinary(), read(), and readAscVal().

◆ rewind()

bool PwpFile::rewind ( )

Reset position to the beginning of the file.

Returns
true on success.

Definition at line 887 of file PwpFile.cxx.

References fp_, and pwpFileRewind().

◆ rtrim()

static std::string& PwpFile::rtrim ( std::string &  s)
inlinestatic

trim trailing whitespace from s

Definition at line 745 of file PwpFile.h.

Referenced by trim().

◆ setByteOrder()

PWP_ENDIANNESS PwpFile::setByteOrder ( PWP_ENDIANNESS  order)

Set the byte order used for writes.

Parameters
orderThe desired byte order.
Returns
The previous byte order.
Note
The byte order is interpreted as:
  • PWP_ENDIAN_FOREIGN Opposite of getOsByteOrder()
  • PWP_ENDIAN_NATIVE Same as getOsByteOrder()
  • PWP_ENDIAN_BIG Always big endian
  • PWP_ENDIAN_LITTLE Always little endian

Definition at line 627 of file PwpFile.cxx.

References byteOrder_.

Referenced by CaePlugin< MT >::wrapRuntimeFile().

◆ setFmtFieldDouble()

void PwpFile::setFmtFieldDouble ( const int  width,
const int  prec 
)
virtual

Implements PwpWriterInterface.

Definition at line 1321 of file PwpFile.cxx.

References PwpFileWriter::setFmtFieldDouble(), and writer_.

Referenced by PwpFileRecord::setFmtFieldDouble().

◆ setFmtFieldSingle()

void PwpFile::setFmtFieldSingle ( const int  width,
const int  prec 
)
virtual

Implements PwpWriterInterface.

Definition at line 1303 of file PwpFile.cxx.

References PwpFileWriter::setFmtFieldSingle(), and writer_.

Referenced by PwpFileRecord::setFmtFieldSingle().

◆ setFmtType()

void PwpFile::setFmtType ( PwpWriterInterface::FormatType  type)
virtual

Implements PwpWriterInterface.

Definition at line 1340 of file PwpFile.cxx.

References PwpFileWriter::setFmtType(), and writer_.

Referenced by PwpFileRecord::setFmtType().

◆ setIntPos()

bool PwpFile::setIntPos ( const PWP_INT64 pos)

Set the current file position.

Note
File position handling is only guaranteed to work for files opened as pwpBinary. Platform end-of-line differences may break getPos() and setPos() if the file is opened as pwpAscii.
Returns
true on success.

Definition at line 870 of file PwpFile.cxx.

References fp_, and pwpFileSetpos().

Referenced by checkAscii(), and parseUnformattedRecord().

◆ setName()

void PwpFile::setName ( std::string  filename)

Set the file's associated filename.

Definition at line 915 of file PwpFile.cxx.

References filename_.

◆ setPos()

bool PwpFile::setPos ( const sysFILEPOS pos)

Set the current file position.

Note
File position handling is only guaranteed to work for files opened as pwpBinary. Platform end-of-line differences may break getPos() and setPos() if the file is opened as pwpAscii.
Returns
true on success.

Definition at line 881 of file PwpFile.cxx.

References fp_, and pwpFileSetpos().

Referenced by checkUnformatted(), PwpAnchoredFileValue< ValType, ValWriter >::commit(), PwpAnchoredFileValue< ValType, ValWriter >::rollback(), and writeAt().

◆ setPrecision()

PWP_ENUM_PRECISION PwpFile::setPrecision ( PWP_ENUM_PRECISION  precision)

Set the floating point precision used for writes.

Parameters
precisionThe desired precision.
Returns
The previous precision.

Definition at line 643 of file PwpFile.cxx.

References precision_.

Referenced by CaePlugin< MT >::wrapRuntimeFile().

◆ skipToChar()

bool PwpFile::skipToChar ( const int  nextC)
inline

Skip all chars up to and including nextC.

Parameters
nextCThe target char.
Returns
true if nextC was found. false if found EOF.

Definition at line 710 of file PwpFile.h.

References getcNotEOF().

◆ swap()

template<typename T >
static void PwpFile::swap ( T &  val)
inlinestatic

swap() - (Importer-only function) Wrapper for function swapByteOrder().

Definition at line 601 of file PwpFile.h.

References swapByteOrder().

Referenced by checkUnformatted(), and readSwap().

◆ swapByteOrder()

static const void* PwpFile::swapByteOrder ( void *  buf,
size_t  size 
)
inlinestatic

Performs an inplace byte swapping.

Used to convert to/from Big-Endian and Little-Endian byte ordering

Definition at line 585 of file PwpFile.h.

Referenced by swap().

◆ trim()

static std::string& PwpFile::trim ( std::string &  s)
inlinestatic

trim leading and trailing whitespace from s

Definition at line 758 of file PwpFile.h.

References ltrim(), and rtrim().

Referenced by readUntil().

◆ unfData() [1/2]

PWU_UNFDATA& PwpFile::unfData ( )
inline

Get the file's unformatted data buffer.

Returns
Reference to the file's unformatted data buffer.

Definition at line 778 of file PwpFile.h.

References ud_.

Referenced by PwpUnformattedWriter::beginRecord(), PwpUnformattedWriter::endRecord(), PwpUnformattedWriter::PwpUnformattedWriter(), PwpUnformattedWriter::write(), and PwpUnformattedWriter::~PwpUnformattedWriter().

◆ unfData() [2/2]

const PWU_UNFDATA& PwpFile::unfData ( ) const
inline

Get the file's unformatted data buffer.

Returns
Const reference to the file's unformatted data buffer.

Definition at line 784 of file PwpFile.h.

References ud_.

◆ ungetc()

bool PwpFile::ungetc ( const int  c)
inline

Return a byte value to the file.

The next read will get this value. This may be called multiple times.

Parameters
cThe byte value to put back into the file.

Definition at line 653 of file PwpFile.h.

References fp_.

Referenced by readAlphaToken(), readDouble(), readInt(), readToken(), and wspaceSkip().

◆ unlink()

bool PwpFile::unlink ( const char *  filename)
static

Delete a file.

Parameters
filenameThe name of an existing file to delete..
Returns
true on success.

Definition at line 1171 of file PwpFile.cxx.

References pwpFileDelete().

◆ wrap()

bool PwpFile::wrap ( FILE *  fp,
std::string  filename = std::string(),
int  mode = 0 
)

Take ownership of fp opened using pwpFileOpen(filename, mode).

The file object will take ownership of fp. fp must have been opened using pwpFileOpen(filename, mode). fp will be closed in this object's destructor. If needed, file will be closed before wrapping fp.

Parameters
fpA FILE pointer returned from pwpFileOpen().
filenameThe filename passed to pwpFileOpen().
modeThe mode passed to pwpFileOpen().
Returns
true on success.
See also
sysFILEMODE, pwpFileOpen()

Definition at line 568 of file PwpFile.cxx.

References close(), filename_, fp(), fp_, isAscii(), isBinary(), isUnformatted(), mode_, and writer_.

Referenced by open(), PwpFile(), and CaePlugin< MT >::wrapRuntimeFile().

◆ write() [1/11]

bool PwpFile::write ( PWP_UINT32  val,
const char *  suffix = 0,
const char *  prefix = 0 
)
virtual

Writes a integer value with proper encoding and byte order.

Parameters
valThe value to write.
suffixString written after val (pwpAscii mode only).
prefixString written before val (pwpAscii mode only).
Returns
true on success.
Note
For pwpBinary and pwpUnformatted modes, byte ordering is enforced.
For pwpUnformatted mode, the record byte count is incremented by sizeof(val).
suffix and prefix are ignored by all modes except pwpAscii.

Implements PwpWriterInterface.

Definition at line 1268 of file PwpFile.cxx.

References PwpWriterInterface::write(), and writer_.

◆ write() [2/11]

bool PwpFile::write ( PWP_INT8  val,
const char *  suffix = 0,
const char *  prefix = 0 
)
virtual

Writes a integer value with proper encoding and byte order.

Parameters
valThe value to write.
suffixString written after val (pwpAscii mode only).
prefixString written before val (pwpAscii mode only).
Returns
true on success.
Note
For pwpBinary and pwpUnformatted modes, byte ordering is enforced.
For pwpUnformatted mode, the record byte count is incremented by sizeof(val).
suffix and prefix are ignored by all modes except pwpAscii.

Implements PwpWriterInterface.

Definition at line 1254 of file PwpFile.cxx.

References PwpWriterInterface::write(), and writer_.

◆ write() [3/11]

bool PwpFile::write ( PWP_FLOAT  val,
const char *  suffix = 0,
const char *  prefix = 0 
)
virtual

Writes a floating point value with proper precision, encoding and byte order.

Parameters
valThe value to write.
suffixString written after val (pwpAscii mode only).
prefixString written before val (pwpAscii mode only).
Returns
true on success.
Note
For pwpBinary and pwpUnformatted modes, precision and byte ordering is enforced.
For pwpUnformatted mode, the record byte count is incremented by sizeof((precision)val).
suffix and prefix are ignored by all modes except pwpAscii.

Implements PwpWriterInterface.

Definition at line 1289 of file PwpFile.cxx.

References PwpWriterInterface::write(), and writer_.

◆ write() [4/11]

bool PwpFile::write ( const char *  val,
PWP_INT  size = -1,
char  pad = 0 
)
virtual

Writes a string value.

Parameters
valThe string to write.
sizeThe number of string characters to write. If -1, strlen(val) is used.
padIf size > strlen(val), the pad value will be used to fill the remaining characters.
Returns
true on success.
Note
For pwpUnformatted mode, the record byte count is incremented by size or strlen(val) if size is -1.

Implements PwpWriterInterface.

Definition at line 1356 of file PwpFile.cxx.

References PwpWriterInterface::write(), and writer_.

◆ write() [5/11]

bool PwpFile::write ( PWP_UINT8  val,
const char *  suffix = 0,
const char *  prefix = 0 
)
virtual

Writes a integer value with proper encoding and byte order.

Parameters
valThe value to write.
suffixString written after val (pwpAscii mode only).
prefixString written before val (pwpAscii mode only).
Returns
true on success.
Note
For pwpBinary and pwpUnformatted modes, byte ordering is enforced.
For pwpUnformatted mode, the record byte count is incremented by sizeof(val).
suffix and prefix are ignored by all modes except pwpAscii.

Implements PwpWriterInterface.

Definition at line 1282 of file PwpFile.cxx.

References PwpWriterInterface::write(), and writer_.

◆ write() [6/11]

bool PwpFile::write ( PWP_INT32  val,
const char *  suffix = 0,
const char *  prefix = 0 
)
virtual

Writes a integer value with proper encoding and byte order.

Parameters
valThe value to write.
suffixString written after val (pwpAscii mode only).
prefixString written before val (pwpAscii mode only).
Returns
true on success.
Note
For pwpBinary and pwpUnformatted modes, byte ordering is enforced.
For pwpUnformatted mode, the record byte count is incremented by sizeof(val).
suffix and prefix are ignored by all modes except pwpAscii.

Implements PwpWriterInterface.

Definition at line 1240 of file PwpFile.cxx.

References PwpWriterInterface::write(), and writer_.

◆ write() [7/11]

bool PwpFile::write ( PWP_REAL  val,
const char *  suffix = 0,
const char *  prefix = 0 
)
virtual

Writes a floating point value with proper precision, encoding and byte order.

Parameters
valThe value to write.
suffixString written after val (pwpAscii mode only).
prefixString written before val (pwpAscii mode only).
Returns
true on success.
Note
For pwpBinary and pwpUnformatted modes, precision and byte ordering is enforced.
For pwpUnformatted mode, the record byte count is incremented by sizeof((precision)val).
suffix and prefix are ignored by all modes except pwpAscii.

Implements PwpWriterInterface.

Definition at line 1296 of file PwpFile.cxx.

References PwpWriterInterface::write(), and writer_.

◆ write() [8/11]

bool PwpFile::write ( PWP_INT64  val,
const char *  suffix = 0,
const char *  prefix = 0 
)
virtual

Writes a integer value with proper encoding and byte order.

Parameters
valThe value to write.
suffixString written after val (pwpAscii mode only).
prefixString written before val (pwpAscii mode only).
Returns
true on success.
Note
For pwpBinary and pwpUnformatted modes, byte ordering is enforced.
For pwpUnformatted mode, the record byte count is incremented by sizeof(val).
suffix and prefix are ignored by all modes except pwpAscii.

Implements PwpWriterInterface.

Definition at line 1233 of file PwpFile.cxx.

References PwpWriterInterface::write(), and writer_.

Referenced by PwpFileRecord::write(), writeAt(), PwpAnchoredFileValueWriter< ValType >::writeBin(), and PwpAnchoredFileValueWriter< ValType >::writeUnf().

◆ write() [9/11]

bool PwpFile::write ( PWP_INT16  val,
const char *  suffix = 0,
const char *  prefix = 0 
)
virtual

Writes a integer value with proper encoding and byte order.

Parameters
valThe value to write.
suffixString written after val (pwpAscii mode only).
prefixString written before val (pwpAscii mode only).
Returns
true on success.
Note
For pwpBinary and pwpUnformatted modes, byte ordering is enforced.
For pwpUnformatted mode, the record byte count is incremented by sizeof(val).
suffix and prefix are ignored by all modes except pwpAscii.

Implements PwpWriterInterface.

Definition at line 1247 of file PwpFile.cxx.

References PwpWriterInterface::write(), and writer_.

◆ write() [10/11]

bool PwpFile::write ( PWP_UINT16  val,
const char *  suffix = 0,
const char *  prefix = 0 
)
virtual

Writes a integer value with proper encoding and byte order.

Parameters
valThe value to write.
suffixString written after val (pwpAscii mode only).
prefixString written before val (pwpAscii mode only).
Returns
true on success.
Note
For pwpBinary and pwpUnformatted modes, byte ordering is enforced.
For pwpUnformatted mode, the record byte count is incremented by sizeof(val).
suffix and prefix are ignored by all modes except pwpAscii.

Implements PwpWriterInterface.

Definition at line 1275 of file PwpFile.cxx.

References PwpWriterInterface::write(), and writer_.

◆ write() [11/11]

bool PwpFile::write ( PWP_UINT64  val,
const char *  suffix = 0,
const char *  prefix = 0 
)
virtual

Writes a integer value with proper encoding and byte order.

Parameters
valThe value to write.
suffixString written after val (pwpAscii mode only).
prefixString written before val (pwpAscii mode only).
Returns
true on success.
Note
For pwpBinary and pwpUnformatted modes, byte ordering is enforced.
For pwpUnformatted mode, the record byte count is incremented by sizeof(val).
suffix and prefix are ignored by all modes except pwpAscii.

Implements PwpWriterInterface.

Definition at line 1261 of file PwpFile.cxx.

References PwpWriterInterface::write(), and writer_.

◆ writeAt()

template<typename T >
bool PwpFile::writeAt ( sysFILEPOS  pos,
const T &  val,
const char *  suffix = 0,
const char *  prefix = 0 
)

Writes an endian enforced value directly at a given file position.

The original file position is restored upon successful return.

Parameters
posThe file position from getPos().
valThe value to write.
suffixString written after val (pwpAscii mode only).
prefixString written before val (pwpAscii mode only).
Returns
true on success.
Note
The pwpUnformatted record length is not changed by this call.
See also
PwpFileRecord::write(sysFILEPOS, PWP_UINT32, PWP_ENDIANNESS)

Definition at line 868 of file PwpFile.h.

References fp_, getByteOrder(), getPos(), isUnformatted(), pwpFileWrite(), PwuApplyEndianness(), setPos(), and write().

Referenced by PwpFileRecord::writeAt().

◆ wspaceSkip()

bool PwpFile::wspaceSkip ( )

Reads and discards consecutive whitespace bytes.

Returns
false if EOF encountered.

Definition at line 936 of file PwpFile.cxx.

References getcNotEOF(), and ungetc().

Referenced by readAlphaToken(), readDouble(), readInt(), readToken(), wspaceSkipToChar(), and wspaceSkipToOneOf().

◆ wspaceSkipToChar()

bool PwpFile::wspaceSkipToChar ( const int  nextC)
inline

Skip whitespace and read the next char.

Parameters
nextCThe target char.
Returns
true if the next, non-whitespace char is nextC. All chars up to and including nextC are consumed.

Definition at line 683 of file PwpFile.h.

References fp_, and wspaceSkip().

Referenced by wspaceSkipToEOF().

◆ wspaceSkipToEOF()

bool PwpFile::wspaceSkipToEOF ( )
inline

Skip whitespace and read until EOF.

Returns
true if the next, non-whitespace char is EOF. All chars up to and including EOF are read and discarded.

Definition at line 726 of file PwpFile.h.

References wspaceSkipToChar().

◆ wspaceSkipToOneOf()

bool PwpFile::wspaceSkipToOneOf ( const char *  stopCs,
char &  theC 
)
inline

Skip whitespace and read the next char returning it in theC.

Parameters
stopCsThe list of target chars.
theCThe next, non-whitespace char on which skip was stopped.
Returns
true if theC is in stopCs. All chars up to and including theC are consumed.

Definition at line 695 of file PwpFile.h.

References fp_, and wspaceSkip().

Member Data Documentation

◆ byteOrder_

PWP_ENDIANNESS PwpFile::byteOrder_
private

The file's byte order.

Definition at line 859 of file PwpFile.h.

Referenced by getByteOrder(), needByteSwap(), operator=(), and setByteOrder().

◆ filename_

std::string PwpFile::filename_
private

The file name.

Definition at line 858 of file PwpFile.h.

Referenced by checkAscii(), close(), getName(), operator=(), PwpFile(), setName(), and wrap().

◆ fp_

FILE* PwpFile::fp_
private

◆ mode_

int PwpFile::mode_
private

The mode.

Definition at line 857 of file PwpFile.h.

Referenced by close(), isAscii(), isBinary(), isReadable(), isUnformatted(), isWritable(), operator=(), PwpFile(), and wrap().

◆ precision_

PWP_ENUM_PRECISION PwpFile::precision_
private

The file's floating point precision.

Definition at line 860 of file PwpFile.h.

Referenced by getPrecision(), isDouble(), isSingle(), operator=(), and setPrecision().

◆ ud_

PWU_UNFDATA PwpFile::ud_
private

The file's unformatted data stats.

Definition at line 861 of file PwpFile.h.

Referenced by unfData().

◆ writer_

PwpFileWriter* PwpFile::writer_
private

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