Initial Commit

This commit is contained in:
Norman Lansing
2026-01-28 19:08:51 -05:00
commit ecb33115bf
54042 changed files with 9695586 additions and 0 deletions

View File

@@ -0,0 +1,110 @@
// Copyright (C) 2004 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_MISC_API_KERNEl_1_
#define DLIB_MISC_API_KERNEl_1_
#ifdef DLIB_ISO_CPP_ONLY
#error "DLIB_ISO_CPP_ONLY is defined so you can't use this OS dependent code. Turn DLIB_ISO_CPP_ONLY off if you want to use it."
#endif
#include "misc_api_kernel_abstract.h"
#include "../algs.h"
#include <string>
#include "../uintn.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
void sleep (
unsigned long milliseconds
);
// ----------------------------------------------------------------------------------------
std::string get_current_dir (
);
// ----------------------------------------------------------------------------------------
class set_current_dir_error : public error
{
public:
set_current_dir_error(
const std::string& a
): error(a) {}
};
void set_current_dir (
const std::string& new_dir
);
// ----------------------------------------------------------------------------------------
class timestamper
{
/*!
INITIAL VALUE
- last_time == 0
- offset == 0
- dword_max == 2^32
CONVENTION
- last_time == the time returned by GetTickCount() the last time we
called it.
- offset == the number of microseconds we should add to the result of
GetTickCount() so that it is correct.
- dword_max == 2^32.
This is the number of values representable by a DWORD.
!*/
mutable unsigned long last_time;
mutable uint64 offset;
mutable uint64 dword_max;
public:
timestamper(
) :
last_time(0),
offset(0)
{
dword_max = 0xFFFFFFFF;
++dword_max;
}
uint64 get_timestamp (
) const;
};
// ----------------------------------------------------------------------------------------
class dir_create_error : public error
{
public:
dir_create_error(
const std::string& dir_name
) :
error(EDIR_CREATE,"Error creating directory '" + dir_name + "'."),
name(dir_name)
{}
~dir_create_error() throw() {}
const std::string name;
};
void create_directory (
const std::string& dir
);
// ----------------------------------------------------------------------------------------
}
#ifdef NO_MAKEFILE
#include "misc_api_kernel_1.cpp"
#endif
#endif // DLIB_MISC_API_KERNEl_1_

View File

@@ -0,0 +1,81 @@
// Copyright (C) 2004 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_MISC_API_KERNEl_2_
#define DLIB_MISC_API_KERNEl_2_
#ifdef DLIB_ISO_CPP_ONLY
#error "DLIB_ISO_CPP_ONLY is defined so you can't use this OS dependent code. Turn DLIB_ISO_CPP_ONLY off if you want to use it."
#endif
#include "misc_api_kernel_abstract.h"
#include "../algs.h"
#include <string>
#include "../uintn.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
void sleep (
unsigned long milliseconds
);
// ----------------------------------------------------------------------------------------
std::string get_current_dir (
);
// ----------------------------------------------------------------------------------------
class set_current_dir_error : public error
{
public:
set_current_dir_error(
const std::string& a
): error(a) {}
};
void set_current_dir (
const std::string& new_dir
);
// ----------------------------------------------------------------------------------------
class timestamper
{
public:
uint64 get_timestamp (
) const;
};
// ----------------------------------------------------------------------------------------
class dir_create_error : public error
{
public:
dir_create_error(
const std::string& dir_name
) :
error(EDIR_CREATE,"Error creating directory '" + dir_name + "'."),
name(dir_name)
{}
const std::string& name;
};
void create_directory (
const std::string& dir
);
// ----------------------------------------------------------------------------------------
}
#ifdef NO_MAKEFILE
#include "misc_api_kernel_2.cpp"
#endif
#endif // DLIB_MISC_API_KERNEl_2_

View File

