Utilities¶
Defined in pigo.hpp
-
enum pigo::FileType¶
Contains the supported file types.
Values:
-
enumerator MATRIX_MARKET¶
An edge list with size, typically .mtx files
-
enumerator EDGE_LIST¶
A file where each line is an edge. This is the simplest format PIGO supports. Each line is
src dst
if it is unweighted, orsrc dst weight
if weighted.
-
enumerator GRAPH¶
A file with a head and where each line contains an adjacency list
-
enumerator AUTO¶
A special format where PIGO will try to detect the input
-
enumerator MATRIX_MARKET¶
-
enum pigo::OpenMode¶
The support PIGO file opening modes.
READ indicates read-only, whereas WRITE indicates read and write, but on opening will create a new file (removing any old file.)
Values:
-
enumerator READ¶
Indicates a read-only file
-
enumerator WRITE¶
Indicates a writeable file, existing files will be removed
-
enumerator READ¶
-
class pigo::FileReader¶
Performs actions on an opened PIGO file.
Public Functions
-
inline FileReader(FilePos d, FilePos end)¶
Initialize a new FileReader.
- Parameters
d – the current position of the reader
end – one beyond the last valid position
-
inline void skip_comments()¶
Move the reader pass any comment lines.
-
template<typename T>
inline T read_int()¶ Read an integer from the file.
Note: this reads integers in base 10 only
- Returns
the newly read integer
-
template<typename T>
inline T read_fp()¶ Read a floating point value from the file.
- Returns
the newly read floating point
-
template<typename T>
inline T read_sign()¶ Read the sign value from an integer.
Reads out either + or -, as appropriate, from the given file position. The file position is the incremented.
- Template Parameters
T – the type of the integer sign to return
- Returns
a T value of either 1 or -1 as appropriate
-
inline bool at_end_of_line()¶
Determine if only spaces remain before the line.
Note that this does not increment the current position.
- Returns
true if there are only spaces, false otherwise
-
inline void move_to_non_int()¶
Move the reader to the next non-int.
-
inline void move_to_non_fp()¶
Move the reader to the next non-floating point.
-
inline void move_to_fp()¶
Move the reader to the next floating point.
-
inline void move_to_first_int()¶
Move to the first integer.
This will move to the first found integer. If it is already on an integer, it will not move.
-
inline void move_to_next_int()¶
Move to the next integer.
Note: this will move through the current integer and then through any non-integer character to get to the next integer
-
inline void move_to_next_signed_int()¶
Move to the next signed integer.
Note: this will move through the current integer and then through any non-integer character to get to the next integer
These integers are signed and so can start with + or -
-
inline size_t count_spaces_to_eol()¶
Count the spaces in the line, moving the cursor.
-
inline void move_to_next_int_or_nl()¶
Move to the next integer or newline.
Note: this will move through the current integer or newline and then through any other character to get to the next integer or newline
-
inline void move_to_eol()¶
Move to the end of the current line.
This moves through the line and finishes on the newline character itself.
-
inline FileReader operator+(size_t s)¶
Increment the file reader by a count.
-
inline FileReader &operator+=(size_t s)¶
Increment the file reader by a count.
-
inline void smaller_end(FileReader &rhs)¶
Set an additional, smaller end.
This will either set a new end, if it is smaller than the current, or do nothing.
- Parameters
new_end – the new end to consider
-
inline bool good()¶
Return if the reader is able to read.
- Returns
true if there are values to read, false otherwise
-
inline size_t size()¶
Return the remaining size to be read.
- Returns
the number of bytes remaining
-
inline bool at_str(std::string s)¶
Check whether the reader is at the string.
- Parameters
s – the string to check against
- Returns
true if the string matches, false otherwise
-
inline char peek()¶
Return the current character of the reader.
- Returns
character the reader is at
-
inline bool at_nl_or_eol()¶
Return whether the reader is at a newline or EOL.
- Returns
true if the reader is at the end of a line, false otherwise
-
inline bool at_zero()¶
Return whether the reader is at a ‘0’ integer.
- Returns
true if the reader is at a ‘0’ integer
-
inline FileReader(FilePos d, FilePos end)¶
-
class pigo::File¶
Manages a file opened for parallel access.
Subclassed by pigo::ROFile, pigo::WFile
Public Functions
-
inline File(std::string fn, OpenMode mode, size_t max_size = 0)¶
Opens the given file.
- Parameters
fn – the file name to open
mode – the mode to open the file in (READ, WRITE)
max_size – (only used when mode=WRITE) the maximum size to allocate for the file
-
inline ~File() noexcept¶
Closes the open file and removes related memory.
-
inline void seek(size_t pos)¶
Seek to the specified offset in the file.
- Parameters
pos – the position to seek to
-
template<class T>
inline T read()¶ Read the next value from the file.
- Template Parameters
T – the type of object to read
- Returns
the resulting object
-
inline void read(const std::string &s)¶
Read passed the given string.
This will ensure that the string exists in the file and then read passed it. The file position will be at the first character after the string when it is done. An error will be throw if the string does not match.
- Parameters
s – the string to compare and read
-
template<class T>
inline void write(T val)¶ Write the given value to the file.
- Template Parameters
T – the type of object to write
- Parameters
val – the value to write
- Returns
the resulting object
-
inline void parallel_write(char *v, size_t v_size)¶
Write a binary region in parallel.
- Parameters
v – the region of data to write
v_size – the size of the region of data to write
-
inline void parallel_read(char *v, size_t v_size)¶
Read a binary region in parallel.
- Parameters
v – the region of data to save to
v_size – the size of the region of data to read
-
inline size_t size()¶
Return the size of the file.
-
inline FileType guess_file_type()¶
Auto-detect the file type.
This will determine the file type based on a mixture of the extension, the contents of the file, and investigating the structure of the lines.
Note that this is a best-guess.
- Returns
the determined FileType
-
inline FileReader reader()¶
Return a FileReader for this file.
- Returns
returns a new FileReader object for this file
-
inline File(std::string fn, OpenMode mode, size_t max_size = 0)¶
-
class pigo::ROFile : public pigo::File¶
Opens a read-only file for use in PIGO.
Public Functions
-
inline ROFile(std::string fn)¶
Opens the given file.
- Parameters
fn – the file name to open
-
inline ROFile(std::string fn)¶
-
class pigo::WFile : public pigo::File¶
Opens a writeable file for use in PIGO.
Public Functions
-
inline WFile(std::string fn, size_t max_size)¶
Opens the given file.
- Parameters
fn – the file name to open
max_size – the size to allocate for the file
-
inline WFile(std::string fn, size_t max_size)¶
-
typedef const char *pigo::FilePos¶
Keep track of the state of an open file.
-
typedef char *pigo::WFilePos¶
Keep track of the state of an open writeable file.
-
template<class T>
inline T pigo::read(FilePos &fp)¶ Read a binary value from an open file.
Reads a binary value out from the given file position. The file position object is incremented to just passed the value read out.
- Template Parameters
T – the type of object to read
- Parameters
fp – [inout] the file position object of the open file
- Returns
the value read out
-
template<class T>
inline void pigo::write(FilePos &fp, T val)¶ Write a binary value from an open file.
Writes a binary value into a file at the given position. The file position object is incremented appropriately.
- Template Parameters
T – the type of object to write
- Parameters
fp – [inout] the file position object of the open file
val – the value to write to the file
-
inline void pigo::parallel_read(FilePos &fp, char *v, size_t v_size)¶
Read a binary region in parallel.
- Parameters
fp – the FilePos to begin writing at. This will be incremented passed the read region
v – the region of data to save to
v_size – the size of the region of data to read
-
inline void pigo::parallel_write(FilePos &fp, char *v, size_t v_size)¶
Write a binary region in parallel.
- Parameters
fp – the FilePos to begin writing at. This will be incremented passed the written block
v – the region of data to write
v_size – the size of the region of data to write
-
class Error : public std::runtime_error¶
Thrown by errors detected in PIGO.
Subclassed by pigo::NotYetImplemented