• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef API_CORE_IO_IFILESYSTEM_H
17 #define API_CORE_IO_IFILESYSTEM_H
18 
19 #include <base/containers/string.h>
20 #include <base/containers/string_view.h>
21 #include <base/containers/unique_ptr.h>
22 #include <base/containers/vector.h>
23 #include <base/namespace.h>
24 #include <core/io/intf_directory.h>
25 #include <core/io/intf_file.h>
26 #include <core/namespace.h>
27 
CORE_BEGIN_NAMESPACE()28 CORE_BEGIN_NAMESPACE()
29 /** @ingroup group_io_ifilesystem */
30 /** IFilesystem */
31 class IFilesystem {
32 public:
33     /** Get directory entry from uri
34      *  @param uri Path to file
35      *  @return IDirectory::Entry defining entry type , size and timestamp.
36      */
37     virtual IDirectory::Entry GetEntry(BASE_NS::string_view uri) = 0;
38 
39     /** Opens file from designated path
40      *  @param path Path to file
41      *  @param mode Access mode
42      */
43     virtual IFile::Ptr OpenFile(BASE_NS::string_view path, IFile::Mode mode) = 0;
44 
45     /** Creates file to given path
46      *  @param path Path where file is created
47      */
48     virtual IFile::Ptr CreateFile(BASE_NS::string_view path) = 0;
49 
50     /** Deletes file from given path
51      *  @param path Path to file
52      */
53     virtual bool DeleteFile(BASE_NS::string_view path) = 0;
54 
55     /** Check if file exists.
56      *  @param Path to file
57      *  @return True if the file exists, otherwise false.
58      */
59     virtual bool FileExists(BASE_NS::string_view path) const = 0;
60 
61     /** Opens directory
62      *  @param path Path to directory for opening
63      */
64     virtual IDirectory::Ptr OpenDirectory(BASE_NS::string_view path) = 0;
65 
66     /** Creates a directory
67      *  @param path Path where directory is created
68      */
69     virtual IDirectory::Ptr CreateDirectory(BASE_NS::string_view path) = 0;
70 
71     /** Deletes directory from given path
72      *  @param path Path to directory
73      */
74     virtual bool DeleteDirectory(BASE_NS::string_view path) = 0;
75 
76     /** Check if directory exists.
77      *  @param path Path to directory
78      *  @return True if directory exists, otherwise false.
79      */
80     virtual bool DirectoryExists(BASE_NS::string_view path) const = 0;
81 
82     /** Renames file or directory from given path to another path
83      *  @param fromPath Path to file or directory to be renamed
84      *  @param toPath Path with destination name
85      */
86     virtual bool Rename(BASE_NS::string_view fromPath, BASE_NS::string_view toPath) = 0;
87 
88     /** Resolves all files which uri might be pointing to
89      *  @param uri Uri to resolve
90      */
91     virtual BASE_NS::vector<BASE_NS::string> GetUriPaths(BASE_NS::string_view uri) const = 0;
92 
93     struct Deleter {
94         constexpr Deleter() noexcept = default;
95         void operator()(IFilesystem* ptr) const
96         {
97             ptr->Destroy();
98         }
99     };
100     using Ptr = BASE_NS::unique_ptr<IFilesystem, Deleter>;
101 
102 protected:
103     IFilesystem() = default;
104     virtual ~IFilesystem() = default;
105     virtual void Destroy() = 0;
106 };
107 CORE_END_NAMESPACE()
108 
109 #endif // API_CORE_IO_IFILESYSTEM_H
110