@@ -0,0 +1,159 @@
// Copyright (C) 2004 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_MISC_API_KERNEl_ABSTRACT_
#ifdef DLIB_MISC_API_KERNEl_ABSTRACT_
#include <string>
#include "../uintn.h"
#include "../algs.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
/*!
GENERAL COMMENTS
This file just contains miscellaneous api functions
!*/
// ----------------------------------------------------------------------------------------
void sleep (
unsigned long milliseconds
);
/*!
ensures
- causes the calling thread to sleep for the given number of
milliseconds.
!*/
// ----------------------------------------------------------------------------------------
std::string get_current_dir (
);
/*!
ensures
- if (no errors occur) then
- returns the path to the current working directory
- else
- returns ""
throws
- std::bad_alloc
!*/
// ----------------------------------------------------------------------------------------
class set_current_dir_error : public error;
void set_current_dir (
const std::string& new_dir
);
/*!
ensures
- sets the current working directory to new_dir
throws
- std::bad_alloc
- set_current_dir_error
This exception is thrown if there is an error when attempting
to change the current working directory.
!*/
// ----------------------------------------------------------------------------------------
class locally_change_current_dir : noncopyable
{
/*!
WHAT THIS OBJECT REPRESENTS
This object is a RAII tool for safely switching the current directory
to a new directory and then automatically switching back to the original
directory upon this object's destruction.
!*/
public:
explicit locally_change_current_dir (
const std::string& new_dir
);
/*!
ensures
- calls set_current_dir(new_dir)
- #old_dir() == The value of get_current_dir() prior to switching to new_dir.
!*/
const std::string& old_dir (
) const;
/*!
ensures
- returns the directory we switch back to once this object is destructed.
!*/
~locally_change_current_dir(
);
/*!
ensures
- if (revert() hasn't already been called) then
- calls set_current_dir(old_dir())
!*/
void revert (
);
/*!
ensures
- if (revert() hasn't already been called) then
- calls set_current_dir(old_dir())
!*/
};
// ----------------------------------------------------------------------------------------
class dir_create_error : public error {
public:
const std::string name
};
void create_directory (
const std::string& dir
);
/*!
ensures
- if (dir does not already exist) then
- creates the given directory.
- else
- the call to create_directory() has no effect.
throws
- dir_create_error
This exception is thrown if we were unable to create the requested
directory and it didn't already exist. The type member of the exception
will bet set to EDIR_CREATE and the name member will be set to dir.
!*/
// ----------------------------------------------------------------------------------------
class timestamper
{
/*!
WHAT THIS OBJECT REPRESENTS
This object represents a timer that is capable of returning
timestamps.
Note that the time is measured in microseconds but you are not
guaranteed to have that level of resolution. The actual resolution
is implementation dependent.
!*/
public:
uint64 get_timestamp (
) const;
/*!
ensures
- returns a timestamp that measures the time in microseconds since an
arbitrary point in the past. Note that this arbitrary point remains
the same between all calls to get_timestamp().
!*/
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_MISC_API_KERNEl_ABSTRACT_

View File

@@ -0,0 +1,57 @@
// Copyright (C) 2014 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_MISC_API_ShARED_Hh_
#define DLIB_MISC_API_ShARED_Hh_
#include <string>
#include "../noncopyable.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
class locally_change_current_dir : noncopyable
{
public:
explicit locally_change_current_dir (
const std::string& new_dir
)
{
reverted = false;
_old_dir = get_current_dir();
set_current_dir(new_dir);
}
~locally_change_current_dir()
{
revert();
}
const std::string& old_dir (
) const
{
return _old_dir;
}
void revert (
)
{
if (!reverted)
{
set_current_dir(_old_dir);
reverted = true;
}
}
private:
bool reverted;
std::string _old_dir;
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_MISC_API_ShARED_Hh_

View File

@@ -0,0 +1,6 @@
// Copyright (C) 2004 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_MISC_API_KERNEl_1_
#include "misc_api_kernel_2.h"
#endif

View File

@@ -0,0 +1,6 @@
// Copyright (C) 2004 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_MISC_API_KERNEl_2_
#include "misc_api_kernel_1.h"
#endif