public

Description

Utility class with functions for file reading and writing.

Note: initFSProvider() is called by Util::init()

File System Provider

   
   
bool registerFSProvider(const std::string & fsName, std::function< AbstractFSProvider *()> providerCreator)

Streamed reading and writing

   
   
std::unique_ptr< std::iostream > open(const FileName & fileName)
Return an input and output stream (or nullptr on failure) for reading from and writing to a file.
   
std::unique_ptr< std::istream > openForReading(const FileName & fileName)
Return an input stream (or nullptr on failure) for reading from a file.
   
std::unique_ptr< std::ostream > openForWriting(const FileName & fileName)
   
std::unique_ptr< std::ostream > openForAppending(const FileName & fileName)

Loading and saving complete files

   
   
std::vector< uint8_t > loadFile(const FileName & filename)
   
std::string getFileContents(const FileName & filename)
   
std::string getParsedFileContents(const FileName & filename)
   
bool saveFile(const FileName & filename, const std::vector< uint8_t > & data, bool overwrite)

Information

   
   
const uint8_t DIR_FILES
flag for dir(…)
   
const uint8_t DIR_DIRECTORIES
flag for dir(…)
   
const uint8_t DIR_RECURSIVE
flag for dir(…)
   
const uint8_t DIR_HIDDEN_FILES
flag for dir(…)
   
bool isFile(const FileName & filename)
   
bool isDir(const FileName & filename)
   
size_t fileSize(const FileName & filename)
   
bool findFile(const FileName & fileName, const std::vector< std::string > & pathHints, FileName & newName)
   
bool dir(const FileName & path, std::list< FileName > & result, uint8_t flags)
   
bool makeRelativeIfPossible(const FileName & fixedPath, FileName & path)

Misc

   
   
bool createDir(const FileName & name, bool recursive)
   
bool remove(const FileName & name, bool recursive)
   
FileName generateNewRandFilename(const FileName & dir, const std::string & prefix, const std::string & postfix, int randomSize)
   
bool copyFile(const FileName & source, const FileName & dest)
   
void flush(const FileName & path)

Documentation

function
Util::FileUtils::registerFSProvider

public static
     
     
bool registerFSProvider( const std::string & fsName,
  std::function< AbstractFSProvider *()> providerCreator
)    

Registers an additional file system provider for the given fsName. Files of the type “fsName://foo.bar” are than handled by that provider

Defined in Util/IO/FileUtils.h:38


function
Util::FileUtils::open

public static
     
     
std::unique_ptr< std::iostream > open( const FileName & fileName )

Return an input and output stream (or nullptr on failure) for reading from and writing to a file.

Defined in Util/IO/FileUtils.h:50


function
Util::FileUtils::openForReading

public static
     
     
std::unique_ptr< std::istream > openForReading( const FileName & fileName )

Return an input stream (or nullptr on failure) for reading from a file.

Defined in Util/IO/FileUtils.h:52


function
Util::FileUtils::openForWriting

public static
     
     
std::unique_ptr< std::ostream > openForWriting( const FileName & fileName )

Return an output stream (or nullptr on failure) for writing to a file. The file is truncated: Any current content is discarded, assuming a length of zero on opening.

Defined in Util/IO/FileUtils.h:57


function
Util::FileUtils::openForAppending

public static
     
     
std::unique_ptr< std::ostream > openForAppending( const FileName & fileName )

Return an output stream (or nullptr on failure) for appending to a file. The stream’s position indicator is set to the end of the stream before.

Defined in Util/IO/FileUtils.h:62


function
Util::FileUtils::loadFile

public static
     
     
std::vector< uint8_t > loadFile( const FileName & filename )

Defined in Util/IO/FileUtils.h:69


function
Util::FileUtils::getFileContents

public static
     
     
std::string getFileContents( const FileName & filename )

Defined in Util/IO/FileUtils.h:70


function
Util::FileUtils::getParsedFileContents

public static
     
     
std::string getParsedFileContents( const FileName & filename )

Defined in Util/IO/FileUtils.h:71


function
Util::FileUtils::saveFile

public static
     
     
bool saveFile( const FileName & filename,
  const std::vector< uint8_t > & data,
  bool overwrite
)    

Defined in Util/IO/FileUtils.h:73


variable
Util::FileUtils::DIR_FILES

public static
 
 
const uint8_t DIR_FILES

flag for dir(…)

