• 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 CORE__IO__STD_FILESYSTEM_H
17 #define CORE__IO__STD_FILESYSTEM_H
18 
19 #include <core/io/intf_file_system.h>
20 #include <core/namespace.h>
21 
CORE_BEGIN_NAMESPACE()22 CORE_BEGIN_NAMESPACE()
23 /** File protocol.
24  * Protocol implementation that wraps standard file i/o.
25  */
26 class StdFilesystem final : public IFilesystem {
27 public:
28     // base path must be absolute, start with a "/" and on windows contain the drive letter "c:".
29     // and should end on a "/". must use a "/" as directory separator.
30     explicit StdFilesystem(BASE_NS::string_view basePath);
31     ~StdFilesystem() override = default;
32     StdFilesystem(StdFilesystem const&) = delete;
33     StdFilesystem& operator=(StdFilesystem const&) = delete;
34 
35     // All uris should be absolute, and are considered such. (should start with "/")
36     IDirectory::Entry GetEntry(BASE_NS::string_view uri) override;
37     IFile::Ptr OpenFile(BASE_NS::string_view path) override;
38     IFile::Ptr CreateFile(BASE_NS::string_view path) override;
39     bool DeleteFile(BASE_NS::string_view path) override;
40 
41     IDirectory::Ptr OpenDirectory(BASE_NS::string_view path) override;
42     IDirectory::Ptr CreateDirectory(BASE_NS::string_view path) override;
43     bool DeleteDirectory(BASE_NS::string_view path) override;
44 
45     bool Rename(BASE_NS::string_view fromPath, BASE_NS::string_view toPath) override;
46 
47     BASE_NS::vector<BASE_NS::string> GetUriPaths(BASE_NS::string_view uri) const override;
48 
49 protected:
50     BASE_NS::string ValidatePath(BASE_NS::string_view path) const;
51     void Destroy() override
52     {
53         delete this;
54     }
55     BASE_NS::string basePath_;
56 };
57 CORE_END_NAMESPACE()
58 
59 #endif // CORE__IO__STD_FILESYSTEM_H
60