-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfs_memory_folder.cpp
More file actions
74 lines (53 loc) · 1.97 KB
/
fs_memory_folder.cpp
File metadata and controls
74 lines (53 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "fs/impl/memory/fs_memory_folder.hpp"
#include "fs/impl/memory/fs_memory_file.hpp"
//------------------------------------------------------------------------------
namespace fs::memory {
//------------------------------------------------------------------------------
MemoryFolder::MemoryFolder( std::string_view _name )
: m_name{ _name }
{
}
//------------------------------------------------------------------------------
MemoryFolder::FolderPtr MemoryFolder::ensureSubFolder( std::string_view _name )
{
std::string name{ _name };
auto pair = m_subdirs.try_emplace( name, FolderPtr{ new MemoryFolder{ _name } } );
auto it = pair.first;
FolderPtr & folderPtr = it->second;
return folderPtr;
}
//------------------------------------------------------------------------------
MemoryFolder::FolderPtr MemoryFolder::getSubFolder( std::string_view _name ) const
{
const std::string name{ _name };
if( auto it = m_subdirs.find( name ); it != m_subdirs.end() )
return it->second;
return nullptr;
}
//------------------------------------------------------------------------------
MemoryFolder::FilePtr MemoryFolder::ensureFile( std::string_view _name )
{
std::string name{ _name };
auto pair = m_files.try_emplace( name, FilePtr{ new MemoryFile{} } );
auto it = pair.first;
FilePtr & filePtr = it->second;
return filePtr;
}
//------------------------------------------------------------------------------
MemoryFolder::FilePtr MemoryFolder::getFile( std::string_view _name ) const
{
const std::string name{ _name };
if( auto it = m_files.find( name ); it != m_files.end() )
return it->second;
return nullptr;
}
//------------------------------------------------------------------------------
void MemoryFolder::forEachItem( ItemCallback _callback )
{
for( auto it : m_subdirs )
_callback( it.first, ItemType::Folder );
for( auto it : m_files )
_callback( it.first, ItemType::File );
}
//------------------------------------------------------------------------------
}