Defined in Util/IO/FileUtils.h:94


variable
Util::FileUtils::DIR_DIRECTORIES

public static
 
 
const uint8_t DIR_DIRECTORIES

flag for dir(…)

Defined in Util/IO/FileUtils.h:95


variable
Util::FileUtils::DIR_RECURSIVE

public static
 
 
const uint8_t DIR_RECURSIVE

flag for dir(…)

Defined in Util/IO/FileUtils.h:96


variable
Util::FileUtils::DIR_HIDDEN_FILES

public static
 
 
const uint8_t DIR_HIDDEN_FILES

flag for dir(…)

Defined in Util/IO/FileUtils.h:97


function
Util::FileUtils::isFile

public static
     
     
bool isFile( const FileName & filename )

Defined in Util/IO/FileUtils.h:80


function
Util::FileUtils::isDir

public static
     
     
bool isDir( const FileName & filename )

Defined in Util/IO/FileUtils.h:81


function
Util::FileUtils::fileSize

public static
     
     
size_t fileSize( const FileName & filename )

Defined in Util/IO/FileUtils.h:82


function
Util::FileUtils::findFile

public static
     
     
bool findFile( const FileName & fileName,
  const std::vector< std::string > & pathHints,
  FileName & newName
)    

Search a file in different paths. The paths are checked absolute and relative to the originating file path.

Parameters

fileName
File name to search.
pathHints
List of paths, which are searched for the file.
newName
New file name in the case the file was found.

Returns

trueif the file was found andfalseotherwise.

Defined in Util/IO/FileUtils.h:92


function
Util::FileUtils::dir

public static
     
     
bool dir( const FileName & path,
  std::list< FileName > & result,
  uint8_t flags
)    

Get files and directories in the given directory (path). The resulting filenames are inserted intoresults. The type of entries is determined byflags. DIR_RECURSIVE searches recursive in all subdirectories.

Note: Only the provider and directory part ofpathis taken; you can create an appropriate Directory-FileName with FileName::createDirName (…)

Defined in Util/IO/FileUtils.h:103


function
Util::FileUtils::makeRelativeIfPossible

public static
     
     
bool makeRelativeIfPossible( const FileName & fixedPath,
  FileName & path
)    

Try to make the givenpathrelative to the givenfixedPath. If the directory ofpath(or the directory to the container in path) begins with the directory offixedPath(or the directory to the container in fixedPath), the directory entry is truncated accordingly.

Returns

true iff the path could be changed

Note: Example:

fixedPath:          "file://./data/scene/Szene_1.minsg"
        path:               "file://./data/scene/../model/tree1.ply"
    dir of the path begins with the dir of the fixedPath ---> make it relative
        resulting path:     "file://../model/tree1.ply"

Note: Example:

fixedPath:          "file://./a/b/c/Szene_1.minsg"
        path:               "zip://./a/b/c/d/Foo.zip$./tree1.ply"
    dir of the path begins with the dir of the fixedPath ---> make it relative
        resulting path:     "zip://d/Foo.zip$./tree1.ply"

Defined in Util/IO/FileUtils.h:126


function
Util::FileUtils::createDir

public static
     
     
bool createDir( const FileName & name,
  bool recursive
)    

Defined in Util/IO/FileUtils.h:134


function
Util::FileUtils::remove

public static
     
     
bool remove( const FileName & name,
  bool recursive
)    

Defined in Util/IO/FileUtils.h:135


function
Util::FileUtils::generateNewRandFilename

public static
     
     
FileName generateNewRandFilename( const FileName & dir,
  const std::string & prefix,
  const std::string & postfix,
  int randomSize
)    

Defined in Util/IO/FileUtils.h:137


function
Util::FileUtils::copyFile

public static
     
     
bool copyFile( const FileName & source,
  const FileName & dest
)    

Copy the file with pathsourceto the file with pathdest. If the destination file already exists, it will be overwritten.

Parameters

source
Path to source file
dest
Path to destination file

Returns

trueif successful,falseotherwise

Defined in Util/IO/FileUtils.h:148


function
Util::FileUtils::flush

public static
     
     
void flush( const FileName & path )

Make sure that any pending data will be written to its destination.

Parameters

path
Path that will be used to determine the correct data to be flushed. It is enough if it contains a file system name, e.g. “zip://”, “file://”.

Defined in Util/IO/FileUtils.h:156