-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathItem.cpp
More file actions
72 lines (54 loc) · 1.46 KB
/
Item.cpp
File metadata and controls
72 lines (54 loc) · 1.46 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
#include "Item.hpp"
#include <boost/filesystem.hpp>
namespace bfs = boost::filesystem;
namespace sequenceParser {
std::string Item::getAbsoluteFirstFilename() const
{
if( getType() == eTypeSequence )
return (_path.parent_path() / getSequence().getFirstFilename()).string();
return getAbsoluteFilepath();
}
std::vector<Item> Item::explode() const{
std::vector<Item> outItems;
if(_type != eTypeSequence){
outItems.push_back(*this);
return outItems;
}
const std::vector<boost::filesystem::path>& seqFilesPath = getSequence().getAbsoluteFilesPath(_path.parent_path());
BOOST_FOREACH(const boost::filesystem::path& filePath, seqFilesPath)
outItems.push_back(Item(getTypeFromPath(filePath), filePath));
return outItems;
}
std::string Item::getFirstFilename() const
{
if( getType() == eTypeSequence )
return getSequence().getFirstFilename();
return getFilename();
}
EType getTypeFromPath( const boost::filesystem::path& path )
{
if( bfs::is_symlink( path ) )
{
return eTypeLink;
}
if( bfs::is_regular_file( path ) )
{
return eTypeFile;
}
if( bfs::is_directory( path ) )
{
return eTypeFolder;
}
return eTypeUndefined;
}
EType getTypeFromPath( const std::string& pathStr )
{
const boost::filesystem::path path( pathStr );
return getTypeFromPath(path);
}
std::ostream& operator<<( std::ostream& os, const Item& item )
{
os << (item.getType() == eTypeSequence ? (item.getFolderPath() / item.getSequence().string()) : item.getPath());
return os;
}
}