RobWorkProject  23.9.11-
Static Public Member Functions | List of all members
IOUtil Class Reference

Collection of IO related utilities. More...

#include <IOUtil.hpp>

Static Public Member Functions

static void readFile (const std::string &file_name, std::vector< char > &result)
 Read the contents of a file. More...
 
static std::string resolveFileName (const std::string &filename, const std::vector< std::string > &extensions)
 Attach to filename the proper extension. More...
 
static void rwAssert (const char *expression, const char *file, int line)
 Emit an assertion message and kill the program. More...
 
static std::string getAbsoluteFileName (const std::string &file)
 returns the absolute filename of file. If file is absolute filename then file is returned. If not, then working directory path is appended to file. More...
 
static bool isLittleEndian ()
 tests if this machine use little or big endian. More...
 
static std::vector< std::string > getFilesInFolder (const std::string &path, bool recursive, bool addPath=true, const std::string &mask="*")
 Returns files in the folder specified by path. More...
 
static void getFilesInFolder (const std::string &path, const std::string &fileMask, bool recursive, bool addPath, std::vector< std::string > &result)
 get all files in a folder More...
 
static size_t getFileSize (const std::string &filename)
 get size of file More...
 
static std::time_t getLastFileWrite (const std::string &filename)
 get the last date of writing of the file filename More...
 
static std::string getFirstXMLElement (const std::string &filename)
 extracts the first element tag in any xml document. More...
 
static std::string getFirstXMLElement (std::istream &inputStream)
 extracts the first element tag in any xml document. More...
 

Detailed Description

Collection of IO related utilities.

Member Function Documentation

◆ getAbsoluteFileName()

static std::string getAbsoluteFileName ( const std::string &  file)
static

returns the absolute filename of file. If file is absolute filename then file is returned. If not, then working directory path is appended to file.

Parameters
file[in] the relative or absolute filename

◆ getFilesInFolder() [1/2]

static std::vector<std::string> getFilesInFolder ( const std::string &  path,
bool  recursive,
bool  addPath = true,
const std::string &  mask = "*" 
)
static

Returns files in the folder specified by path.

Throws rw::core::Exception if unable to obtain file names.

Parameters
path[in] Path to search in
recursive[in] if true files in subfolders are also added
addPath[in] If true both path and filenames are returned. Otherwise only the filenames are returned.
mask[in] Mask to filter filenames. Example: "*.dll" to return all DLL files.
Returns
Files located at path.

◆ getFilesInFolder() [2/2]

static void getFilesInFolder ( const std::string &  path,
const std::string &  fileMask,
bool  recursive,
bool  addPath,
std::vector< std::string > &  result 
)
static

get all files in a folder

Parameters
path[in] folder path
fileMask[in] file mask. Example: "*.dll" to return all DLL files.
recursive[in] if true files in subfolders are also added
addPath[in] if true then folder paths are added to solution
result[out] all files and if addPath

◆ getFileSize()

static size_t getFileSize ( const std::string &  filename)
static

get size of file

Parameters
filename[in] name of file
Returns
the size of file in bytes

◆ getFirstXMLElement() [1/2]

static std::string getFirstXMLElement ( const std::string &  filename)
static

extracts the first element tag in any xml document.

throws if not xml document or file cannot be openned

Parameters
filename[in] name of the xml file
Returns
name of first xml element

◆ getFirstXMLElement() [2/2]

static std::string getFirstXMLElement ( std::istream &  inputStream)
static

extracts the first element tag in any xml document.

throws if not xml document

Parameters
inputStream[in] ifstream containing the xml document
Returns
name of first xml element

◆ getLastFileWrite()

static std::time_t getLastFileWrite ( const std::string &  filename)
static

get the last date of writing of the file filename

Parameters
filename[in] name of file
Returns
time of modification

◆ isLittleEndian()

static bool isLittleEndian ( )
static

tests if this machine use little or big endian.

Returns
true if machine

◆ readFile()

static void readFile ( const std::string &  file_name,
std::vector< char > &  result 
)
static

Read the contents of a file.

The contents of the file file_name are read into the buffer result. The result buffer is resized to match the length of the input.

Files can be lengthy which is why the result is returned via the result parameter (an alternative would be to return a smart pointer to a vector).

An exception is thrown if the file can't be opened or can't be read.

Parameters
file_name[in] The name of the file.
result[out] Buffer to which the file contents are written.

◆ resolveFileName()

static std::string resolveFileName ( const std::string &  filename,
const std::vector< std::string > &  extensions 
)
static

Attach to filename the proper extension.

Find the the suffix of extensions that when appended to filename yields the file name for readable file.

For suffix of extensions, lower case and upper case versions of this suffix are also considered.

The file name filename as is with nothing prepended at all is considered as the first thing.

If filename can't be resolved to a readable file, an informative error message is thrown.

Parameters
filename[in] The file name to resolve.
extensions[in] The sequence of file name suffixes.
Returns
The filename with extension

◆ rwAssert()

static void rwAssert ( const char *  expression,
const char *  file,
int  line 
)
static

Emit an assertion message and kill the program.

rwAssert() is called by the RW_ASSERT() macro.

rwAssert() is for internal use only.

Parameters
expression[in] The thing that wasn't true.
file[in] The originating file name.
line[in] The originating line number.

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