Lesson 35 - Get Compute Auth Token Working

This commit is contained in:
Norman Lansing
2026-02-28 12:32:28 -05:00
parent 1d477ee42a
commit 4fde462bce
7743 changed files with 1397833 additions and 18 deletions

View File

@@ -0,0 +1,436 @@
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_MAP_KERNEl_1_
#define DLIB_MAP_KERNEl_1_
#include "map_kernel_abstract.h"
#include "../algs.h"
#include "../interfaces/enumerable.h"
#include "../interfaces/map_pair.h"
#include "../interfaces/remover.h"
#include "../serialize.h"
namespace dlib
{
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager = default_memory_manager
>
class map_kernel_1 : public enumerable<map_pair<domain,range> >,
public asc_pair_remover<domain,range,typename bst_base::compare_type>
{
/*!
REQUIREMENTS ON BST_BASE
bst_base is instantiated with domain and range and
implements binary_search_tree/binary_search_tree_kernel_abstract.h
INITIAL VALUE
bst has its initial value
CONVENTION
bst.size() == the number of elements in the map and
the elements in map are stored in bst_base
!*/
public:
typedef domain domain_type;
typedef range range_type;
typedef typename bst_base::compare_type compare_type;
typedef mem_manager mem_manager_type;
map_kernel_1(
)
{}
virtual ~map_kernel_1(
)
{}
inline void clear(
);
inline void add (
domain& d,
range& r
);
inline bool is_in_domain (
const domain& d
) const;
inline void remove_any (
domain& d,
range& r
);
inline void remove (
const domain& d,
domain& d_copy,
range& r
);
inline void destroy (
const domain& d
);
inline range& operator[] (
const domain& d
);
inline const range& operator[] (
const domain& d
) const;
inline void swap (
map_kernel_1& item
);
// functions from the enumerable interface
inline size_t size (
) const;
inline bool at_start (
) const;
inline void reset (
) const;
inline bool current_element_valid (
) const;
inline const map_pair<domain,range>& element (
) const;
inline map_pair<domain,range>& element (
);
inline bool move_next (
) const;
private:
bst_base bst;
// restricted functions
map_kernel_1(map_kernel_1&);
map_kernel_1& operator= ( map_kernel_1&);
};
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
inline void swap (
map_kernel_1<domain,range,bst_base,mem_manager>& a,
map_kernel_1<domain,range,bst_base,mem_manager>& b
) { a.swap(b); }
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
void deserialize (
map_kernel_1<domain,range,bst_base,mem_manager>& item,
std::istream& in
)
{
try
{
item.clear();
unsigned long size;
deserialize(size,in);
domain d;
range r;
for (unsigned long i = 0; i < size; ++i)
{
deserialize(d,in);
deserialize(r,in);
item.add(d,r);
}
}
catch (serialization_error& e)
{
item.clear();
throw serialization_error(e.info + "\n while deserializing object of type map_kernel_1");
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
void map_kernel_1<domain,range,bst_base,mem_manager>::
clear (
)
{
bst.clear();
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
void map_kernel_1<domain,range,bst_base,mem_manager>::
add(
domain& d,
range& r
)
{
// try to add pair to bst_base
bst.add(d,r);
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
bool map_kernel_1<domain,range,bst_base,mem_manager>::
is_in_domain(
const domain& d
) const
{
return (bst[d] != 0);
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
void map_kernel_1<domain,range,bst_base,mem_manager>::
remove_any(
domain& d,
range& r
)
{
bst.remove_any(d,r);
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
void map_kernel_1<domain,range,bst_base,mem_manager>::
remove (
const domain& d,
domain& d_copy,
range& r
)
{
bst.remove(d,d_copy,r);
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
void map_kernel_1<domain,range,bst_base,mem_manager>::
destroy (
const domain& d
)
{
bst.destroy(d);
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
range& map_kernel_1<domain,range,bst_base,mem_manager>::
operator[](
const domain& d
)
{
return *bst[d];
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
const range& map_kernel_1<domain,range,bst_base,mem_manager>::
operator[](
const domain& d
) const
{
return *bst[d];
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
size_t map_kernel_1<domain,range,bst_base,mem_manager>::
size (
) const
{
return bst.size();
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
void map_kernel_1<domain,range,bst_base,mem_manager>::
swap (
map_kernel_1<domain,range,bst_base,mem_manager>& item
)
{
bst.swap(item.bst);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// enumerable function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
bool map_kernel_1<domain,range,bst_base,mem_manager>::
at_start (
) const
{
return bst.at_start();
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
void map_kernel_1<domain,range,bst_base,mem_manager>::
reset (
) const
{
bst.reset();
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
bool map_kernel_1<domain,range,bst_base,mem_manager>::
current_element_valid (
) const
{
return bst.current_element_valid();
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
const map_pair<domain,range>& map_kernel_1<domain,range,bst_base,mem_manager>::
element (
) const
{
return bst.element();
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
map_pair<domain,range>& map_kernel_1<domain,range,bst_base,mem_manager>::
element (
)
{
return bst.element();
}
// ----------------------------------------------------------------------------------------
template <
typename domain,
typename range,
typename bst_base,
typename mem_manager
>
bool map_kernel_1<domain,range,bst_base,mem_manager>::
move_next (
) const
{
return bst.move_next();
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_MAP_KERNEl_1_

View File

@@ -0,0 +1,235 @@
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_MAP_KERNEl_ABSTRACT_
#ifdef DLIB_MAP_KERNEl_ABSTRACT_
#include "../interfaces/map_pair.h"
#include "../interfaces/enumerable.h"
#include "../interfaces/remover.h"
#include "../serialize.h"
#include "../algs.h"
#include <functional>
namespace dlib
{
template <
typename domain,
typename range,
typename mem_manager = default_memory_manager,
typename compare = std::less<domain>
>
class map : public enumerable<map_pair<domain,range> >,
public asc_pair_remover<domain,range,compare>
{
/*!
REQUIREMENTS ON domain
domain must be comparable by compare where compare is a functor compatible with std::less and
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
REQUIREMENTS ON mem_manager
must be an implementation of memory_manager/memory_manager_kernel_abstract.h or
must be an implementation of memory_manager_global/memory_manager_global_kernel_abstract.h or
must be an implementation of memory_manager_stateless/memory_manager_stateless_kernel_abstract.h
mem_manager::type can be set to anything.
POINTERS AND REFERENCES TO INTERNAL DATA
swap(), is_in_domain(), and operator[] functions do not invalidate
pointers or references to internal data.
All other functions have no such guarantee.
INITIAL VALUE
size() == 0
ENUMERATION ORDER
The enumerator will iterate over the domain (and each associated
range element) elements in ascending order according to the compare functor.
(i.e. the elements are enumerated in sorted order)
WHAT THIS OBJECT REPRESENTS
map contains items of type domain and range
This object is similar an array. It maps items of type domain on to
items of type range.
Also note that unless specified otherwise, no member functions
of this object throw exceptions.
definition of equivalent:
a is equivalent to b if
a < b == false and
b < a == false
!*/
public:
typedef domain domain_type;
typedef range range_type;
typedef compare compare_type;
typedef mem_manager mem_manager_type;
map(
);
/*!
ensures
- #*this is properly initialized
throws
- std::bad_alloc or any exception thrown by domain's or range's
constructor.
!*/
virtual ~map(
);
/*!
ensures
- all memory associated with *this has been released
!*/
void clear(
);
/*!
ensures
- #*this has its initial value
throws
- std::bad_alloc or any exception thrown by domain's or range's
constructor.
if this exception is thrown then *this is unusable
until clear() is called and succeeds
!*/
void add (
domain& d,
range& r
);
/*!
requires
- &d != &r (i.e. d and r cannot be the same variable)
- is_in_domain(d) == false
ensures
- #is_in_domain(d) == true
- #operator[](d) == r
- #d and #r have initial values for their types
- #size() == size() + 1
- #at_start() == true
throws
- std::bad_alloc or any exception thrown by domain's or range's
constructor.
if add() throws then it has no effect
!*/
bool is_in_domain (
const domain& d
) const;
/*!
ensures
- returns whether or not an element equivalent to d is in the
domain of *this
!*/
void remove (
const domain& d,
domain& d_copy,
range& r
);
/*!
requires
- &d != &r (i.e. d and r cannot be the same variable)
- &d != &d_copy (i.e. d and d_copy cannot be the same variable)
- &r != &d_copy (i.e. r and d_copy cannot be the same variable)
- is_in_domain(d) == true
ensures
- #is_in_domain(d) == false
- #d_copy is equivalent to d
- the element in the range of *this associated with #d_copy has been
swapped into #r
- #size() == size() - 1
- #at_start() == true
!*/
void destroy (
const domain& d
);
/*!
requires
- is_in_domain(d) == true
ensures
- #is_in_domain(d) == false
- #size() == size() - 1
- #at_start() == true
!*/
range& operator[] (
const domain& d
);
/*!
requires
- is_in_domain(d) == true
ensures
- returns a non-const reference to the element in the range of *this
associated with the element equivalent to d
!*/
const range& operator[] (
const domain& d
) const;
/*!
requires
- is_in_domain(d) == true
ensures
- returns a const reference to the element in the range of *this
associated with the element equivalent to d
!*/
void swap (
map& item
);
/*!
ensures
- swaps *this and item
!*/
private:
// restricted functions
map(map&); // copy constructor
map& operator=(map&); // assignment operator
};
template <
typename domain,
typename range,
typename mem_manager,
typename compare
>
inline void swap (
map<domain,range,mem_manager,compare>& a,
map<domain,range,mem_manager,compare>& b
) { a.swap(b); }
/*!
provides a global swap function
!*/
template <
typename domain,
typename range,
typename mem_manager,
typename compare
>
void deserialize (
map<domain,range,mem_manager,compare>& item,
std::istream& in
);
/*!
provides deserialization support
!*/
}
#endif // DLIB_MAP_KERNEl_ABSTRACT_

View File

@@ -0,0 +1,248 @@
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_MAP_KERNEl_C_
#define DLIB_MAP_KERNEl_C_
#include "map_kernel_abstract.h"
#include "../algs.h"
#include "../assert.h"
#include "../interfaces/map_pair.h"
namespace dlib
{
template <
typename map_base
>
class map_kernel_c : public map_base
{
typedef typename map_base::domain_type domain;
typedef typename map_base::range_type range;
public:
void add (
domain& d,
range& r
);
void remove_any (
domain& d,
range& r
);
void remove (
const domain& d,
domain& d_copy,
range& r
);
void destroy (
const domain& d
);
range& operator[] (
const domain& d
);
const range& operator[] (
const domain& d
) const;
const map_pair<domain,range>& element (
) const
{
// make sure requires clause is not broken
DLIB_CASSERT(this->current_element_valid() == true,
"\tconst map_pair<domain,range>& map::element"
<< "\n\tyou can't access the current element if it doesn't exist"
<< "\n\tthis: " << this
);
// call the real function
return map_base::element();
}
map_pair<domain,range>& element (
)
{
// make sure requires clause is not broken
DLIB_CASSERT(this->current_element_valid() == true,
"\tmap_pair<domain,range>& map::element"
<< "\n\tyou can't access the current element if it doesn't exist"
<< "\n\tthis: " << this
);
// call the real function
return map_base::element();
}
};
template <
typename map_base
>
inline void swap (
map_kernel_c<map_base>& a,
map_kernel_c<map_base>& b
) { a.swap(b); }
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename map_base
>
void map_kernel_c<map_base>::
add (
domain& d,
range& r
)
{
// make sure requires clause is not broken
DLIB_CASSERT( (!this->is_in_domain(d)) &&
(static_cast<void*>(&d) != static_cast<void*>(&r)),
"\tvoid map::add"
<< "\n\tdomain element being added must not already be in the map"
<< "\n\tand d and r must not be the same variable"
<< "\n\tis_in_domain(d): " << (this->is_in_domain(d) ? "true" : "false")
<< "\n\tthis: " << this
<< "\n\t&d: " << static_cast<void*>(&d)
<< "\n\t&r: " << static_cast<void*>(&r)
);
// call the real function
map_base::add(d,r);
}
// ----------------------------------------------------------------------------------------
template <
typename map_base
>
void map_kernel_c<map_base>::
remove_any (
domain& d,
range& r
)
{
// make sure requires clause is not broken
DLIB_CASSERT( (this->size() > 0) &&
(static_cast<void*>(&d) != static_cast<void*>(&r)),
"\tvoid map::remove_any"
<< "\n\tsize() must be greater than zero if something is going to be removed"
<< "\n\tand d and r must not be the same variable."
<< "\n\tsize(): " << this->size()
<< "\n\tthis: " << this
<< "\n\t&d: " << static_cast<void*>(&d)
<< "\n\t&r: " << static_cast<void*>(&r)
);
// call the real function
map_base::remove_any(d,r);
}
// ----------------------------------------------------------------------------------------
template <
typename map_base
>
void map_kernel_c<map_base>::
remove (
const domain& d,
domain& d_copy,
range& r
)
{
// make sure requires clause is not broken
DLIB_CASSERT( (this->is_in_domain(d)) &&
(static_cast<const void*>(&d) != static_cast<void*>(&r)) &&
(static_cast<void*>(&r) != static_cast<void*>(&d_copy)) &&
(static_cast<const void*>(&d) != static_cast<void*>(&d_copy)),
"\tvoid map::remove"
<< "\n\tcan't remove something that isn't in the map or if the paremeters actually"
<< "\n\tare the same variable. Either way can't remove."
<< "\n\tis_in_domain(d): " << (this->is_in_domain(d) ? "true" : "false")
<< "\n\tthis: " << this
<< "\n\t&d: " << static_cast<const void*>(&d)
<< "\n\t&r: " << static_cast<void*>(&r)
<< "\n\t&d_copy: " << static_cast<void*>(&d_copy)
);
// call the real function
map_base::remove(d,d_copy,r);
}
// ----------------------------------------------------------------------------------------
template <
typename map_base
>
void map_kernel_c<map_base>::
destroy (
const domain& d
)
{
// make sure requires clause is not broken
DLIB_CASSERT(this->is_in_domain(d),
"\tvoid map::destroy"
<< "\n\tcan't remove something that isn't in the map"
<< "\n\tthis: " << this
<< "\n\t&d: " << static_cast<const void*>(&d)
);
// call the real function
map_base::destroy(d);
}
// ----------------------------------------------------------------------------------------
template <
typename map_base
>
typename map_base::range_type& map_kernel_c<map_base>::
operator[] (
const domain& d
)
{
// make sure requires clause is not broken
DLIB_CASSERT( this->is_in_domain(d),
"\trange& map::operator[]"
<< "\n\td must be in the domain of the map"
<< "\n\tthis: " << this
);
// call the real function
return map_base::operator[](d);
}
// ----------------------------------------------------------------------------------------
template <
typename map_base
>
const typename map_base::range_type& map_kernel_c<map_base>::
operator[] (
const domain& d
) const
{
// make sure requires clause is not broken
DLIB_CASSERT( this->is_in_domain(d),
"\tconst range& map::operator[]"
<< "\n\td must be in the domain of the map"
<< "\n\tthis: " << this
);
// call the real function
return map_base::operator[](d);
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_MAP_KERNEl_C_