• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 <core/io/intf_directory.h>
24 #include <core/io/intf_file.h>
25 #include <core/namespace.h>
26 
CORE_BEGIN_NAMESPACE()27 CORE_BEGIN_NAMESPACE()
28 /** @ingroup group_io_ifilesystem */
29 /** IFilesystem */
30 class IFilesystem {
31 public:
32     /** Get directory entry from uri
33      *  @param uri Path to file
34      *  @return IDirectory::Entry defining entry type , size and timestamp.
35      */
36     virtual IDirectory::Entry GetEntry(BASE_NS::string_view uri) = 0;
37 
38     /** Opens file from designated path
39      *  @param path Path to file
40      */
41     virtual IFile::Ptr OpenFile(BASE_NS::string_view path) = 0;
42 
43     /** Creates file to given path
44      *  @param path Path where file is created
45      */
46     virtual IFile::Ptr CreateFile(BASE_NS::string_view path) = 0;
47 
48     /** Deletes file from given path
49      *  @param path Path to file
50      */
51     virtual bool DeleteFile(BASE_NS::string_view path) = 0;
52 
53     /** Opens directory
54      *  @param path Path to directory for opening
55      */
56     virtual IDirectory::Ptr OpenDirectory(BASE_NS::string_view path) = 0;
57 
58     /** Creates a directory
59      *  @param path Path where directory is created
60      */
61     virtual IDirectory::Ptr CreateDirectory(BASE_NS::string_view path) = 0;
62 
63     /** Deletes directory from given path
64      *  @param path Path to directory
65      */
66     virtual bool DeleteDirectory(BASE_NS::string_view path) = 0;
67 
68     /** Renames file or directory from given path to another path
69      *  @param fromPath Path to file or directory to be renamed
70      *  @param toPath Path with destination name
71      */
72     virtual bool Rename(BASE_NS::string_view fromPath, BASE_NS::string_view toPath) = 0;
73 
74     /** Resolves all files which uri might be pointing to
75      *  @param uri Uri to resolve
76      */
77     virtual BASE_NS::vector<BASE_NS::string> GetUriPaths(BASE_NS::string_view uri) const = 0;
78 
79     struct Deleter {
80         constexpr Deleter() noexcept = default;
81         void operator()(IFilesystem* ptr) const
82         {
83             ptr->Destroy();
84         }
85     };
86     using Ptr = BASE_NS::unique_ptr<IFilesystem, Deleter>;
87 
88 protected:
89     IFilesystem() = default;
90     virtual ~IFilesystem() = default;
91     virtual void Destroy() = 0;
92 };
93 CORE_END_NAMESPACE()
94 
95 #endif // API_CORE_IO_IFILESYSTEM_H
96