Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
a96a3886
Commit
a96a3886
authored
Feb 28, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed the file and directory objects to not be reference counted. This
is so they are safer to use in threaded programs.
parent
12dfdde3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
129 additions
and
305 deletions
+129
-305
dir_nav_kernel_1.cpp
dlib/dir_nav/dir_nav_kernel_1.cpp
+25
-29
dir_nav_kernel_1.h
dlib/dir_nav/dir_nav_kernel_1.h
+37
-117
dir_nav_kernel_2.cpp
dlib/dir_nav/dir_nav_kernel_2.cpp
+27
-31
dir_nav_kernel_2.h
dlib/dir_nav/dir_nav_kernel_2.h
+40
-120
dir_nav_kernel_abstract.h
dlib/dir_nav/dir_nav_kernel_abstract.h
+0
-8
No files found.
dlib/dir_nav/dir_nav_kernel_1.cpp
View file @
a96a3886
...
...
@@ -30,8 +30,6 @@ namespace dlib
)
{
using
namespace
std
;
state
=
new
data
;
state
->
count
=
1
;
char
buf
[
3000
];
...
...
@@ -41,21 +39,21 @@ namespace dlib
// the file was not found
throw
file_not_found
(
"Unable to find file "
+
name
);
}
state
->
full_name
=
buf
;
state
.
full_name
=
buf
;
string
::
size_type
pos
=
state
->
full_name
.
find_last_of
(
directory
::
get_separator
());
string
::
size_type
pos
=
state
.
full_name
.
find_last_of
(
directory
::
get_separator
());
if
(
pos
==
string
::
npos
)
{
// no valid full path has no separator characters.
throw
file_not_found
(
"Unable to find file "
+
name
);
}
state
->
name
=
state
->
full_name
.
substr
(
pos
+
1
);
state
.
name
=
state
.
full_name
.
substr
(
pos
+
1
);
// now find the size of this file
WIN32_FIND_DATAA
data
;
HANDLE
ffind
=
FindFirstFileA
(
state
->
full_name
.
c_str
(),
&
data
);
HANDLE
ffind
=
FindFirstFileA
(
state
.
full_name
.
c_str
(),
&
data
);
if
(
ffind
==
INVALID_HANDLE_VALUE
||
(
data
.
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
)
!=
0
)
{
...
...
@@ -66,7 +64,7 @@ namespace dlib
uint64
temp
=
data
.
nFileSizeHigh
;
temp
<<=
32
;
temp
|=
data
.
nFileSizeLow
;
state
->
file_size
=
temp
;
state
.
file_size
=
temp
;
FindClose
(
ffind
);
}
...
...
@@ -81,12 +79,12 @@ namespace dlib
{
using
namespace
std
;
if
(
state
->
full_name
.
size
()
!=
rhs
.
state
->
full_name
.
size
())
if
(
state
.
full_name
.
size
()
!=
rhs
.
state
.
full_name
.
size
())
return
false
;
// compare the strings but ignore the case because file names
// are not case sensitive on windows
return
tolower
(
state
->
full_name
)
==
tolower
(
rhs
.
state
->
full_name
);
return
tolower
(
state
.
full_name
)
==
tolower
(
rhs
.
state
.
full_name
);
}
// ----------------------------------------------------------------------------------------
...
...
@@ -102,8 +100,6 @@ namespace dlib
{
using
namespace
std
;
state
=
new
data
;
state
->
count
=
1
;
char
buf
[
3000
];
char
*
str
;
...
...
@@ -112,30 +108,30 @@ namespace dlib
// the directory was not found
throw
dir_not_found
(
"Unable to find directory "
+
name
);
}
state
->
full_name
=
buf
;
state
.
full_name
=
buf
;
const
char
sep
=
get_separator
();
if
(
is_root_path
(
state
->
full_name
)
==
false
)
if
(
is_root_path
(
state
.
full_name
)
==
false
)
{
// ensure that thre is not a trialing separator
if
(
state
->
full_name
[
state
->
full_name
.
size
()
-
1
]
==
sep
)
state
->
full_name
.
erase
(
state
->
full_name
.
size
()
-
1
);
if
(
state
.
full_name
[
state
.
full_name
.
size
()
-
1
]
==
sep
)
state
.
full_name
.
erase
(
state
.
full_name
.
size
()
-
1
);
// pick out the directory name
string
::
size_type
pos
=
state
->
full_name
.
find_last_of
(
sep
);
state
->
name
=
state
->
full_name
.
substr
(
pos
+
1
);
string
::
size_type
pos
=
state
.
full_name
.
find_last_of
(
sep
);
state
.
name
=
state
.
full_name
.
substr
(
pos
+
1
);
}
else
{
// ensure that there is a trailing separator
if
(
state
->
full_name
[
state
->
full_name
.
size
()
-
1
]
!=
sep
)
state
->
full_name
+=
sep
;
if
(
state
.
full_name
[
state
.
full_name
.
size
()
-
1
]
!=
sep
)
state
.
full_name
+=
sep
;
}
// now check that this is actually a valid directory
DWORD
attribs
=
GetFileAttributesA
(
state
->
full_name
.
c_str
());
DWORD
attribs
=
GetFileAttributesA
(
state
.
full_name
.
c_str
());
if
(
attribs
==
INVALID_FILE_ATTRIBUTES
||
(
attribs
&
FILE_ATTRIBUTE_DIRECTORY
)
==
0
)
{
...
...
@@ -163,12 +159,12 @@ namespace dlib
{
using
namespace
std
;
if
(
state
->
full_name
.
size
()
!=
rhs
.
state
->
full_name
.
size
())
if
(
state
.
full_name
.
size
()
!=
rhs
.
state
.
full_name
.
size
())
return
false
;
// compare the strings but ignore the case because file names
// are not case sensitive on windows
return
tolower
(
state
->
full_name
)
==
tolower
(
rhs
.
state
->
full_name
);
return
tolower
(
state
.
full_name
)
==
tolower
(
rhs
.
state
.
full_name
);
}
// ----------------------------------------------------------------------------------------
...
...
@@ -189,23 +185,23 @@ namespace dlib
const
char
sep
=
get_separator
();
string
::
size_type
pos
=
state
->
full_name
.
find_last_of
(
sep
);
temp
.
state
->
full_name
=
state
->
full_name
.
substr
(
0
,
pos
);
string
::
size_type
pos
=
state
.
full_name
.
find_last_of
(
sep
);
temp
.
state
.
full_name
=
state
.
full_name
.
substr
(
0
,
pos
);
if
(
is_root_path
(
temp
.
state
->
full_name
))
if
(
is_root_path
(
temp
.
state
.
full_name
))
{
temp
.
state
->
full_name
+=
sep
;
temp
.
state
.
full_name
+=
sep
;
}
else
{
pos
=
temp
.
state
->
full_name
.
find_last_of
(
sep
);
pos
=
temp
.
state
.
full_name
.
find_last_of
(
sep
);
if
(
pos
!=
string
::
npos
)
{
temp
.
state
->
name
=
temp
.
state
->
full_name
.
substr
(
pos
+
1
);
temp
.
state
.
name
=
temp
.
state
.
full_name
.
substr
(
pos
+
1
);
}
else
{
temp
.
state
->
full_name
+=
sep
;
temp
.
state
.
full_name
+=
sep
;
}
}
return
temp
;
...
...
dlib/dir_nav/dir_nav_kernel_1.h
View file @
a96a3886
...
...
@@ -36,15 +36,14 @@ namespace dlib
{
/*!
INITIAL VALUES
state
->
name == name()
state
->
full_name == full_name()
state
->
file_size == size()
state
.
name == name()
state
.
full_name == full_name()
state
.
file_size == size()
CONVENTION
state->name == name()
state->full_name == full_name()
state->file_size == size()
state->count == the number of file objects that point to state
state.name == name()
state.full_name == full_name()
state.file_size == size()
!*/
...
...
@@ -55,7 +54,6 @@ namespace dlib
uint64
file_size
;
std
::
string
name
;
std
::
string
full_name
;
unsigned
long
count
;
};
...
...
@@ -71,11 +69,9 @@ namespace dlib
private_constructor
)
{
state
=
new
data
;
state
->
count
=
1
;
state
->
file_size
=
file_size
;
state
->
name
=
name
;
state
->
full_name
=
full_name
;
state
.
file_size
=
file_size
;
state
.
name
=
name
;
state
.
full_name
=
full_name
;
}
...
...
@@ -88,9 +84,7 @@ namespace dlib
inline
file
(
)
{
state
=
new
data
;
state
->
count
=
1
;
state
->
file_size
=
0
;
state
.
file_size
=
0
;
}
file
(
...
...
@@ -101,48 +95,14 @@ namespace dlib
const
char
*
name
)
{
init
(
name
);
}
inline
file
(
const
file
&
item
)
{
state
=
item
.
state
;
state
->
count
+=
1
;
}
inline
~
file
(
)
{
if
(
state
->
count
==
1
)
delete
state
;
else
state
->
count
-=
1
;
}
inline
const
std
::
string
&
name
(
)
const
{
return
state
->
name
;
}
)
const
{
return
state
.
name
;
}
inline
const
std
::
string
&
full_name
(
)
const
{
return
state
->
full_name
;
}
)
const
{
return
state
.
full_name
;
}
inline
uint64
size
(
)
const
{
return
state
->
file_size
;
}
inline
file
&
operator
=
(
const
file
&
rhs
)
{
if
(
&
rhs
==
this
)
return
*
this
;
if
(
state
->
count
==
1
)
delete
state
;
else
state
->
count
-=
1
;
state
=
rhs
.
state
;
state
->
count
+=
1
;
return
*
this
;
}
)
const
{
return
state
.
file_size
;
}
bool
operator
==
(
const
file
&
rhs
...
...
@@ -165,8 +125,7 @@ namespace dlib
private
:
// member data
data
*
state
;
data
state
;
};
...
...
@@ -180,14 +139,13 @@ namespace dlib
{
/*!
INITIAL VALUES
state
->
name == name()
state
->
full_name == full_name()
state
.
name == name()
state
.
full_name == full_name()
CONVENTION
state->name == name()
state->full_name == full_name()
state->count == the number of directory objects that point to state
is_root() == state->name.size() == 0
state.name == name()
state.full_name == full_name()
is_root() == state.name.size() == 0
!*/
...
...
@@ -199,7 +157,6 @@ namespace dlib
{
std
::
string
name
;
std
::
string
full_name
;
unsigned
long
count
;
};
...
...
@@ -218,10 +175,8 @@ namespace dlib
private_constructor
)
{
state
=
new
data
;
state
->
count
=
1
;
state
->
name
=
name
;
state
->
full_name
=
full_name
;
state
.
name
=
name
;
state
.
full_name
=
full_name
;
}
...
...
@@ -235,8 +190,6 @@ namespace dlib
inline
directory
(
)
{
state
=
new
data
;
state
->
count
=
1
;
}
directory
(
...
...
@@ -247,22 +200,6 @@ namespace dlib
const
char
*
name
)
{
init
(
name
);
}
inline
directory
(
const
directory
&
item
)
{
state
=
item
.
state
;
state
->
count
+=
1
;
}
inline
~
directory
(
)
{
if
(
state
->
count
==
1
)
delete
state
;
else
state
->
count
-=
1
;
}
static
char
get_separator
(
);
...
...
@@ -286,30 +223,13 @@ namespace dlib
)
const
;
inline
bool
is_root
(
)
const
{
return
state
->
name
.
size
()
==
0
;
}
)
const
{
return
state
.
name
.
size
()
==
0
;
}
inline
const
std
::
string
&
name
(
)
const
{
return
state
->
name
;
}
)
const
{
return
state
.
name
;
}
inline
const
std
::
string
&
full_name
(
)
const
{
return
state
->
full_name
;
}
directory
&
operator
=
(
const
directory
&
rhs
)
{
if
(
&
rhs
==
this
)
return
*
this
;
if
(
state
->
count
==
1
)
delete
state
;
else
state
->
count
-=
1
;
state
=
rhs
.
state
;
state
->
count
+=
1
;
return
*
this
;
}
)
const
{
return
state
.
full_name
;
}
bool
operator
==
(
const
directory
&
rhs
...
...
@@ -333,7 +253,7 @@ namespace dlib
private
:
// member data
data
*
state
;
data
state
;
bool
is_root_path
(
const
std
::
string
&
path
...
...
@@ -423,7 +343,7 @@ namespace dlib
>
typename
disable_if
<
is_std_vector
<
queue_of_files
>
,
void
>::
type
directory_helper_get_files
(
const
directory
::
data
*
state
,
const
directory
::
data
&
state
,
queue_of_files
&
files
)
{
...
...
@@ -432,14 +352,14 @@ namespace dlib
typedef
file
::
private_constructor
private_constructor
;
files
.
clear
();
if
(
state
->
full_name
.
size
()
==
0
)
if
(
state
.
full_name
.
size
()
==
0
)
throw
listing_error
(
"This directory object currently doesn't represent any directory."
);
HANDLE
ffind
=
INVALID_HANDLE_VALUE
;
try
{
WIN32_FIND_DATAA
data
;
string
path
=
state
->
full_name
;
string
path
=
state
.
full_name
;
// ensure that the path ends with a separator
if
(
path
[
path
.
size
()
-
1
]
!=
directory
::
get_separator
())
path
+=
directory
::
get_separator
();
...
...
@@ -447,7 +367,7 @@ namespace dlib
ffind
=
FindFirstFileA
((
path
+
"*"
).
c_str
(),
&
data
);
if
(
ffind
==
INVALID_HANDLE_VALUE
)
{
throw
listing_error
(
"Unable to list the contents of "
+
state
->
full_name
);
throw
listing_error
(
"Unable to list the contents of "
+
state
.
full_name
);
}
...
...
@@ -475,7 +395,7 @@ namespace dlib
else
{
// there was an error
throw
listing_error
(
"Unable to list the contents of "
+
state
->
full_name
);
throw
listing_error
(
"Unable to list the contents of "
+
state
.
full_name
);
}
}
}
while
(
no_more_files
==
false
);
...
...
@@ -499,7 +419,7 @@ namespace dlib
>
typename
enable_if
<
is_std_vector
<
queue_of_files
>
,
void
>::
type
directory_helper_get_files
(
const
directory
::
data
*
state
,
const
directory
::
data
&
state
,
queue_of_files
&
files
)
{
...
...
@@ -540,7 +460,7 @@ namespace dlib
>
typename
disable_if
<
is_std_vector
<
queue_of_dirs
>
,
void
>::
type
directory_helper_get_dirs
(
const
directory
::
data
*
state
,
const
directory
::
data
&
state
,
queue_of_dirs
&
dirs
)
{
...
...
@@ -549,14 +469,14 @@ namespace dlib
typedef
directory
::
private_constructor
private_constructor
;
dirs
.
clear
();
if
(
state
->
full_name
.
size
()
==
0
)
if
(
state
.
full_name
.
size
()
==
0
)
throw
listing_error
(
"This directory object currently doesn't represent any directory."
);
HANDLE
dfind
=
INVALID_HANDLE_VALUE
;
try
{
WIN32_FIND_DATAA
data
;
string
path
=
state
->
full_name
;
string
path
=
state
.
full_name
;
// ensure that the path ends with a separator
if
(
path
[
path
.
size
()
-
1
]
!=
directory
::
get_separator
())
path
+=
directory
::
get_separator
();
...
...
@@ -564,7 +484,7 @@ namespace dlib
dfind
=
FindFirstFileA
((
path
+
"*"
).
c_str
(),
&
data
);
if
(
dfind
==
INVALID_HANDLE_VALUE
)
{
throw
listing_error
(
"Unable to list the contents of "
+
state
->
full_name
);
throw
listing_error
(
"Unable to list the contents of "
+
state
.
full_name
);
}
...
...
@@ -592,7 +512,7 @@ namespace dlib
else
{
// there was an error
throw
listing_error
(
"Unable to list the contents of "
+
state
->
full_name
);
throw
listing_error
(
"Unable to list the contents of "
+
state
.
full_name
);
}
}
}
while
(
no_more_files
==
false
);
...
...
@@ -617,7 +537,7 @@ namespace dlib
>
typename
enable_if
<
is_std_vector
<
queue_of_dirs
>
,
void
>::
type
directory_helper_get_dirs
(
const
directory
::
data
*
state
,
const
directory
::
data
&
state
,
queue_of_dirs
&
dirs
)
{
...
...
dlib/dir_nav/dir_nav_kernel_2.cpp
View file @
a96a3886
...
...
@@ -29,8 +29,6 @@ namespace dlib
)
{
using
namespace
std
;
state
=
new
data
;
state
->
count
=
1
;
...
...
@@ -40,21 +38,21 @@ namespace dlib
// the file was not found
throw
file_not_found
(
"Unable to find file "
+
name
);
}
state
->
full_name
=
buf
;
state
.
full_name
=
buf
;
string
::
size_type
pos
=
state
->
full_name
.
find_last_of
(
directory
::
get_separator
());
string
::
size_type
pos
=
state
.
full_name
.
find_last_of
(
directory
::
get_separator
());
if
(
pos
==
string
::
npos
)
{
// no valid full path has no separtor characters.
throw
file_not_found
(
"Unable to find file "
+
name
);
}
state
->
name
=
state
->
full_name
.
substr
(
pos
+
1
);
state
.
name
=
state
.
full_name
.
substr
(
pos
+
1
);
// now find the size of this file
struct
stat64
buffer
;
if
(
::
stat64
(
state
->
full_name
.
c_str
(),
&
buffer
)
||
if
(
::
stat64
(
state
.
full_name
.
c_str
(),
&
buffer
)
||
S_ISDIR
(
buffer
.
st_mode
))
{
// there was an error during the call to stat64 or
...
...
@@ -63,7 +61,7 @@ namespace dlib
}
else
{
state
->
file_size
=
static_cast
<
uint64
>
(
buffer
.
st_size
);
state
.
file_size
=
static_cast
<
uint64
>
(
buffer
.
st_size
);
}
}
...
...
@@ -76,18 +74,18 @@ namespace dlib
)
const
{
using
namespace
std
;
if
(
state
->
full_name
.
size
()
==
0
&&
rhs
.
state
->
full_name
.
size
()
==
0
)
if
(
state
.
full_name
.
size
()
==
0
&&
rhs
.
state
.
full_name
.
size
()
==
0
)
return
true
;
// These files might have different names but actually represent the same
// file due to the presence of symbolic links.
char
buf
[
PATH_MAX
];
string
left
,
right
;
if
(
realpath
(
state
->
full_name
.
c_str
(),
buf
)
==
0
)
if
(
realpath
(
state
.
full_name
.
c_str
(),
buf
)
==
0
)
return
false
;
left
=
buf
;
if
(
realpath
(
rhs
.
state
->
full_name
.
c_str
(),
buf
)
==
0
)
if
(
realpath
(
rhs
.
state
.
full_name
.
c_str
(),
buf
)
==
0
)
return
false
;
right
=
buf
;
...
...
@@ -107,8 +105,6 @@ namespace dlib
{
using
namespace
std
;
state
=
new
data
;
state
->
count
=
1
;
char
buf
[
PATH_MAX
];
if
(
realpath
(
name
.
c_str
(),
buf
)
==
0
)
...
...
@@ -116,31 +112,31 @@ namespace dlib
// the directory was not found
throw
dir_not_found
(
"Unable to find directory "
+
name
);
}
state
->
full_name
=
buf
;
state
.
full_name
=
buf
;
const
char
sep
=
get_separator
();
if
(
is_root_path
(
state
->
full_name
)
==
false
)
if
(
is_root_path
(
state
.
full_name
)
==
false
)
{
// ensure that thre is not a trialing separator
if
(
state
->
full_name
[
state
->
full_name
.
size
()
-
1
]
==
sep
)
state
->
full_name
.
erase
(
state
->
full_name
.
size
()
-
1
);
if
(
state
.
full_name
[
state
.
full_name
.
size
()
-
1
]
==
sep
)
state
.
full_name
.
erase
(
state
.
full_name
.
size
()
-
1
);
// pick out the directory name
string
::
size_type
pos
=
state
->
full_name
.
find_last_of
(
sep
);
state
->
name
=
state
->
full_name
.
substr
(
pos
+
1
);
string
::
size_type
pos
=
state
.
full_name
.
find_last_of
(
sep
);
state
.
name
=
state
.
full_name
.
substr
(
pos
+
1
);
}
else
{
// ensure that there is a trailing separator
if
(
state
->
full_name
[
state
->
full_name
.
size
()
-
1
]
!=
sep
)
state
->
full_name
+=
sep
;
if
(
state
.
full_name
[
state
.
full_name
.
size
()
-
1
]
!=
sep
)
state
.
full_name
+=
sep
;
}
struct
stat64
buffer
;
// now check that this is actually a valid directory
if
(
::
stat64
(
state
->
full_name
.
c_str
(),
&
buffer
))
if
(
::
stat64
(
state
.
full_name
.
c_str
(),
&
buffer
))
{
// the directory was not found
throw
dir_not_found
(
"Unable to find directory "
+
name
);
...
...
@@ -169,18 +165,18 @@ namespace dlib
)
const
{
using
namespace
std
;
if
(
state
->
full_name
.
size
()
==
0
&&
rhs
.
state
->
full_name
.
size
()
==
0
)
if
(
state
.
full_name
.
size
()
==
0
&&
rhs
.
state
.
full_name
.
size
()
==
0
)
return
true
;
// These directories might have different names but actually represent the same
// directory due to the presence of symbolic links.
char
buf
[
PATH_MAX
];
string
left
,
right
;
if
(
realpath
(
state
->
full_name
.
c_str
(),
buf
)
==
0
)
if
(
realpath
(
state
.
full_name
.
c_str
(),
buf
)
==
0
)
return
false
;
left
=
buf
;
if
(
realpath
(
rhs
.
state
->
full_name
.
c_str
(),
buf
)
==
0
)
if
(
realpath
(
rhs
.
state
.
full_name
.
c_str
(),
buf
)
==
0
)
return
false
;
right
=
buf
;
...
...
@@ -205,23 +201,23 @@ namespace dlib
const
char
sep
=
get_separator
();
string
::
size_type
pos
=
state
->
full_name
.
find_last_of
(
sep
);
temp
.
state
->
full_name
=
state
->
full_name
.
substr
(
0
,
pos
);
string
::
size_type
pos
=
state
.
full_name
.
find_last_of
(
sep
);
temp
.
state
.
full_name
=
state
.
full_name
.
substr
(
0
,
pos
);
if
(
is_root_path
(
temp
.
state
->
full_name
))
if
(
is_root_path
(
temp
.
state
.
full_name
))
{
temp
.
state
->
full_name
+=
sep
;
temp
.
state
.
full_name
+=
sep
;
}
else
{
pos
=
temp
.
state
->
full_name
.
find_last_of
(
sep
);
pos
=
temp
.
state
.
full_name
.
find_last_of
(
sep
);
if
(
pos
!=
string
::
npos
)
{
temp
.
state
->
name
=
temp
.
state
->
full_name
.
substr
(
pos
+
1
);
temp
.
state
.
name
=
temp
.
state
.
full_name
.
substr
(
pos
+
1
);
}
else
{
temp
.
state
->
full_name
+=
sep
;
temp
.
state
.
full_name
+=
sep
;
}
}
return
temp
;
...
...
dlib/dir_nav/dir_nav_kernel_2.h
View file @
a96a3886
...
...
@@ -44,15 +44,14 @@ namespace dlib
{
/*!
INITIAL VALUES
state
->
name == name()
state
->
full_name == full_name()
state
->
file_size == size()
state
.
name == name()
state
.
full_name == full_name()
state
.
file_size == size()
CONVENTION
state->name == name()
state->full_name == full_name()
state->file_size == size()
state->count == the number of file objects that point to state
state.name == name()
state.full_name == full_name()
state.file_size == size()
!*/
...
...
@@ -63,7 +62,6 @@ namespace dlib
uint64
file_size
;
std
::
string
name
;
std
::
string
full_name
;
unsigned
long
count
;
};
void
init
(
const
std
::
string
&
name
);
...
...
@@ -78,11 +76,9 @@ namespace dlib
private_constructor
)
{
state
=
new
data
;
state
->
count
=
1
;
state
->
file_size
=
file_size
;
state
->
name
=
name
;
state
->
full_name
=
full_name
;
state
.
file_size
=
file_size
;
state
.
name
=
name
;
state
.
full_name
=
full_name
;
}
...
...
@@ -93,9 +89,7 @@ namespace dlib
inline
file
(
)
{
state
=
new
data
;
state
->
count
=
1
;
state
->
file_size
=
0
;
state
.
file_size
=
0
;
}
file
(
...
...
@@ -106,48 +100,14 @@ namespace dlib
const
char
*
name
)
{
init
(
name
);
}
inline
file
(
const
file
&
item
)
{
state
=
item
.
state
;
state
->
count
+=
1
;
}
inline
~
file
(
)
{
if
(
state
->
count
==
1
)
delete
state
;
else
state
->
count
-=
1
;
}
inline
const
std
::
string
&
name
(
)
const
{
return
state
->
name
;
}
)
const
{
return
state
.
name
;
}
inline
const
std
::
string
&
full_name
(
)
const
{
return
state
->
full_name
;
}
)
const
{
return
state
.
full_name
;
}
inline
uint64
size
(
)
const
{
return
state
->
file_size
;
}
inline
file
&
operator
=
(
const
file
&
rhs
)
{
if
(
&
rhs
==
this
)
return
*
this
;
if
(
state
->
count
==
1
)
delete
state
;
else
state
->
count
-=
1
;
state
=
rhs
.
state
;
state
->
count
+=
1
;
return
*
this
;
}
)
const
{
return
state
.
file_size
;
}
bool
operator
==
(
const
file
&
rhs
...
...
@@ -171,7 +131,7 @@ namespace dlib
private
:
// member data
data
*
state
;
data
state
;
};
...
...
@@ -185,14 +145,13 @@ namespace dlib
{
/*!
INITIAL VALUES
state
->
name == name()
state
->
full_name == full_name()
state
.
name == name()
state
.
full_name == full_name()
CONVENTION
state->name == name()
state->full_name == full_name()
state->count == the number of directory objects that point to state
is_root() == state->name.size() == 0
state.name == name()
state.full_name == full_name()
is_root() == state.name.size() == 0
!*/
...
...
@@ -206,17 +165,14 @@ namespace dlib
private_constructor
)
{
state
=
new
data
;
state
->
count
=
1
;
state
->
name
=
name
;
state
->
full_name
=
full_name
;
state
.
name
=
name
;
state
.
full_name
=
full_name
;
}
struct
data
{
std
::
string
name
;
std
::
string
full_name
;
unsigned
long
count
;
};
class
dir_not_found
:
public
error
{
...
...
@@ -229,8 +185,6 @@ namespace dlib
inline
directory
(
)
{
state
=
new
data
;
state
->
count
=
1
;
}
directory
(
...
...
@@ -241,23 +195,6 @@ namespace dlib
const
char
*
name
)
{
init
(
name
);
}
inline
directory
(
const
directory
&
item
)
{
state
=
item
.
state
;
state
->
count
+=
1
;
}
inline
~
directory
(
)
{
if
(
state
->
count
==
1
)
delete
state
;
else
state
->
count
-=
1
;
}
static
char
get_separator
(
);
...
...
@@ -279,30 +216,13 @@ namespace dlib
)
const
;
inline
bool
is_root
(
)
const
{
return
state
->
name
.
size
()
==
0
;
}
)
const
{
return
state
.
name
.
size
()
==
0
;
}
inline
const
std
::
string
&
name
(
)
const
{
return
state
->
name
;
}
)
const
{
return
state
.
name
;
}
inline
const
std
::
string
&
full_name
(
)
const
{
return
state
->
full_name
;
}
directory
&
operator
=
(
const
directory
&
rhs
)
{
if
(
&
rhs
==
this
)
return
*
this
;
if
(
state
->
count
==
1
)
delete
state
;
else
state
->
count
-=
1
;
state
=
rhs
.
state
;
state
->
count
+=
1
;
return
*
this
;
}
)
const
{
return
state
.
full_name
;
}
bool
operator
==
(
const
directory
&
rhs
...
...
@@ -326,7 +246,7 @@ namespace dlib
private
:
// member data
data
*
state
;
data
state
;
bool
is_root_path
(
const
std
::
string
&
path
...
...
@@ -365,14 +285,14 @@ namespace dlib
>
typename
disable_if
<
is_std_vector
<
queue_of_files
>
,
void
>::
type
directory_helper_get_files
(
const
directory
::
data
*
state
,
const
directory
::
data
&
state
,
queue_of_files
&
files
)
{
using
namespace
std
;
files
.
clear
();
if
(
state
->
full_name
.
size
()
==
0
)
if
(
state
.
full_name
.
size
()
==
0
)
throw
directory
::
listing_error
(
"This directory object currently doesn't represent any directory."
);
DIR
*
ffind
=
0
;
...
...
@@ -381,16 +301,16 @@ namespace dlib
try
{
string
path
=
state
->
full_name
;
string
path
=
state
.
full_name
;
// ensure that the path ends with a separator
if
(
path
[
path
.
size
()
-
1
]
!=
directory
::
get_separator
())
path
+=
directory
::
get_separator
();
// get a handle to something we can search with
ffind
=
opendir
(
state
->
full_name
.
c_str
());
ffind
=
opendir
(
state
.
full_name
.
c_str
());
if
(
ffind
==
0
)
{
throw
directory
::
listing_error
(
"Unable to list the contents of "
+
state
->
full_name
);
throw
directory
::
listing_error
(
"Unable to list the contents of "
+
state
.
full_name
);
}
while
(
true
)
...
...
@@ -407,7 +327,7 @@ namespace dlib
else
{
// there was an error
throw
directory
::
listing_error
(
"Unable to list the contents of "
+
state
->
full_name
);
throw
directory
::
listing_error
(
"Unable to list the contents of "
+
state
.
full_name
);
}
}
...
...
@@ -420,7 +340,7 @@ namespace dlib
char
buf
[
PATH_MAX
];
ssize_t
temp
=
readlink
((
path
+
data
->
d_name
).
c_str
(),
buf
,
sizeof
(
buf
));
if
(
temp
==
-
1
)
throw
directory
::
listing_error
(
"Unable to list the contents of "
+
state
->
full_name
);
throw
directory
::
listing_error
(
"Unable to list the contents of "
+
state
.
full_name
);
else
file_size
=
static_cast
<
uint64
>
(
temp
);
}
...
...
@@ -476,7 +396,7 @@ namespace dlib
>
typename
enable_if
<
is_std_vector
<
queue_of_files
>
,
void
>::
type
directory_helper_get_files
(
const
directory
::
data
*
state
,
const
directory
::
data
&
state
,
queue_of_files
&
files
)
{
...
...
@@ -517,14 +437,14 @@ namespace dlib
>
typename
disable_if
<
is_std_vector
<
queue_of_dirs
>
,
void
>::
type
directory_helper_get_dirs
(
const
directory
::
data
*
state
,
const
directory
::
data
&
state
,
queue_of_dirs
&
dirs
)
{
using
namespace
std
;
dirs
.
clear
();
if
(
state
->
full_name
.
size
()
==
0
)
if
(
state
.
full_name
.
size
()
==
0
)
throw
directory
::
listing_error
(
"This directory object currently doesn't represent any directory."
);
DIR
*
ffind
=
0
;
...
...
@@ -533,16 +453,16 @@ namespace dlib
try
{
string
path
=
state
->
full_name
;
string
path
=
state
.
full_name
;
// ensure that the path ends with a separator
if
(
path
[
path
.
size
()
-
1
]
!=
directory
::
get_separator
())
path
+=
directory
::
get_separator
();
// get a handle to something we can search with
ffind
=
opendir
(
state
->
full_name
.
c_str
());
ffind
=
opendir
(
state
.
full_name
.
c_str
());
if
(
ffind
==
0
)
{
throw
directory
::
listing_error
(
"Unable to list the contents of "
+
state
->
full_name
);
throw
directory
::
listing_error
(
"Unable to list the contents of "
+
state
.
full_name
);
}
while
(
true
)
...
...
@@ -559,7 +479,7 @@ namespace dlib
else
{
// there was an error
throw
directory
::
listing_error
(
"Unable to list the contents of "
+
state
->
full_name
);
throw
directory
::
listing_error
(
"Unable to list the contents of "
+
state
.
full_name
);
}
}
...
...
@@ -616,7 +536,7 @@ namespace dlib
>
typename
enable_if
<
is_std_vector
<
queue_of_dirs
>
,
void
>::
type
directory_helper_get_dirs
(
const
directory
::
data
*
state
,
const
directory
::
data
&
state
,
queue_of_dirs
&
dirs
)
{
...
...
dlib/dir_nav/dir_nav_kernel_abstract.h
View file @
a96a3886
...
...
@@ -56,10 +56,6 @@ namespace dlib
object is constructed. Thus if a file changes sizes after its
file object has been created its file object's size() method
will not reflect the new file size.
THREAD SAFETY
This object is reference counted so use with caution in a threaded
environment.
!*/
public
:
...
...
@@ -208,10 +204,6 @@ namespace dlib
the ability to traverse a directory tree.
Note that the directories . and .. are not returned by get_dirs()
THREAD SAFETY
This object is reference counted so use with caution in a threaded
environment.
!*/
public
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment