Go to the documentation of this file.
130 PwpFile(FILE *
fp = 0, std::string filename = std::string(),
int mode = 0);
141 PwpFile(std::string filename,
int mode);
165 bool wrap(FILE *
fp, std::string filename = std::string(),
int mode = 0);
177 bool open(std::string filename,
int mode);
272 bool checkUnformatted(
bool &swapped, std::vector<PWP_INT64> *pRecSizes = 0)
const;
347 void setName(std::string filename);
362 bool read(
void *buf,
size_t size,
size_t count);
402 bool readUntil(std::string &str,
const int stopC,
int maxLen = 0,
403 const bool doTrim =
false);
414 const char stopTok[2]{ stopC,
'\0' };
428 inline bool readUntilTrim(std::string &str,
const int stopC,
int maxLen=0) {
429 return readUntil(str, stopC, maxLen,
true); }
487 template<
typename T >
501 template<
typename T >
504 const bool ret =
read(&val,
sizeof(T), 1);
517 template<
typename T >
521 if (1 == fread(&result,
sizeof(T), 1,
fp_)) {
538 template<
typename T >
588 char *cbuf = (
char*)buf;
590 size_t tNdx = size - 1;
591 while (hNdx < tNdx) {
592 const char tmp = cbuf[hNdx];
593 cbuf[hNdx++] = cbuf[tNdx];
617 return readInt(v, 8, maxDigits); }
629 return readInt(v, 16, maxDigits); }
637 return ::fgetc(
fp_); }
646 return EOF != (c = ::fgetc(
fp_)); }
675 return readToken(fileTok) && (tok == fileTok); }
686 return ::fgetc(
fp_) == nextC; }
698 theC = char(::fgetc(
fp_));
699 if (
nullptr == stopCs) {
702 const char *stopCsEnd = stopCs + strlen(stopCs);
703 return stopCsEnd != std::find(stopCs, stopCsEnd, theC); }
732 inline static std::string &
736 s.erase(s.begin(), std::find_if(s.begin(), s.end(),
737 [](std::string::value_type i) {
738 return 0 == std::isspace(i);
745 inline static std::string &
749 s.erase(std::find_if(s.rbegin(), s.rend(),
750 [](std::string::value_type i) {
751 return 0 == std::isspace(i);
758 inline static std::string &
767 inline FILE *
fp()
const {
773 inline operator FILE*()
const {
802 static bool unlink(
const char *filename);
844 template<
typename T >
846 const char * prefix = 0);
867 template<
typename T >
880 sizeof(T)),
sizeof(T), 1,
fp_));
883 ret =
write(val, suffix, prefix);
885 return ret &&
setPos(curPos);
970 template<
typename T >
972 const char * prefix = 0) {
990 #endif // _PWPFILE_H_
bool readUntil(PWP_UINT32 &v, const char stopC)
Reads a stopC terminated PWP_UINT32 value.
bool setIntPos(const PWP_INT64 &pos)
Set the current file position.
bool setPos(const sysFILEPOS &pos)
Set the current file position.
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.
static std::string & rtrim(std::string &s)
trim trailing whitespace from s
PWU_UNFDATA ud_
The file's unformatted data stats.
bool readAlphaTokenIs(const char *tok)
Read and compare an alpha token.
bool readToken(std::string &tok)
Reads a whitespace delimited token (word).
bool isEof() const
Get the end-of-file status.
bool getPos(sysFILEPOS &pos) const
Get the current file position of this record's file object.
virtual ~PwpFile()
Destructor.
bool isWritable() const
Determines if file supports write operations.
PWP_ENDIANNESS byteOrder_
The file's byte order.
bool isOpen() const
Determines a file's status.
bool readOptionalInt(PWP_UINT32 &v, const PWP_UINT32 defV, const PWP_UINT32 base=10, PWP_UINT32 maxDigits=0)
Reads a single PWP_UINT32 value.
bool fileEof() const
Check for the end of file.
static PWP_ENDIANNESS getOsByteOrder()
Get the OS's native byte ordering.
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.
PwpFileRecord(PwpFile &file, bool doBeginRecord=true)
Constructor.
static std::string & trim(std::string &s)
trim leading and trailing whitespace from s
const char * getName() const
Get the file's associated filename.
Manages FORTRAN unformatted file records.
bool readOctal(PWP_UINT32 &v, PWP_UINT32 maxDigits=0)
Reads a single PWP_UINT32 octal value.
bool read(void *buf, size_t size, size_t count)
Read a collection of data items.
static const void * swapByteOrder(void *buf, size_t size)
Performs an inplace byte swapping.
PWP_ENUM_PRECISION getPrecision() const
Get the floating point precision used for writes.
bool needByteSwap() const
Determine if byte swapping is needed for this file.
int getc()
Reads a single byte value.
bool isUnformatted() const
Determines if file was opened with pwpUnformatted mode flag.
bool getPos(sysFILEPOS &pos) const
Get the current file position.
bool readSwap(T &val, const bool swapbyte)
Reads a single value of type T.
bool isReadable() const
Determines if file supports read operations.
static void swap(T &val)
swap() - (Importer-only function) Wrapper for function swapByteOrder().
bool ungetc(const int c)
Return a byte value to the file.
bool checkUnformatted(bool &swapped, std::vector< PWP_INT64 > *pRecSizes=0) const
Determines unformatted type settings by reading the contents of the file.
FILE * fp() const
Get the FILE pointer.
const PwpFile & file() const
Get this record's file object.
bool wrap(FILE *fp, std::string filename=std::string(), int mode=0)
Take ownership of fp opened using pwpFileOpen(filename, mode).
bool readAlphaToken(std::string &tok)
Reads a whitespace delimited token (word).
FILE * fp_
The FILE pointer.
bool readTokenIs(const char *tok)
Read and compare a token.
bool wspaceSkipToEOF()
Skip whitespace and read until EOF.
virtual ~PwpFileRecord()
Destructor.
bool readVal(T &v, const PWP_UINT32 base=10)
Reads a single value of type T.
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.
void setName(std::string filename)
Set the file's associated filename.
PwpFileRecord & operator=(const PwpFileRecord &)
bool wspaceSkipToChar(const int nextC)
Skip whitespace and read the next char.
bool wspaceSkip()
Reads and discards consecutive whitespace bytes.
PwpFileWriter * writer_
The file writer implementation.
PwpFile(FILE *fp=0, std::string filename=std::string(), int mode=0)
Default constructor.
bool wspaceSkipToOneOf(const char *stopCs, char &theC)
Skip whitespace and read the next char returning it in theC.
The abstract PwpFileWriter class.
bool isSingle() const
Determines if floating point precision is PWP_PRECISION_SINGLE.
bool flush()
Flush file to disk.
virtual bool write(PWP_INT64 val, const char *suffix=0, const char *prefix=0)
Writes a integer value with proper encoding and byte order.
PWP_ENDIANNESS
Flags used to indicate endianness or control endian behaviors in functions.
PwpFile & operator=(const PwpFile &ref)
Assignment operator Does not copy the file position or unformatted data.
PWP_ENDIANNESS setByteOrder(PWP_ENDIANNESS order)
Set the byte order used for writes.
bool getSize(PWP_UINT64 &size) const
Get the size of the file managed by this object.
PWP_ENUM_PRECISION setPrecision(PWP_ENUM_PRECISION precision)
Set the floating point precision used for writes.
bool readHex(PWP_UINT32 &v, PWP_UINT32 maxDigits=0)
Reads a single PWP_UINT32 hex value.
bool isDouble() const
Determines if floating point precision is PWP_PRECISION_DOUBLE.
static PWP_ENDIANNESS mapToBigLittle(PWP_ENDIANNESS byteOrder)
Map a byte ordering value to PWP_ENDIAN_BIG or PWP_ENDIAN_LITTLE based on getOsByteOrder().
const PWU_UNFDATA & unfData() const
Get the file's unformatted data buffer.
bool readVal(T *v, const PWP_UINT32 cnt, const PWP_UINT32 base=10)
Reads an array of cnt values of type T.
bool skipToChar(const int nextC)
Skip all chars up to and including nextC.
PWP_INT64 getPos() const
Get the current file position.
bool readUntilTrim(std::string &str, const int stopC, int maxLen=0)
Reads up to maxLen chars until the specified stop char is encountered.
bool isAscii() const
Determines if file was opened with either the pwpAscii or pwpFormatted mode flag.
#define PwpWriterInterface_SUBCLASS
PWU_UNFDATA & unfData()
Get the file's unformatted data buffer.
const void * PwuApplyEndianness(PWP_ENDIANNESS endianness, const void *buf, size_t size)
Apply specified byte order to buf containing size bytes.
bool close()
Explicitly close the file object.
bool isBinary() const
Determines if file was opened with pwpBinary mode flag.
PWP_ENDIANNESS getByteOrder(bool mapBigLittle=false) const
Get the byte order used for writes.
bool readInt(PWP_UINT32 &v, const PWP_UINT32 base=10, PWP_UINT32 maxDigits=0)
Reads a single PWP_UINT32 value.
Data and functions useful to PWP-API compliant plugins.
static bool unlink(const char *filename)
Delete a file.
std::string filename_
The file name.
static std::string & ltrim(std::string &s)
trim leading whitespace from s
PWP_ENUM_PRECISION precision_
The file's floating point precision.
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.
bool open(std::string filename, int mode)
Opens a file with the given filename and mode.
bool readDouble(PWP_REAL &v, PWP_UINT32 maxDigits=0)
Reads a single PWP_REAL value.
bool getcNotEOF(int &c)
Reads a single byte value.
PwpFile & file()
Get this record's file object.
T readSwap(const bool swapbyte)
Reads a single value of type T.
PWP_ENUM_PRECISION
File precision values.
bool rewind()
Reset position to the beginning of the file.
Unformatted file data block.
bool checkAscii() const
Determines whether the file is Ascii by reading the contents of the file.
The abstract PwpWriterInterface class.