Pointwise Plugin SDK
|
Writes solver files. More...
#include <PwpFile.h>
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 |
Determines whether the file is Ascii by reading the contents of the file. More... | |
bool | checkUnformatted (bool &swapped, std::vector< PWP_INT64 > *pRecSizes=0) const |
Determines 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... | |
PWP_INT64 | getPos () const |
Get the current file position. More... | |
bool | getPos (sysFILEPOS &pos) 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 supports 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 supports 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... | |
PwpFile & | operator= (const PwpFile &ref) |
Assignment operator Does not copy the file position or unformatted data. More... | |
PwpFile (const PwpFile &ref) | |
Copy constructor 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... | |
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 (char *v, PWP_UINT32 cnt, const PWP_UINT32 base=10) |
Reads an array of cnt characters 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_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_UINT32 *v, PWP_UINT32 cnt, const PWP_UINT32 base=10) |
Reads an array of cnt PWP_UINT32 values 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 > | |
T | readSwap (const bool swapbyte) |
Reads a single value of type T. More... | |
template<typename T > | |
bool | readSwap (T &val, 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 (PWP_UINT32 &v, const char stopC) |
Reads a stopC terminated PWP_UINT32 value. 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 | 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_UNFDATA & | unfData () |
Get the file's unformatted data buffer. More... | |
const PWU_UNFDATA & | unfData () 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 (const char *val, PWP_INT size=-1, char pad=0) |
Writes a string value. 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_INT16 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_INT64 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_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_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_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_UINT8 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... | |
![]() | |
bool | writef (const char *fmt,...) |
Writes a formatted string value. More... | |
bool | writef (PWP_INT size, char pad, 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... | |
PwpFileWriter * | writer_ |
The file writer implementation. More... | |
Additional Inherited Members | |
![]() | |
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... | |
![]() | |
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... | |
Writes solver files.
The PwpFile class is especially useful when a solver supports files of various encodings, precisions and byte orders.
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.
fp | A FILE pointer returned from pwpFileOpen(). |
filename | The filename passed to pwpFileOpen(). |
mode | The mode passed to pwpFileOpen(). |
Definition at line 515 of file PwpFile.cxx.
PwpFile::PwpFile | ( | std::string | filename, |
int | mode | ||
) |
File open constructor.
Constructs and opens a file object for the given filename and mode.
filename | The filename to open. |
mode | Controls how the file is opened. This value is built from the bitwise OR of 2 sysFILEMODE flags. |
Definition at line 528 of file PwpFile.cxx.
References open().
PwpFile::PwpFile | ( | const PwpFile & | ref | ) |
Copy constructor Does not copy the file position or unformatted data.
Definition at line 540 of file PwpFile.cxx.
|
virtual |
Destructor.
If needed, file will be closed.
Definition at line 552 of file PwpFile.cxx.
References close().
|
virtual |
Starts an unformatted record.
Starts an unformatted record. If a record is already active, it will be closed.
Implements PwpWriterInterface.
Definition at line 1235 of file PwpFile.cxx.
References PwpFileWriter::beginRecord(), and writer_.
Referenced by PwpFileRecord::beginRecord().
|
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).
Implements PwpWriterInterface.
Definition at line 1241 of file PwpFile.cxx.
References PwpFileWriter::beginRecord(), and writer_.
bool PwpFile::checkAscii | ( | ) | const |
Determines whether the file is Ascii by reading the contents of the file.
Uses the same method as used in GgFile::isAscii()
Definition at line 693 of file PwpFile.cxx.
References filename_, fp_, getSize(), pwpFileRead(), and setIntPos().
bool PwpFile::checkUnformatted | ( | bool & | swapped, |
std::vector< PWP_INT64 > * | pRecSizes = 0 |
||
) | const |
Determines unformatted type settings by reading the contents of the file.
Uses the same method as used in GgFile::isUnformatted()
Definition at line 777 of file PwpFile.cxx.
References getPos(), getSize(), parseUnformattedRecord(), setPos(), and swap().
bool PwpFile::close | ( | ) |
Explicitly close the file object.
File will automatically be closed in the destructor.
Definition at line 613 of file PwpFile.cxx.
References filename_, fp_, mode_, pwpFileClose(), and writer_.
Referenced by wrap(), and ~PwpFile().
|
virtual |
Ends an unformatted record.
Ends an active record for files opened with pwpUnformatted mode.
Implements PwpWriterInterface.
Definition at line 1247 of file PwpFile.cxx.
References PwpFileWriter::endRecord(), and writer_.
Referenced by PwpFileRecord::endRecord().
bool PwpFile::fileEof | ( | ) | const |
Check for the end of file.
Definition at line 606 of file PwpFile.cxx.
References fp_.
bool PwpFile::flush | ( | ) |
Flush file to disk.
Definition at line 842 of file PwpFile.cxx.
References fp_, and pwpFileFlush().
|
inline |
Get the FILE pointer.
Definition at line 767 of file PwpFile.h.
References fp_.
Referenced by CaePlugin< MT >::fp(), PwpFile(), PwpUnformattedWriter::PwpUnformattedWriter(), wrap(), PwpBinaryWriter::write(), PwpAsciiWriter::write(), PwpBinaryWriter::writeOrdered(), and PwpAsciiWriter::writeWdPrec().
PWP_ENDIANNESS PwpFile::getByteOrder | ( | bool | mapBigLittle = false | ) | const |
Get the byte order used for writes.
mapBigLittle | If true, PWP_ENDIAN_FOREIGN or PWP_ENDIAN_NATIVE byte orders will be mapped to PWP_ENDIAN_BIG or PWP_ENDIAN_LITTLE based on getOsByteOrder(). |
Definition at line 636 of file PwpFile.cxx.
References byteOrder_, and mapToBigLittle().
Referenced by PwpUnformattedWriter::beginRecord(), writeAt(), and PwpAnchoredFileValueWriter< ValType >::writeUnf().
|
inline |
|
inline |
Reads a single byte value.
c | The byte value read or EOF. |
Definition at line 645 of file PwpFile.h.
References fp_.
Referenced by skipToChar(), and wspaceSkip().
|
virtual |
Implements PwpWriterInterface.
Definition at line 1350 of file PwpFile.cxx.
References PwpFileWriter::getFmtFieldDouble(), and writer_.
Referenced by PwpFileRecord::getFmtFieldDouble().
|
virtual |
Implements PwpWriterInterface.
Definition at line 1332 of file PwpFile.cxx.
References PwpFileWriter::getFmtFieldSingle(), and writer_.
Referenced by PwpFileRecord::getFmtFieldSingle().
|
virtual |
Implements PwpWriterInterface.
Definition at line 1369 of file PwpFile.cxx.
References PwpWriterInterface::FormatG, PwpFileWriter::getFmtType(), and writer_.
Referenced by PwpFileRecord::getFmtType().
const char * PwpFile::getName | ( | ) | const |
Get the file's associated filename.
Definition at line 922 of file PwpFile.cxx.
References filename_.
|
static |
Get the OS's native byte ordering.
Definition at line 1198 of file PwpFile.cxx.
References PwuGetOsEndianness().
Referenced by mapToBigLittle(), and needByteSwap().
PWP_INT64 PwpFile::getPos | ( | ) | const |
Get the current file position.
Definition at line 855 of file PwpFile.cxx.
References fp_, and pwpFileGetpos().
Referenced by writeAt().
bool PwpFile::getPos | ( | sysFILEPOS & | pos | ) | const |
Get the current file position.
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().
PWP_ENUM_PRECISION PwpFile::getPrecision | ( | ) | const |
Get the floating point precision used for writes.
Definition at line 652 of file PwpFile.cxx.
References precision_.
|
static |
Get the file size for the given filename.
Definition at line 905 of file PwpFile.cxx.
References pwpFilenameGetSize().
bool PwpFile::getSize | ( | PWP_UINT64 & | size | ) | const |
Get the size of the file managed by this object.
Definition at line 895 of file PwpFile.cxx.
References fp_, and pwpFileGetSize().
Referenced by checkAscii(), checkUnformatted(), and parseUnformattedRecord().
bool PwpFile::isAscii | ( | ) | const |
Determines if file was opened with either the 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().
bool PwpFile::isBinary | ( | ) | const |
Determines 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().
bool PwpFile::isDouble | ( | ) | const |
Determines if floating point 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().
bool PwpFile::isEof | ( | ) | const |
Get the end-of-file status.
Definition at line 835 of file PwpFile.cxx.
References fp_, and pwpFileEof().
bool PwpFile::isOpen | ( | ) | const |
Determines a file's status.
Definition at line 600 of file PwpFile.cxx.
References fp_.
Referenced by PwpFileRecord::~PwpFileRecord().
bool PwpFile::isReadable | ( | ) | const |
Determines if file supports read operations.
Definition at line 659 of file PwpFile.cxx.
bool PwpFile::isSingle | ( | ) | const |
Determines if floating point 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().
bool PwpFile::isUnformatted | ( | ) | const |
Determines 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().
bool PwpFile::isWritable | ( | ) | const |
Determines if file supports write operations.
Definition at line 666 of file PwpFile.cxx.
|
inlinestatic |
|
static |
Map a byte ordering value to PWP_ENDIAN_BIG or PWP_ENDIAN_LITTLE based on getOsByteOrder().
byteOrder | The byte order value to map. |
Definition at line 1205 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().
|
inline |
Determine if byte swapping is needed for this file.
Definition at line 793 of file PwpFile.h.
References byteOrder_.
Referenced by PwpBinaryWriter::writeOrdered().
|
static |
Determine if byte swapping is needed for a given byte order.
byteOrder | The byte order value to check. |
Definition at line 1228 of file PwpFile.cxx.
References getOsByteOrder(), and mapToBigLittle().
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.
filename | The filename to open. |
mode | Controls how the file is opened. This value is built from the bitwise OR of 2 sysFILEMODE flags. |
Definition at line 593 of file PwpFile.cxx.
References pwpFileOpen(), and wrap().
Referenced by operator=(), and PwpFile().
|
inline |
Assignment 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_.
bool PwpFile::read | ( | void * | buf, |
size_t | size, | ||
size_t | count | ||
) |
Read a collection of data items.
buf | Pointer to the read buffer. |
size | The size of each item. |
count | The number of items to read. |
Definition at line 929 of file PwpFile.cxx.
References fp_, and pwpFileRead().
Referenced by readSwap(), and readVal().
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.
tok | Receives the token. |
Definition at line 977 of file PwpFile.cxx.
References DefReserve, fp_, ungetc(), and wspaceSkip().
Referenced by readAlphaTokenIs().
|
inline |
Read and compare an alpha token.
tok | The expected token. |
Definition at line 663 of file PwpFile.h.
References readAlphaToken().
bool PwpFile::readAscVal | ( | char * | v, |
PWP_UINT32 | cnt, | ||
const PWP_UINT32 | base = 10 |
||
) |
Reads an array of cnt characters from an ascii file.
v | Ptr to the array being filled. |
cnt | The number of values to read. |
base | The numeric base to use when converting the ascii value. Defaults to 10. |
Definition at line 1089 of file PwpFile.cxx.
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.
v | Ptr to the array being filled. |
cnt | The number of values to read. |
base | Ignored for floating point values. It is included to make its call signature the same as the integer overloads. |
Definition at line 1063 of file PwpFile.cxx.
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.
v | Ptr to the array being filled. |
cnt | The number of values to read. |
base | Ignored for floating point values. It is included to make its call signature the same as the integer overloads. |
Definition at line 1050 of file PwpFile.cxx.
Referenced by readVal().
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.
v | Ptr to the array being filled. |
cnt | The number of values to read. |
base | The numeric base to use when converting the ascii value. Defaults to 10. |
Definition at line 1076 of file PwpFile.cxx.
bool PwpFile::readDouble | ( | PWP_REAL & | v, |
PWP_UINT32 | maxDigits = 0 |
||
) |
Reads a single PWP_REAL value.
v | The value being read. |
maxDigits | The maximum number of digits to read. Ignored by non-ascii files. |
Definition at line 1161 of file PwpFile.cxx.
References DefReserve, fp_, PWP_UINT32_MAX, ungetc(), and wspaceSkip().
|
inline |
Reads a single PWP_UINT32 hex value.
For non-ascii files, this is the same as calling readInt().
v | The value being read. |
maxDigits | The maximum number of digits to read. Ignored by non-ascii files. |
Definition at line 628 of file PwpFile.h.
References 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.
v | The value being read. |
base | The numeric base to use when converting the ascii value. Defaults to 10. Ignored by non-ascii files. |
maxDigits | The maximum number of digits to read. Ignored by non-ascii files. |
Definition at line 1101 of file PwpFile.cxx.
References DefReserve, fp_, PWP_UINT32_MAX, ungetc(), and wspaceSkip().
Referenced by readHex(), readOctal(), readOptionalInt(), and readUntil().
|
inline |
Reads a single PWP_UINT32 octal value.
For non-ascii files, this is the same as calling readInt().
v | The value being read. |
maxDigits | The maximum number of digits to read. Ignored by non-ascii files. |
Definition at line 616 of file PwpFile.h.
References readInt().
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.
v | The value being read. |
defV | The value stored in v if not read from file. |
base | The numeric base to use when converting the ascii value. Defaults to 10. Ignored by non-ascii files. |
maxDigits | The maximum number of digits to read. Ignored by non-ascii files. |
Definition at line 1153 of file PwpFile.cxx.
References readInt().
|
inline |
|
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.
val | The value read. |
swapbyte | If true, swap the val's bytes after reading from the file. |
Definition at line 502 of file PwpFile.h.
References read(), and swap().
Referenced by parseUnformattedRecord().
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.
tok | Receives the token. |
Definition at line 953 of file PwpFile.cxx.
References DefReserve, fp_, ungetc(), and wspaceSkip().
Referenced by readTokenIs().
|
inline |
Read and compare a token.
tok | The expected token. |
Definition at line 673 of file PwpFile.h.
References readToken().
Referenced by readUntil().
|
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.
v | Receives the PWP_UINT32 read from the file. |
stopC | The char on which to stop reading. EOF is a valid stopC. |
Definition at line 413 of file PwpFile.h.
References readInt(), and readTokenIs().
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.
str | Receives the chars read from the file. |
stopC | The char on which to stop reading. EOF is a valid stopC. |
maxLen | The max number of chars to read if stopC is not encountered. Set to zero for unlimited (the default). |
doTrim | If true, trim(str) is called. Otherwise str contains all chars read prior to stopC. |
Definition at line 1001 of file PwpFile.cxx.
References DefReserve, fp_, and trim().
Referenced by readUntilTrim().
|
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.
str | Receives the chars read from the file after trim(str). |
stopC | The char on which to stop reading. EOF is a valid stopC. |
maxLen | The max number of chars to read if stopC is not encountered. Set to zero for unlimited (the default). |
Definition at line 428 of file PwpFile.h.
References readUntil().
|
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.
v | The value being read. |
base | The numeric base to use when converting the ascii value. Defaults to 10. |
Definition at line 488 of file PwpFile.h.
References isBinary(), read(), and readAscVal().
|
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.
v | Ptr to the array being filled. |
cnt | The number of values to read. |
base | The numeric base to use when converting the ascii value. Defaults to 10. |
Definition at line 539 of file PwpFile.h.
References isBinary(), read(), and readAscVal().
bool PwpFile::rewind | ( | ) |
Reset position to the beginning of the file.
Definition at line 887 of file PwpFile.cxx.
References fp_, and pwpFileRewind().
|
inlinestatic |
PWP_ENDIANNESS PwpFile::setByteOrder | ( | PWP_ENDIANNESS | order | ) |
Set the byte order used for writes.
order | The desired byte order. |
Definition at line 627 of file PwpFile.cxx.
References byteOrder_.
Referenced by CaePlugin< MT >::wrapRuntimeFile().
|
virtual |
Implements PwpWriterInterface.
Definition at line 1341 of file PwpFile.cxx.
References PwpFileWriter::setFmtFieldDouble(), and writer_.
Referenced by PwpFileRecord::setFmtFieldDouble().
|
virtual |
Implements PwpWriterInterface.
Definition at line 1323 of file PwpFile.cxx.
References PwpFileWriter::setFmtFieldSingle(), and writer_.
Referenced by PwpFileRecord::setFmtFieldSingle().
|
virtual |
Implements PwpWriterInterface.
Definition at line 1360 of file PwpFile.cxx.
References PwpFileWriter::setFmtType(), and writer_.
Referenced by PwpFileRecord::setFmtType().
bool PwpFile::setIntPos | ( | const PWP_INT64 & | pos | ) |
Set the current file position.
Definition at line 870 of file PwpFile.cxx.
References fp_, and pwpFileSetpos().
Referenced by checkAscii(), and parseUnformattedRecord().
void PwpFile::setName | ( | std::string | filename | ) |
Set the file's associated filename.
Definition at line 915 of file PwpFile.cxx.
References filename_.
bool PwpFile::setPos | ( | const sysFILEPOS & | pos | ) |
Set the current file position.
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().
PWP_ENUM_PRECISION PwpFile::setPrecision | ( | PWP_ENUM_PRECISION | precision | ) |
Set the floating point precision used for writes.
precision | The desired precision. |
Definition at line 643 of file PwpFile.cxx.
References precision_.
Referenced by CaePlugin< MT >::wrapRuntimeFile().
|
inline |
Skip all chars up to and including nextC.
nextC | The target char. |
Definition at line 711 of file PwpFile.h.
References getcNotEOF().
|
inlinestatic |
swap() - (Importer-only function) Wrapper for function swapByteOrder().
Definition at line 602 of file PwpFile.h.
References swapByteOrder().
Referenced by checkUnformatted(), and readSwap().
|
inlinestatic |
|
inlinestatic |
trim leading and trailing whitespace from s
Definition at line 759 of file PwpFile.h.
References ltrim(), and rtrim().
Referenced by readUntil().
|
inline |
Get the file's unformatted data buffer.
Definition at line 779 of file PwpFile.h.
References ud_.
Referenced by PwpUnformattedWriter::beginRecord(), PwpUnformattedWriter::endRecord(), PwpUnformattedWriter::PwpUnformattedWriter(), PwpUnformattedWriter::write(), and PwpUnformattedWriter::~PwpUnformattedWriter().
|
inline |
|
inline |
Return a byte value to the file.
The next read will get this value. This may be called multiple times.
c | The byte value to put back into the file. |
Definition at line 654 of file PwpFile.h.
References fp_.
Referenced by readAlphaToken(), readDouble(), readInt(), readToken(), and wspaceSkip().
|
static |
Delete a file.
filename | The name of an existing file to delete.. |
Definition at line 1191 of file PwpFile.cxx.
References pwpFileDelete().
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.
fp | A FILE pointer returned from pwpFileOpen(). |
filename | The filename passed to pwpFileOpen(). |
mode | The mode passed to 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().
|
virtual |
Writes a string value.
val | The string to write. |
size | The number of string characters to write. If -1, strlen(val) is used. |
pad | If size > strlen(val), the pad value will be used to fill the remaining characters. |
Implements PwpWriterInterface.
Definition at line 1376 of file PwpFile.cxx.
References PwpWriterInterface::write(), and writer_.
|
virtual |
Writes a floating point value with proper precision, encoding and byte order.
val | The value to write. |
suffix | String written after val (pwpAscii mode only). |
prefix | String written before val (pwpAscii mode only). |
Implements PwpWriterInterface.
Definition at line 1309 of file PwpFile.cxx.
References PwpWriterInterface::write(), and writer_.
|
virtual |
Writes a integer value with proper encoding and byte order.
val | The value to write. |
suffix | String written after val (pwpAscii mode only). |
prefix | String written before val (pwpAscii mode only). |
Implements PwpWriterInterface.
Definition at line 1267 of file PwpFile.cxx.
References PwpWriterInterface::write(), and writer_.
|
virtual |
Writes a integer value with proper encoding and byte order.
val | The value to write. |
suffix | String written after val (pwpAscii mode only). |
prefix | String written before val (pwpAscii mode only). |
Implements PwpWriterInterface.
Definition at line 1260 of file PwpFile.cxx.
References PwpWriterInterface::write(), and writer_.
|
virtual |
Writes a integer value with proper encoding and byte order.
val | The value to write. |
suffix | String written after val (pwpAscii mode only). |
prefix | String written before val (pwpAscii mode only). |
Implements PwpWriterInterface.
Definition at line 1253 of file PwpFile.cxx.
References PwpWriterInterface::write(), and writer_.
Referenced by PwpFileRecord::write(), writeAt(), PwpAnchoredFileValueWriter< ValType >::writeBin(), and PwpAnchoredFileValueWriter< ValType >::writeUnf().
|
virtual |
Writes a integer value with proper encoding and byte order.
val | The value to write. |
suffix | String written after val (pwpAscii mode only). |
prefix | String written before val (pwpAscii mode only). |
Implements PwpWriterInterface.
Definition at line 1274 of file PwpFile.cxx.
References PwpWriterInterface::write(), and writer_.
|
virtual |
Writes a floating point value with proper precision, encoding and byte order.
val | The value to write. |
suffix | String written after val (pwpAscii mode only). |
prefix | String written before val (pwpAscii mode only). |
Implements PwpWriterInterface.
Definition at line 1316 of file PwpFile.cxx.
References PwpWriterInterface::write(), and writer_.
|
virtual |
Writes a integer value with proper encoding and byte order.
val | The value to write. |
suffix | String written after val (pwpAscii mode only). |
prefix | String written before val (pwpAscii mode only). |
Implements PwpWriterInterface.
Definition at line 1295 of file PwpFile.cxx.
References PwpWriterInterface::write(), and writer_.
|
virtual |
Writes a integer value with proper encoding and byte order.
val | The value to write. |
suffix | String written after val (pwpAscii mode only). |
prefix | String written before val (pwpAscii mode only). |
Implements PwpWriterInterface.
Definition at line 1288 of file PwpFile.cxx.
References PwpWriterInterface::write(), and writer_.
|
virtual |
Writes a integer value with proper encoding and byte order.
val | The value to write. |
suffix | String written after val (pwpAscii mode only). |
prefix | String written before val (pwpAscii mode only). |
Implements PwpWriterInterface.
Definition at line 1281 of file PwpFile.cxx.
References PwpWriterInterface::write(), and writer_.
|
virtual |
Writes a integer value with proper encoding and byte order.
val | The value to write. |
suffix | String written after val (pwpAscii mode only). |
prefix | String written before val (pwpAscii mode only). |
Implements PwpWriterInterface.
Definition at line 1302 of file PwpFile.cxx.
References PwpWriterInterface::write(), and writer_.
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.
pos | The file position from getPos(). |
val | The value to write. |
suffix | String written after val (pwpAscii mode only). |
prefix | String written before val (pwpAscii mode only). |
Definition at line 869 of file PwpFile.h.
References fp_, getByteOrder(), getPos(), isUnformatted(), pwpFileWrite(), PwuApplyEndianness(), setPos(), and write().
Referenced by PwpFileRecord::writeAt().
bool PwpFile::wspaceSkip | ( | ) |
Reads and discards consecutive whitespace bytes.
Definition at line 936 of file PwpFile.cxx.
References getcNotEOF(), and ungetc().
Referenced by readAlphaToken(), readDouble(), readInt(), readToken(), wspaceSkipToChar(), and wspaceSkipToOneOf().
|
inline |
Skip whitespace and read the next char.
nextC | The target char. |
Definition at line 684 of file PwpFile.h.
References fp_, and wspaceSkip().
Referenced by wspaceSkipToEOF().
|
inline |
Skip whitespace and read until EOF.
Definition at line 727 of file PwpFile.h.
References wspaceSkipToChar().
|
inline |
Skip whitespace and read the next char returning it in theC.
stopCs | The list of target chars. |
theC | The next, non-whitespace char on which skip was stopped. |
Definition at line 696 of file PwpFile.h.
References fp_, and wspaceSkip().
|
private |
The file's byte order.
Definition at line 860 of file PwpFile.h.
Referenced by getByteOrder(), needByteSwap(), operator=(), and setByteOrder().
|
private |
The file name.
Definition at line 859 of file PwpFile.h.
Referenced by checkAscii(), close(), getName(), operator=(), PwpFile(), setName(), and wrap().
|
private |
The FILE pointer.
Definition at line 857 of file PwpFile.h.
Referenced by checkAscii(), close(), fileEof(), flush(), fp(), getc(), getcNotEOF(), getPos(), getSize(), isEof(), isOpen(), operator FILE *(), read(), readAlphaToken(), readDouble(), readInt(), readSwap(), readToken(), readUntil(), rewind(), setIntPos(), setPos(), ungetc(), wrap(), writeAt(), wspaceSkipToChar(), and wspaceSkipToOneOf().
|
private |
The mode.
Definition at line 858 of file PwpFile.h.
Referenced by close(), isAscii(), isBinary(), isReadable(), isUnformatted(), isWritable(), operator=(), PwpFile(), and wrap().
|
private |
The file's floating point precision.
Definition at line 861 of file PwpFile.h.
Referenced by getPrecision(), isDouble(), isSingle(), operator=(), and setPrecision().
|
private |
|
private |
The file writer implementation.
Definition at line 863 of file PwpFile.h.
Referenced by beginRecord(), close(), endRecord(), getFmtFieldDouble(), getFmtFieldSingle(), getFmtType(), setFmtFieldDouble(), setFmtFieldSingle(), setFmtType(), wrap(), and write().