From ae050524109f1ce827962665436ef7430f2ac479 Mon Sep 17 00:00:00 2001 From: David Monahan Date: Wed, 22 Mar 2023 16:48:58 +0000 Subject: IVGCVSW-7255 Update Doxygen Documentation and publish on GitHub. * Updating Doxygen documentation for 23.02 release. Signed-off-by: David Monahan Change-Id: I545574ff7664b4595d2fe6a91a3c35d2ad55df82 --- latest/_filesystem_8cpp_source.xhtml | 226 +++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 latest/_filesystem_8cpp_source.xhtml (limited to 'latest/_filesystem_8cpp_source.xhtml') diff --git a/latest/_filesystem_8cpp_source.xhtml b/latest/_filesystem_8cpp_source.xhtml new file mode 100644 index 0000000000..3820813733 --- /dev/null +++ b/latest/_filesystem_8cpp_source.xhtml @@ -0,0 +1,226 @@ + + + + + + + + + + + + + +ArmNN: src/armnnUtils/Filesystem.cpp Source File + + + + + + + + + + + + + + + + +
+
+ + + + ArmNN + + + +
+
+  23.02 +
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+
+
Filesystem.cpp
+
+
+Go to the documentation of this file.
1 //
+
2 // Copyright © 2020,2023 Arm Ltd and Contributors. All rights reserved.
+
3 // SPDX-License-Identifier: MIT
+
4 //
+
5 #if !defined(ARMNN_DISABLE_FILESYSTEM)
+
6 
+
7 #include <armnn/Exceptions.hpp>
+ +
9 
+
10 namespace armnnUtils
+
11 {
+
12 namespace Filesystem
+
13 {
+
14 
+
15 /**
+
16  * @brief Construct a temporary file name.
+
17  *
+
18  * Given a specified file name construct a path to that file in the
+
19  * system temporary directory. If the file already exists it is deleted. This
+
20  * could throw filesystem_error exceptions.
+
21  *
+
22  * @param fileName the file name required in the temporary directory.
+
23  * @return path consisting of system temporary directory and file name.
+
24  */
+
25 fs::path NamedTempFile(const char* fileName)
+
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 }
+
35 
+
36 /**
+
37  * @brief Construct a temporary directory
+
38  *
+
39  * Given a specified directory name construct a path in the
+
40  * system temporary directory. If the directory already exists, it is deleted,
+
41  * otherwise create it. This could throw filesystem_error exceptions.
+
42  *
+
43  * @param path is the path required in the temporary directory.
+
44  * @return path consisting of system temporary directory.
+
45  * @throws RuntimeException if the directory cannot be created or exists but cannot be removed.
+
46  */
+
47 std::string CreateDirectory(std::string path)
+
48 {
+
49  // This line is very unlikely to throw an exception.
+
50  fs::path tmpDir = fs::temp_directory_path();
+
51  std::string full_path = tmpDir.generic_string() + path;
+
52  if (fs::exists(full_path))
+
53  {
+
54  try
+
55  {
+
56  // This could throw an exception on a multi-user system.
+
57  fs::remove_all(full_path);
+
58  }
+
59  catch (const std::system_error& e)
+
60  {
+
61  std::string error = "Directory exists and cannot be removed. Reason: ";
+
62  error.append(e.what());
+ +
64  }
+
65  }
+
66 #if defined(_WIN32)
+
67  result = _mkdir(full_path.c_str()); // can be used on Windows
+
68  armnn::ConditionalThrow<armnn::RuntimeException>((result == 0), "Was unable to create temporary directory");
+
69 #else
+
70  try
+
71  {
+
72  if(!fs::create_directory(full_path))
+
73  {
+
74  throw armnn::RuntimeException("Unable to create directory: " + full_path);
+
75  }
+
76  }
+
77  catch (const std::system_error& e)
+
78  {
+
79  std::string error = "Unable to create directory. Reason: ";
+
80  error.append(e.what());
+ +
82  }
+
83 #endif
+
84 
+
85  return full_path + "/";
+
86 }
+
87 
+
88 FileContents ReadFileContentsIntoString(const std::string path) {
+
89  if (!fs::exists(path))
+
90  {
+
91  throw armnn::RuntimeException("Path does not exist: " + path);
+
92  }
+
93  std::ifstream input_file(path);
+
94  armnn::ConditionalThrow<armnn::RuntimeException>((input_file.is_open()), "Could not read file contents");
+
95  return FileContents((std::istreambuf_iterator<char>(input_file)), std::istreambuf_iterator<char>());
+
96 }
+
97 
+
98 } // namespace armnnUtils
+
99 } // namespace Filesystem
+
100 
+
101 #endif // !defined(ARMNN_DISABLE_FILESYSTEM)
+
+
+
std::string CreateDirectory(std::string sPath)
Returns full path to temporary folder.
Definition: Filesystem.cpp:47
+
FileContents ReadFileContentsIntoString(const std::string path)
Definition: Filesystem.cpp:88
+ + +
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.
Definition: Filesystem.cpp:25
+ + +
std::string FileContents
Definition: Filesystem.hpp:24
+ + + + + -- cgit v1.2.1