Commit 4a0b2c66 authored by Davis King's avatar Davis King

- made sockets test compile in vc7

 - made the dir_nav stuff compile in vc, cygwin, and mingw

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402502
parent b434f430
...@@ -58,10 +58,16 @@ namespace dlib ...@@ -58,10 +58,16 @@ namespace dlib
unsigned long count; unsigned long count;
}; };
public:
struct private_constructor{};
inline file ( inline file (
const std::string& name, const std::string& name,
const std::string& full_name, const std::string& full_name,
const uint64 file_size const uint64 file_size,
private_constructor
) )
{ {
state = new data; state = new data;
...@@ -74,7 +80,6 @@ namespace dlib ...@@ -74,7 +80,6 @@ namespace dlib
public:
class file_not_found : public error { class file_not_found : public error {
public: file_not_found(const std::string& s): error(s){} public: file_not_found(const std::string& s): error(s){}
}; };
...@@ -176,6 +181,8 @@ namespace dlib ...@@ -176,6 +181,8 @@ namespace dlib
is_root() == state->name.size() == 0 is_root() == state->name.size() == 0
!*/ !*/
public:
struct data struct data
{ {
std::string name; std::string name;
...@@ -183,7 +190,6 @@ namespace dlib ...@@ -183,7 +190,6 @@ namespace dlib
unsigned long count; unsigned long count;
}; };
public:
/* /*
The reason we don't just make this constructor actually The reason we don't just make this constructor actually
...@@ -245,31 +251,18 @@ namespace dlib ...@@ -245,31 +251,18 @@ namespace dlib
static char get_separator ( static char get_separator (
); );
template <
typename queue_of_files
>
typename enable_if<is_std_vector<queue_of_files>,void>::type get_files (
queue_of_files& files
) const;
template < template <
typename queue_of_files typename queue_of_files
> >
typename disable_if<is_std_vector<queue_of_files>,void>::type get_files ( void get_files (
queue_of_files& files queue_of_files& files
) const; ) const;
template < template <
typename queue_of_dirs typename queue_of_dirs
> >
typename enable_if<is_std_vector<queue_of_dirs>,void>::type get_dirs ( void get_dirs (
queue_of_dirs& dirs
) const;
template <
typename queue_of_dirs
>
typename disable_if<is_std_vector<queue_of_dirs>,void>::type get_dirs (
queue_of_dirs& dirs queue_of_dirs& dirs
) const; ) const;
...@@ -408,35 +401,15 @@ namespace dlib ...@@ -408,35 +401,15 @@ namespace dlib
template < template <
typename queue_of_files typename queue_of_files
> >
typename enable_if<is_std_vector<queue_of_files>,void>::type directory:: typename disable_if<is_std_vector<queue_of_files>,void>::type
get_files ( directory_helper_get_files (
const directory::data* state,
queue_of_files& files queue_of_files& files
) const )
{
queue<file>::kernel_2a temp_files;
get_files(temp_files);
files.clear();
// copy the queue of files into the vector
temp_files.reset();
while (temp_files.move_next())
{
files.push_back(temp_files.element());
}
}
// ----------------------------------------------------------------------------------------
template <
typename queue_of_files
>
typename disable_if<is_std_vector<queue_of_files>,void>::type directory::
get_files (
queue_of_files& files
) const
{ {
using namespace std; using namespace std;
typedef directory::listing_error listing_error;
typedef file::private_constructor private_constructor;
files.clear(); files.clear();
if (state->full_name.size() == 0) if (state->full_name.size() == 0)
...@@ -448,8 +421,8 @@ namespace dlib ...@@ -448,8 +421,8 @@ namespace dlib
WIN32_FIND_DATAA data; WIN32_FIND_DATAA data;
string path = state->full_name; string path = state->full_name;
// ensure that the path ends with a separator // ensure that the path ends with a separator
if (path[path.size()-1] != get_separator()) if (path[path.size()-1] != directory::get_separator())
path += get_separator(); path += directory::get_separator();
ffind = FindFirstFileA((path+"*").c_str(), &data); ffind = FindFirstFileA((path+"*").c_str(), &data);
if (ffind == INVALID_HANDLE_VALUE) if (ffind == INVALID_HANDLE_VALUE)
...@@ -467,7 +440,7 @@ namespace dlib ...@@ -467,7 +440,7 @@ namespace dlib
file_size <<= 32; file_size <<= 32;
file_size |= data.nFileSizeLow; file_size |= data.nFileSizeLow;
// this is a file so add it to the queue // this is a file so add it to the queue
file temp(data.cFileName,path+data.cFileName,file_size); file temp(data.cFileName,path+data.cFileName,file_size, private_constructor());
files.enqueue(temp); files.enqueue(temp);
} }
...@@ -502,37 +475,58 @@ namespace dlib ...@@ -502,37 +475,58 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
typename queue_of_dirs typename queue_of_files
> >
typename enable_if<is_std_vector<queue_of_dirs>,void>::type directory:: typename enable_if<is_std_vector<queue_of_files>,void>::type
get_dirs ( directory_helper_get_files (
queue_of_dirs& dirs const directory::data* state,
) const queue_of_files& files
)
{ {
queue<directory>::kernel_2a temp_dirs; queue<file>::kernel_2a temp_files;
get_dirs(temp_dirs); directory_helper_get_files(state,temp_files);
dirs.clear(); files.clear();
// copy the queue of dirs into the vector // copy the queue of files into the vector
temp_dirs.reset(); temp_files.reset();
while (temp_dirs.move_next()) while (temp_files.move_next())
{ {
dirs.push_back(temp_dirs.element()); files.push_back(temp_files.element());
} }
} }
// ----------------------------------------------------------------------------------------
template <
typename queue_of_files
>
void directory::
get_files (
queue_of_files& files
) const
{
// the reason for this indirection here is because it avoids a bug in
// the mingw version of gcc
directory_helper_get_files(state,files);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
typename queue_of_dirs typename queue_of_dirs
> >
typename disable_if<is_std_vector<queue_of_dirs>,void>::type directory:: typename disable_if<is_std_vector<queue_of_dirs>,void>::type
get_dirs ( directory_helper_get_dirs (
const directory::data* state,
queue_of_dirs& dirs queue_of_dirs& dirs
) const )
{ {
using namespace std; using namespace std;
typedef directory::listing_error listing_error;
typedef directory::private_constructor private_constructor;
dirs.clear(); dirs.clear();
if (state->full_name.size() == 0) if (state->full_name.size() == 0)
...@@ -544,8 +538,8 @@ namespace dlib ...@@ -544,8 +538,8 @@ namespace dlib
WIN32_FIND_DATAA data; WIN32_FIND_DATAA data;
string path = state->full_name; string path = state->full_name;
// ensure that the path ends with a separator // ensure that the path ends with a separator
if (path[path.size()-1] != get_separator()) if (path[path.size()-1] != directory::get_separator())
path += get_separator(); path += directory::get_separator();
dfind = FindFirstFileA((path+"*").c_str(), &data); dfind = FindFirstFileA((path+"*").c_str(), &data);
if (dfind == INVALID_HANDLE_VALUE) if (dfind == INVALID_HANDLE_VALUE)
...@@ -596,6 +590,47 @@ namespace dlib ...@@ -596,6 +590,47 @@ namespace dlib
} }
// ----------------------------------------------------------------------------------------
template <
typename queue_of_dirs
>
typename enable_if<is_std_vector<queue_of_dirs>,void>::type
directory_helper_get_dirs (
const directory::data* state,
queue_of_dirs& dirs
)
{
queue<directory>::kernel_2a temp_dirs;
directory_helper_get_dirs(state,temp_dirs);
dirs.clear();
// copy the queue of dirs into the vector
temp_dirs.reset();
while (temp_dirs.move_next())
{
dirs.push_back(temp_dirs.element());
}
}
// ----------------------------------------------------------------------------------------
template <
typename queue_of_dirs
>
void directory::
get_dirs (
queue_of_dirs& dirs
) const
{
// the reason for this indirection here is because it avoids a bug in
// the mingw version of gcc
directory_helper_get_dirs(state,dirs);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
This diff is collapsed.
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "../algs.h" #include "../algs.h"
#include <string> #include <string>
#include "../threads.h" #include "../threads.h"
#include "../smart_pointers.h"
namespace dlib namespace dlib
......
...@@ -18,8 +18,8 @@ namespace { ...@@ -18,8 +18,8 @@ namespace {
using namespace dlib; using namespace dlib;
using namespace std; using namespace std;
dlib::mutex m; dlib::mutex gm;
dlib::signaler s(m); dlib::signaler gs(gm);
const char magic_num = 42; const char magic_num = 42;
const int min_bytes_sent = 10000; const int min_bytes_sent = 10000;
int assigned_port; int assigned_port;
...@@ -40,9 +40,9 @@ namespace { ...@@ -40,9 +40,9 @@ namespace {
void on_listening_port_assigned ( void on_listening_port_assigned (
) )
{ {
auto_mutex M(m); auto_mutex M(gm);
assigned_port = get_listening_port(); assigned_port = get_listening_port();
s.broadcast(); gs.broadcast();
} }
...@@ -112,9 +112,9 @@ namespace { ...@@ -112,9 +112,9 @@ namespace {
{ {
dlog << LTRACE << "enter thread"; dlog << LTRACE << "enter thread";
{ {
auto_mutex M(::m); auto_mutex M(gm);
while (assigned_port == 0) while (assigned_port == 0)
::s.wait(); gs.wait();
} }
int status; int status;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment