Initial Commit - Lesson 31 (Commit #1)

This commit is contained in:
Norman Lansing
2026-02-24 22:39:26 -05:00
commit 9591e7f503
4631 changed files with 1019212 additions and 0 deletions

View File

@@ -0,0 +1,107 @@
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_CMD_LINE_PARSER_OPTIOn_
#define DLIB_CMD_LINE_PARSER_OPTIOn_
#include <string>
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <
typename charT
>
class cmd_line_parser_option
{
/*!
POINTERS AND REFERENCES TO INTERNAL DATA
None of the functions in cmd_line_parser_option will invalidate
pointers or references to internal data when called.
WHAT THIS OBJECT REPRESENTS
This object represents a command line option.
!*/
public:
typedef charT char_type;
typedef std::basic_string<charT> string_type;
virtual ~cmd_line_parser_option (
) = 0;
virtual const string_type& name (
) const = 0;
/*!
ensures
- returns the name of this option
!*/
virtual const string_type& group_name (
) const = 0;
/*!
ensures
- returns the name of the group this option is in. If no group was set for
this option then this function returns "".
!*/
virtual const string_type& description (
) const = 0;
/*!
ensures
- returns the description for this option
!*/
virtual unsigned long number_of_arguments(
) const = 0;
/*!
ensures
- returns the number of arguments for this option
!*/
virtual unsigned long count(
) const = 0;
/*!
ensures
- returns the number of times this option appears on the command line.
!*/
virtual const string_type& argument (
unsigned long arg = 0,
unsigned long N = 0
) const = 0;
/*!
requires
- arg < number_of_arguments()
- N < count()
ensures
- returns the arg-th argument to the Nth occurrence of this
option on the command line.
!*/
inline operator bool (
) const { return count() > 0; }
/*!
ensures
- returns true if this option appears on the command line at all
!*/
protected:
// restricted functions
cmd_line_parser_option& operator=(const cmd_line_parser_option&){return *this;}
};
// destructor does nothing
template < typename charT >
cmd_line_parser_option<charT>::~cmd_line_parser_option() {}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_CMD_LINE_PARSER_OPTIOn_

View File

@@ -0,0 +1,130 @@
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ENUMERABLe_INTERFACE_
#define DLIB_ENUMERABLe_INTERFACE_
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <
typename T
>
class enumerable
{
/*!
POINTERS AND REFERENCES TO INTERNAL DATA
- if (at_start()) then
- all pointers and references to data returned via element() are
invalid.
- calling move_next() or reset() invalidates pointers and references to
data returned via element() and only data returned via element().
- calling at_start(), current_element_valid(), size(), or element()
does NOT invalidate pointers or references to any internal data.
INITIAL VALUE
current_element_valid() == false
at_start() == true
WHAT THIS OBJECT REPRESENTS
This object represent an interface for iterating through the
elements in a container. It starts out one before the first element
in the container.
EXAMPLE: The following loops though all elements in the container
and prints them to cout.
container.reset();
while(container.move_next()) {
cout << container.element();
}
!*/
public:
typedef T type;
inline virtual ~enumerable(
) = 0;
virtual bool at_start (
) const = 0;
/*!
ensures
- returns true if *this represents one position before the first element
in the container (this would also make the current element invalid)
else returns false
!*/
virtual void reset (
) const = 0;
/*!
ensures
- #current_element_valid() == false
- #at_start() == true
!*/
virtual bool current_element_valid (
) const = 0;
/*!
ensures
- returns true if we are currently at a valid element else
returns false
!*/
virtual const T& element (
) const = 0;
/*!
requires
- current_element_valid() == true
ensures
- returns a const reference to the current element
!*/
virtual T& element (
) = 0;
/*!
requires
- current_element_valid() == true
ensures
- returns a non-const reference to the current element
!*/
virtual bool move_next (
) const = 0;
/*!
ensures
- moves to the next element. i.e. #element() will now
return the next element in the container
- the return value will be equal to #current_element_valid()
- #at_start() == false
- returns true if there is another element
- returns false if there are no more elements in the container
!*/
virtual size_t size (
) const = 0;
/*!
ensures
- returns the number of elements in *this
!*/
protected:
// restricted functions
enumerable& operator=(const enumerable&) {return *this;} // no assignment operator
};
// destructor does nothing
template <typename T>
enumerable<T>::~enumerable() {}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ENUMERABLe_INTERFACE_

View File

@@ -0,0 +1,74 @@
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_MAP_PAIr_INTERFACE_
#define DLIB_MAP_PAIr_INTERFACE_
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <
typename T1,
typename T2
>
class map_pair
{
/*!
POINTERS AND REFERENCES TO INTERNAL DATA
None of the functions in map_pair will invalidate
pointers or references to internal data when called.
WHAT THIS OBJECT REPRESENTS
this object is used to return the key/value pair used in the
map and hash_map containers when using the enumerable interface.
note that the enumerable interface is defined in
interfaces/enumerable.h
!*/
public:
typedef T1 key_type;
typedef T2 value_type;
virtual ~map_pair(
)=0;
virtual const T1& key(
) const =0;
/*!
ensures
- returns a const reference to the key
!*/
virtual const T2& value(
) const =0;
/*!
ensures
- returns a const reference to the value associated with key
!*/
virtual T2& value(
)=0;
/*!
ensures
- returns a non-const reference to the value associated with key
!*/
protected:
// restricted functions
map_pair<T1,T2>& operator=(const map_pair<T1,T2>&) {return *this;} // no assignment operator
};
// destructor does nothing
template <typename T1,typename T2>
map_pair<T1,T2>::~map_pair () {}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_MAP_PAIr_INTERFACE_

View File

@@ -0,0 +1,220 @@
// Copyright (C) 2005 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_REMOVER_KERNEl_INTERFACE_
#define DLIB_REMOVER_KERNEl_INTERFACE_
#include <functional>
namespace dlib
{
template <
typename T
>
class remover
{
/*!
REQUIREMENTS ON T
T is swappable by a global swap() and
T must have a default constructor
POINTERS AND REFERENCES TO INTERNAL DATA
The size() function does not invalidate pointers or
references to internal data. All other functions have no such
guarantee.
WHAT THIS OBJECT REPRESENTS
This object represents some generalized interface for removing
single items from container classes.
!*/
public:
typedef T type;
virtual ~remover(
);
/*!
ensures
- all resources associated with *this have been released.
!*/
virtual void remove_any (
T& item
) = 0;
/*!
requires
- size() != 0
ensures
- #size() == size() - 1
- removes an element from *this and swaps it into item.
- if (*this implements the enumerable interface) then
- #at_start() == true
!*/
virtual size_t size (
) const = 0;
/*!
ensures
- returns the number of elements in *this
!*/
protected:
// restricted functions
remover& operator=(const remover&) {return *this;} // assignment operator
};
// ----------------------------------------------------------------------------------------
template <
typename T,
typename compare
>
class asc_remover : public remover<T>
{
/*!
REQUIREMENTS ON T
T is swappable by a global swap() and
T must have a default constructor and
T must be comparable by compare where compare is a functor compatible with std::less
WHAT THIS OBJECT REPRESENTS
This object represents the same thing as remover except
that remove_any() will remove elements in ascending order
according to the compare functor.
!*/
public:
typedef compare compare_type;
protected:
// restricted functions
asc_remover& operator=(const asc_remover&) {return *this;} // assignment operator
};
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range
>
class pair_remover
{
/*!
REQUIREMENTS ON domain
domain is swappable by a global swap() and
domain must have a default constructor
REQUIREMENTS ON range
range is swappable by a global swap() and
range must have a default constructor
POINTERS AND REFERENCES TO INTERNAL DATA
The size() function does not invalidate pointers or
references to internal data. All other functions have no such
guarantee.
WHAT THIS OBJECT REPRESENTS
This object represents some generalized interface for removing
pairs from container classes which enforce some kind of pairing on
the elements that they contain.
!*/
public:
typedef domain domain_type;
typedef range range_type;
virtual ~pair_remover(
);
/*!
ensures
- all resources associated with *this have been released.
!*/
virtual void remove_any (
domain& d,
range& r
) = 0;
/*!
requires
- &d != &r (i.e. d and r cannot be the same variable)
- size() != 0
ensures
- #size() == size() - 1
- removes an element from the domain of *this and swaps it
into d.
- removes the element in *this's range that is associated
with #d and swaps it into r.
- if (*this implements the enumerable interface) then
- #at_start() == true
!*/
virtual size_t size (
) const = 0;
/*!
ensures
- returns the number of elements in *this
!*/
protected:
// restricted functions
pair_remover& operator=(const pair_remover&) {return *this;} // assignment operator
};
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename compare
>
class asc_pair_remover : public pair_remover<domain,range>
{
/*!
REQUIREMENTS ON domain
domain is swappable by a global swap() and
domain must have a default constructor and
domain must be comparable by compare where compare is a functor compatible with std::less
REQUIREMENTS ON range
range is swappable by a global swap() and
range must have a default constructor
WHAT THIS OBJECT REPRESENTS
This object represents the same thing as pair_remover except
that remove_any() will remove domain elements in ascending
order according to the compare functor.
!*/
public:
typedef compare compare_type;
protected:
// restricted functions
asc_pair_remover& operator=(const asc_pair_remover&) {return *this;} // assignment operator
};
// ----------------------------------------------------------------------------------------
// destructor does nothing
template <typename T>
remover<T>::~remover() {}
// destructor does nothing
template <typename domain, typename range>
pair_remover<domain,range>::~pair_remover() {}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_REMOVER_KERNEl_INTERFACE_