ArmNN
 22.11
armnnUtils::Filesystem Namespace Reference

Typedefs

using FileContents = std::string
 

Functions

fs::path NamedTempFile (const char *fileName)
 Returns a path to a file in the system temporary folder. If the file existed it will be deleted. More...
 
std::string CreateDirectory (std::string sPath)
 Returns full path to temporary folder. More...
 
FileContents ReadFileContentsIntoString (const std::string path)
 

Typedef Documentation

◆ FileContents

using FileContents = std::string

Definition at line 22 of file Filesystem.hpp.

Function Documentation

◆ CreateDirectory()

std::string CreateDirectory ( std::string  path)

Returns full path to temporary folder.

Construct a temporary directory.

Given a specified directory name construct a path in the system temporary directory. If the directory already exists, it is deleted, otherwise create it. This could throw filesystem_error exceptions.

Parameters
pathis the path required in the temporary directory.
Returns
path consisting of system temporary directory.

Definition at line 46 of file Filesystem.cpp.

Referenced by armnn::Optimize().

47 {
48  fs::path tmpDir = fs::temp_directory_path();
49  mode_t permissions = 0733;
50  int result = 0;
51 
52  std::string full_path = tmpDir.generic_string() + path;
53  if (fs::exists(full_path))
54  {
55  fs::remove_all(full_path);
56  }
57 
58 #if defined(_WIN32)
59  result = _mkdir(full_path.c_str()); // can be used on Windows
60  armnn::ConditionalThrow<armnn::RuntimeException>((result == 0), "Was unable to create temporary directory");
61 #else
62  result = mkdir(full_path.c_str(), permissions);
63  armnn::ConditionalThrow<armnn::RuntimeException>((result == 0), "Was unable to create temporary directory");
64 #endif
65 
66  return full_path + "/";
67 }

◆ NamedTempFile()

fs::path NamedTempFile ( const char *  fileName)

Returns a path to a file in the system temporary folder. If the file existed it will be deleted.

Construct a temporary file name.

Given a specified file name construct a path to that file in the system temporary directory. If the file already exists it is deleted. This could throw filesystem_error exceptions.

Parameters
fileNamethe file name required in the temporary directory.
Returns
path consisting of system temporary directory and file name.

Definition at line 25 of file Filesystem.cpp.

Referenced by TEST_SUITE().

26 {
27  fs::path tmpDir = fs::temp_directory_path();
28  fs::path namedTempFile{tmpDir / fileName};
29  if (fs::exists(namedTempFile))
30  {
31  fs::remove(namedTempFile);
32  }
33  return namedTempFile;
34 }

◆ ReadFileContentsIntoString()

FileContents ReadFileContentsIntoString ( const std::string  path)

Definition at line 69 of file Filesystem.cpp.

69  {
70  std::ifstream input_file(path);
71  armnn::ConditionalThrow<armnn::RuntimeException>((input_file.is_open()), "Could not read file contents");
72  return FileContents((std::istreambuf_iterator<char>(input_file)), std::istreambuf_iterator<char>());
73 }
std::string FileContents
Definition: Filesystem.hpp:22