Commit 754da0ef authored by Davis King's avatar Davis King
Browse files

Properly organized the svn repository. Finally.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402199
parent 49388714
// Copyright (C) 2006 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_ARRAY2D_KERNEl_ABSTRACT_
#ifdef DLIB_ARRAY2D_KERNEl_ABSTRACT_
#include "../interfaces/enumerable.h"
#include "../serialize.h"
#include "../memory_manager/memory_manager_kernel_abstract.h"
namespace dlib
{
template <
typename T,
typename mem_manager = memory_manager<char>::kernel_1a
>
class array2d : public enumerable<T>
{
/*!
REQUIREMENTS ON T
T 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
No member functions in this object will invalidate pointers
or references to internal data except for the set_size()
and clear() member functions.
INITIAL VALUE
nr() == 0
nc() == 0
ENUMERATION ORDER
The enumerator will iterate over the elements of the array starting
with row 0 and then proceeding to row 1 and so on. Each row will be
fully enumerated before proceeding on to the next row and the elements
in a row will be enumerated beginning with the 0th column, then the 1st
column and so on.
WHAT THIS OBJECT REPRESENTS
This object represents a 2-Dimensional array of objects of
type T.
!*/
public:
// ----------------------------------------
typedef T type;
typedef mem_manager mem_manager_type;
// ----------------------------------------
class row
{
/*!
POINTERS AND REFERENCES TO INTERNAL DATA
No member functions in this object will invalidate pointers
or references to internal data.
WHAT THIS OBJECT REPRESENTS
This object represents a row of Ts in an array2d object.
!*/
public:
long nc (
) const;
/*!
ensures
- returns the number of columns in this row
!*/
const T& operator[] (
long column
) const;
/*!
requires
- 0 <= column < nc()
ensures
- returns a const reference to the T in the given column
!*/
T& operator[] (
long column
);
/*!
requires
- 0 <= column < nc()
ensures
- returns a non-const reference to the T in the given column
!*/
private:
// restricted functions
row();
row(row&);
row& operator=(row&);
};
// ----------------------------------------
array2d (
);
/*!
ensures
- #*this is properly initialized
throws
- std::bad_alloc
!*/
virtual ~array2d (
);
/*!
ensures
- all resources associated with *this has been released
!*/
void clear (
);
/*!
ensures
- #*this has an initial value for its type
!*/
long nc (
) const;
/*!
ensures
- returns the number of elements there are in a row. i.e. returns
the number of columns in *this
!*/
long nr (
) const;
/*!
ensures
- returns the number of rows in *this
!*/
void set_size (
long rows,
long cols
);
/*!
requires
- cols > 0 && rows > 0 or
cols == 0 && rows == 0
ensures
- #nc() == cols
- #nr() == rows
- #at_start() == true
- if (the call to set_size() doesn't change the dimensions of this array) then
- all elements in this array retain their values from before this function was called
- else
- all elements in this array have initial values for their type
throws
- std::bad_alloc
If this exception is thrown then #*this will have an initial
value for its type.
!*/
row& operator[] (
long row_index
);
/*!
requires
- 0 <= row_index < nr()
ensures
- returns a non-const row of nc() elements that represents the
given row_index'th row in *this.
!*/
const row& operator[] (
long row_index
) const;
/*!
requires
- 0 <= row_index < nr()
ensures
- returns a const row of nc() elements that represents the
given row_index'th row in *this.
!*/
void swap (
array2d& item
);
/*!
ensures
- swaps *this and item
!*/
private:
// restricted functions
array2d(array2d&); // copy constructor
array2d& operator=(array2d&); // assignment operator
};
template <
typename T
>
inline void swap (
array2d<T>& a,
array2d<T>& b
) { a.swap(b); }
/*!
provides a global swap function
!*/
template <
typename T
>
void serialize (
const array2d<T>& item,
std::ostream& out
);
/*!
provides serialization support
!*/
template <
typename T
>
void deserialize (
array2d<T>& item,
std::istream& in
);
/*!
provides deserialization support
!*/
}
#endif // DLIB_ARRAY2D_KERNEl_ABSTRACT_
// Copyright (C) 2006 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY2D_KERNEl_C_
#define DLIB_ARRAY2D_KERNEl_C_
#include "array2d_kernel_abstract.h"
#include "../algs.h"
#include "../assert.h"
#include "../interfaces/enumerable.h"
namespace dlib
{
template <
typename array2d_base // is an implementation of array2d_kernel_abstract.h
>
class array2d_kernel_c : public enumerable<typename array2d_base::type>
{
/*!
CONVENTION
- if (obj.size() > 0) then
- rows == an array of size obj.nr() row objects and
each row object in the array has a valid pointer to its
associated row in obj.
- else
- rows == 0
!*/
typedef typename array2d_base::type T;
public:
typedef typename array2d_base::type type;
typedef typename array2d_base::mem_manager_type mem_manager_type;
// -----------------------------------
class row
{
friend class array2d_kernel_c;
public:
long nc (
) const { return data->nc(); }
const T& operator[] (
long column
) const;
T& operator[] (
long column
);
private:
typename array2d_base::row* data;
// restricted functions
row(){}
row(row&);
row& operator=(row&);
};
// -----------------------------------
array2d_kernel_c (
) :
rows(0)
{
}
virtual ~array2d_kernel_c (
) { clear(); }
long nc (
) const { return obj.nc(); }
long nr (
) const { return obj.nr(); }
row& operator[] (
long row
);
const row& operator[] (
long row
) const;
void swap (
array2d_kernel_c& item
)
{
exchange(obj,item.obj);
exchange(rows,item.rows);
}
void clear (
)
{
obj.clear();
if (rows != 0)
{
delete [] rows;
rows = 0;
}
}
void set_size (
long nr__,
long nc__
);
bool at_start (
) const { return obj.at_start();; }
void reset (
) const { obj.reset(); }
bool current_element_valid (
) const { return obj.current_element_valid(); }
const T& element (
) const;
T& element (
);
bool move_next (
) const { return obj.move_next(); }
unsigned long size (
) const { return obj.size(); }
private:
array2d_base obj;
row* rows;
};
template <
typename array2d_base
>
inline void swap (
array2d_kernel_c<array2d_base>& a,
array2d_kernel_c<array2d_base>& b
) { a.swap(b); }
template <
typename array2d_base
>
void serialize (
const array2d_kernel_c<array2d_base>& item,
std::ostream& out
)
{
try
{
serialize(item.nc(),out);
serialize(item.nr(),out);
item.reset();
while (item.move_next())
serialize(item.element(),out);
item.reset();
}
catch (serialization_error e)
{
throw serialization_error(e.info + "\n while serializing object of type array2d_kernel_c");
}
}
template <
typename array2d_base
>
void deserialize (
array2d_kernel_c<array2d_base>& item,
std::istream& in
)
{
try
{
long nc, nr;
deserialize(nc,in);
deserialize(nr,in);
item.set_size(nr,nc);
while (item.move_next())
deserialize(item.element(),in);
item.reset();
}
catch (serialization_error e)
{
item.clear();
throw serialization_error(e.info + "\n while deserializing object of type array2d_kernel_c");
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename array2d_base
>
const typename array2d_base::type& array2d_kernel_c<array2d_base>::
element (
) const
{
// make sure requires clause is not broken
DLIB_CASSERT(current_element_valid() == true,
"\tT& array2d::element()()"
<< "\n\tYou can only call element() when you are at a valid one."
<< "\n\tthis: " << this
);
return obj.element();
}
// ----------------------------------------------------------------------------------------
template <
typename array2d_base
>
typename array2d_base::type& array2d_kernel_c<array2d_base>::
element (
)
{
// make sure requires clause is not broken
DLIB_CASSERT(current_element_valid() == true,
"\tT& array2d::element()()"
<< "\n\tYou can only call element() when you are at a valid one."
<< "\n\tthis: " << this
);
return obj.element();
}
// ----------------------------------------------------------------------------------------
template <
typename array2d_base
>
void array2d_kernel_c<array2d_base>::
set_size (
long nr_,
long nc_
)
{
// make sure requires clause is not broken
DLIB_CASSERT(nc_ > 0 && nr_ > 0 ||
nc_ == 0 && nr_ == 0,
"\tvoid array2d::set_size(long nr_, long nc_)"
<< "\n\tYou have to give a non zero nc and nr or just make both zero."
<< "\n\tthis: " << this
<< "\n\tnc_: " << nc_
<< "\n\tnr_: " << nr_
);
obj.set_size(nr_,nc_);
// set up the rows array
if (rows != 0)
delete [] rows;
try
{
rows = new row[obj.nr()];
}
catch (...)
{
rows = 0;
obj.clear();
throw;
}
for (long i = 0; i < obj.nr(); ++i)
{
rows[i].data = &obj[i];
}
}
// ----------------------------------------------------------------------------------------
template <
typename array2d_base
>
typename array2d_kernel_c<array2d_base>::row& array2d_kernel_c<array2d_base>::
operator[] (
long row
)
{
// make sure requires clause is not broken
DLIB_CASSERT(row < nr() && row >= 0,
"\trow& array2d::operator[](long row)"
<< "\n\tThe row index given must be less than the number of rows."
<< "\n\tthis: " << this
<< "\n\trow: " << row
<< "\n\tnr(): " << nr()
);
return rows[row];
}
// ----------------------------------------------------------------------------------------
template <
typename array2d_base
>
const typename array2d_kernel_c<array2d_base>::row& array2d_kernel_c<array2d_base>::
operator[] (
long row
) const
{
// make sure requires clause is not broken
DLIB_CASSERT(row < nr() && row >= 0,
"\tconst row& array2d::operator[](long row) const"
<< "\n\tThe row index given must be less than the number of rows."
<< "\n\tthis: " << this
<< "\n\trow: " << row
<< "\n\tnr(): " << nr()
);
return rows[row];
}
// ----------------------------------------------------------------------------------------
template <
typename array2d_base
>
const typename array2d_base::type& array2d_kernel_c<array2d_base>::row::
operator[] (
long column
) const
{
// make sure requires clause is not broken
DLIB_CASSERT(column < nc() && column >= 0,
"\tconst T& array2d::operator[](long column) const"
<< "\n\tThe column index given must be less than the number of columns."
<< "\n\tthis: " << this
<< "\n\tcolumn: " << column
<< "\n\tnc(): " << nc()
);
return (*data)[column];
}
// ----------------------------------------------------------------------------------------
template <
typename array2d_base
>
typename array2d_base::type& array2d_kernel_c<array2d_base>::row::
operator[] (
long column
)
{
// make sure requires clause is not broken
DLIB_CASSERT(column < nc() && column >= 0,
"\tT& array2d::operator[](long column)"
<< "\n\tThe column index given must be less than the number of columns."
<< "\n\tthis: " << this
<< "\n\tcolumn: " << column
<< "\n\tnc(): " << nc()
);
return (*data)[column];
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY2D_KERNEl_C_
// Copyright (C) 2003 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ASSERt_
#define DLIB_ASSERt_
#include <sstream>
#include <iosfwd>
#include "error.h"
// -----------------------------
// Use some stuff from boost here
// (C) Copyright John Maddock 2001 - 2003.
// (C) Copyright Darin Adler 2001.
// (C) Copyright Peter Dimov 2001.
// (C) Copyright Bill Kempf 2002.
// (C) Copyright Jens Maurer 2002.
// (C) Copyright David Abrahams 2002 - 2003.
// (C) Copyright Gennaro Prota 2003.
// (C) Copyright Eric Friedman 2003.
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef BOOST_JOIN
#define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y )
#define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y)
#define BOOST_DO_JOIN2( X, Y ) X##Y
#endif
// -----------------------------
namespace dlib
{
template <bool value> struct compile_time_assert;
template <> struct compile_time_assert<true> { enum {value=1}; };
template <typename T, typename U> struct assert_are_same_type;
template <typename T> struct assert_are_same_type<T,T> {enum{value=1};};
template <typename T, typename U> struct assert_are_not_same_type {enum{value=1}; };
template <typename T> struct assert_are_not_same_type<T,T> {};
}
#define COMPILE_TIME_ASSERT(expression) \
typedef char BOOST_JOIN(DLIB_CTA, __LINE__)[::dlib::compile_time_assert<(bool)(expression)>::value]
#define ASSERT_ARE_SAME_TYPE(type1, type2) \
typedef char BOOST_JOIN(DLIB_AAST, __LINE__)[::dlib::assert_are_same_type<type1,type2>::value]
#define ASSERT_ARE_NOT_SAME_TYPE(type1, type2) \
typedef char BOOST_JOIN(DLIB_AANST, __LINE__)[::dlib::assert_are_not_same_type<type1,type2>::value]
// -----------------------------
#if defined DEBUG || defined _DEBUG
// make sure ENABLE_ASSERTS is defined if we are indeed using them.
#ifndef ENABLE_ASSERTS
#define ENABLE_ASSERTS
#endif
#endif
// -----------------------------
#ifdef __GNUC__
#define DLIB_FUNCTION_NAME __PRETTY_FUNCTION__
#elif _MSC_VER
#define DLIB_FUNCTION_NAME __FUNCSIG__
#else
#define DLIB_FUNCTION_NAME "unknown function"
#endif
#define DLIB_CASSERT(_exp,_message) \
{if ( !(_exp) ) \
{ \
std::ostringstream dlib__out; \
dlib__out << "\n\nError occurred at line " << __LINE__ << ".\n"; \
dlib__out << "Error occurred in file " << __FILE__ << ".\n"; \
dlib__out << "Error occurred in function " << DLIB_FUNCTION_NAME << ".\n\n"; \
dlib__out << "Failing expression was " << #_exp << ".\n"; \
dlib__out << _message << "\n"; \
dlib_assert_breakpoint(); \
throw dlib::fatal_error(dlib::EBROKEN_ASSERT,dlib__out.str()); \
}}
#ifdef ENABLE_ASSERTS
#define DLIB_ASSERT(_exp,_message) DLIB_CASSERT(_exp,_message)
#else
#define DLIB_ASSERT(_exp,_message)
#endif
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// breakpoints
extern "C"
{
inline void dlib_assert_breakpoint(
) {}
/*!
ensures
- this function does nothing
It exists just so you can put breakpoints on it in a debugging tool.
It is called only when an DLIB_ASSERT or DLIB_CASSERT fails and is about to
throw an exception.
!*/
}
// -----------------------------
#endif // DLIB_ASSERt_
// Copyright (C) 2006 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_BASe64_
#define DLIB_BASe64_
#include "base64/base64_kernel_1.h"
namespace dlib
{
class base64
{
base64() {}
public:
//----------- kernels ---------------
// kernel_1a
typedef base64_kernel_1
kernel_1a;
};
}
#endif // DLIB_BASe64_
// Copyright (C) 2006 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_BASE64_KERNEL_1_CPp_
#define DLIB_BASE64_KERNEL_1_CPp_
#include "base64_kernel_1.h"
#include <iostream>
#include <sstream>
#include <climits>
namespace dlib
{
// ----------------------------------------------------------------------------------------
base64_kernel_1::
base64_kernel_1 (
) :
encode_table(0),
decode_table(0),
bad_value(100)
{
try
{
encode_table = new char[64];
decode_table = new unsigned char[UCHAR_MAX];
}
catch (...)
{
if (encode_table) delete [] encode_table;
if (decode_table) delete [] decode_table;
throw;
}
// now set up the tables with the right stuff
encode_table[0] = 'A';
encode_table[17] = 'R';
encode_table[34] = 'i';
encode_table[51] = 'z';
encode_table[1] = 'B';
encode_table[18] = 'S';
encode_table[35] = 'j';
encode_table[52] = '0';
encode_table[2] = 'C';
encode_table[19] = 'T';
encode_table[36] = 'k';
encode_table[53] = '1';
encode_table[3] = 'D';
encode_table[20] = 'U';
encode_table[37] = 'l';
encode_table[54] = '2';
encode_table[4] = 'E';
encode_table[21] = 'V';
encode_table[38] = 'm';
encode_table[55] = '3';
encode_table[5] = 'F';
encode_table[22] = 'W';
encode_table[39] = 'n';
encode_table[56] = '4';
encode_table[6] = 'G';
encode_table[23] = 'X';
encode_table[40] = 'o';
encode_table[57] = '5';
encode_table[7] = 'H';
encode_table[24] = 'Y';
encode_table[41] = 'p';
encode_table[58] = '6';
encode_table[8] = 'I';
encode_table[25] = 'Z';
encode_table[42] = 'q';
encode_table[59] = '7';
encode_table[9] = 'J';
encode_table[26] = 'a';
encode_table[43] = 'r';
encode_table[60] = '8';
encode_table[10] = 'K';
encode_table[27] = 'b';
encode_table[44] = 's';
encode_table[61] = '9';
encode_table[11] = 'L';
encode_table[28] = 'c';
encode_table[45] = 't';
encode_table[62] = '+';
encode_table[12] = 'M';
encode_table[29] = 'd';
encode_table[46] = 'u';
encode_table[63] = '/';
encode_table[13] = 'N';
encode_table[30] = 'e';
encode_table[47] = 'v';
encode_table[14] = 'O';
encode_table[31] = 'f';
encode_table[48] = 'w';
encode_table[15] = 'P';
encode_table[32] = 'g';
encode_table[49] = 'x';
encode_table[16] = 'Q';
encode_table[33] = 'h';
encode_table[50] = 'y';
// we can now fill out the decode_table by using the encode_table
for (int i = 0; i < UCHAR_MAX; ++i)
{
decode_table[i] = bad_value;
}
for (unsigned char i = 0; i < 64; ++i)
{
decode_table[encode_table[i]] = i;
}
}
// ----------------------------------------------------------------------------------------
base64_kernel_1::
~base64_kernel_1 (
)
{
delete [] encode_table;
delete [] decode_table;
}
// ----------------------------------------------------------------------------------------
void base64_kernel_1::
encode (
std::istream& in_,
std::ostream& out_
) const
{
using namespace std;
streambuf& in = *in_.rdbuf();
streambuf& out = *out_.rdbuf();
unsigned char inbuf[3];
unsigned char outbuf[4];
streamsize status = in.sgetn(reinterpret_cast<char*>(&inbuf),3);
unsigned char c1, c2, c3, c4, c5, c6;
int counter = 19;
const char newline = '\n';
// while we haven't hit the end of the input stream
while (status != 0)
{
if (counter == 0)
{
counter = 19;
// write a newline
if (out.sputn(reinterpret_cast<const char*>(&newline),1)!=1)
{
throw std::ios_base::failure("error occured in the base64 object");
}
}
--counter;
if (status == 3)
{
// encode the bytes in inbuf to base64 and write them to the output stream
c1 = inbuf[0]&0xfc;
c2 = inbuf[0]&0x03;
c3 = inbuf[1]&0xf0;
c4 = inbuf[1]&0x0f;
c5 = inbuf[2]&0xc0;
c6 = inbuf[2]&0x3f;
outbuf[0] = c1>>2;
outbuf[1] = (c2<<4)|(c3>>4);
outbuf[2] = (c4<<2)|(c5>>6);
outbuf[3] = c6;
outbuf[0] = encode_table[outbuf[0]];
outbuf[1] = encode_table[outbuf[1]];
outbuf[2] = encode_table[outbuf[2]];
outbuf[3] = encode_table[outbuf[3]];
// write the encoded bytes to the output stream
if (out.sputn(reinterpret_cast<char*>(&outbuf),4)!=4)
{
throw std::ios_base::failure("error occured in the base64 object");
}
// get 3 more input bytes
status = in.sgetn(reinterpret_cast<char*>(&inbuf),3);
continue;
}
else if (status == 2)
{
// we are at the end of the input stream and need to add some padding
// encode the bytes in inbuf to base64 and write them to the output stream
c1 = inbuf[0]&0xfc;
c2 = inbuf[0]&0x03;
c3 = inbuf[1]&0xf0;
c4 = inbuf[1]&0x0f;
c5 = 0;
outbuf[0] = c1>>2;
outbuf[1] = (c2<<4)|(c3>>4);
outbuf[2] = (c4<<2)|(c5>>6);
outbuf[3] = '=';
outbuf[0] = encode_table[outbuf[0]];
outbuf[1] = encode_table[outbuf[1]];
outbuf[2] = encode_table[outbuf[2]];
// write the encoded bytes to the output stream
if (out.sputn(reinterpret_cast<char*>(&outbuf),4)!=4)
{
throw std::ios_base::failure("error occured in the base64 object");
}
break;
}
else // in this case status must be 1
{
// we are at the end of the input stream and need to add some padding
// encode the bytes in inbuf to base64 and write them to the output stream
c1 = inbuf[0]&0xfc;
c2 = inbuf[0]&0x03;
c3 = 0;
outbuf[0] = c1>>2;
outbuf[1] = (c2<<4)|(c3>>4);
outbuf[2] = '=';
outbuf[3] = '=';
outbuf[0] = encode_table[outbuf[0]];
outbuf[1] = encode_table[outbuf[1]];
// write the encoded bytes to the output stream
if (out.sputn(reinterpret_cast<char*>(&outbuf),4)!=4)
{
throw std::ios_base::failure("error occured in the base64 object");
}
break;
}
} // while (status != 0)
// make sure the stream buffer flushes to its I/O channel
out.pubsync();
}
// ----------------------------------------------------------------------------------------
void base64_kernel_1::
decode (
std::istream& in_,
std::ostream& out_
) const
{
using namespace std;
streambuf& in = *in_.rdbuf();
streambuf& out = *out_.rdbuf();
unsigned char inbuf[4];
unsigned char outbuf[3];
int inbuf_pos = 0;
streamsize status = in.sgetn(reinterpret_cast<char*>(inbuf),1);
// only count this character if it isn't some kind of filler
if (status == 1 && decode_table[inbuf[0]] != bad_value )
++inbuf_pos;
unsigned char c1, c2, c3, c4, c5, c6;
streamsize outsize;
// while we haven't hit the end of the input stream
while (status != 0)
{
// if we have 4 valid characters
if (inbuf_pos == 4)
{
inbuf_pos = 0;
// this might be the end of the encoded data so we need to figure out if
// there was any padding applied.
outsize = 3;
if (inbuf[3] == '=')
{
if (inbuf[2] == '=')
outsize = 1;
else
outsize = 2;
}
// decode the incoming characters
inbuf[0] = decode_table[inbuf[0]];
inbuf[1] = decode_table[inbuf[1]];
inbuf[2] = decode_table[inbuf[2]];
inbuf[3] = decode_table[inbuf[3]];
// now pack these guys into bytes rather than 6 bit chunks
c1 = inbuf[0]<<2;
c2 = inbuf[1]>>4;
c3 = inbuf[1]<<4;
c4 = inbuf[2]>>2;
c5 = inbuf[2]<<6;
c6 = inbuf[3];
outbuf[0] = c1|c2;
outbuf[1] = c3|c4;
outbuf[2] = c5|c6;
// write the encoded bytes to the output stream
if (out.sputn(reinterpret_cast<char*>(&outbuf),outsize)!=outsize)
{
throw std::ios_base::failure("error occured in the base64 object");
}
}
// get more input characters
status = in.sgetn(reinterpret_cast<char*>(inbuf + inbuf_pos),1);
// only count this character if it isn't some kind of filler
if ((decode_table[inbuf[inbuf_pos]] != bad_value || inbuf[inbuf_pos] == '=') &&
status != 0)
++inbuf_pos;
} // while (status != 0)
if (inbuf_pos != 0)
{
ostringstream sout;
sout << inbuf_pos << " extra characters were found at the end of the encoded data."
<< " This may indicate that the data stream has been truncated.";
// this happens if we hit EOF in the middle of decoding a 24bit block.
throw decode_error(sout.str());
}
// make sure the stream buffer flushes to its I/O channel
out.pubsync();
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_BASE64_KERNEL_1_CPp_
// Copyright (C) 2006 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_BASE64_KERNEl_1_
#define DLIB_BASE64_KERNEl_1_
#include "../algs.h"
#include <iosfwd>
namespace dlib
{
class base64_kernel_1
{
/*!
INITIAL VALUE
- bad_value == 100
- encode_table == a pointer to an array of 64 chars
- where x is a 6 bit value the following is true:
- encode_table[x] == the base64 encoding of x
- decode_table == a pointer to an array of UCHAR_MAX chars
- where x is any char value:
- if (x is a valid character in the base64 coding scheme) then
- decode_table[x] == the 6 bit value that x encodes
- else
- decode_table[x] == bad_value
CONVENTION
- The state of this object never changes so just refer to its
initial value.
!*/
public:
class decode_error : public dlib::error { public:
decode_error( const std::string& e) : error(e) {}};
base64_kernel_1 (
);
virtual ~base64_kernel_1 (
);
void encode (
std::istream& in,
std::ostream& out
) const;
void decode (
std::istream& in,
std::ostream& out
) const;
private:
char* encode_table;
unsigned char* decode_table;
const unsigned char bad_value;
// restricted functions
base64_kernel_1(base64_kernel_1&); // copy constructor
base64_kernel_1& operator=(base64_kernel_1&); // assignment operator
};
}
#ifdef NO_MAKEFILE
#include "base64_kernel_1.cpp"
#endif
#endif // DLIB_BASE64_KERNEl_1_
// Copyright (C) 2006 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_BASE64_KERNEl_ABSTRACT_
#ifdef DLIB_BASE64_KERNEl_ABSTRACT_
#include "../algs.h"
#include <iosfwd>
namespace dlib
{
class base64
{
/*!
INITIAL VALUE
This object does not have any state associated with it.
WHAT THIS OBJECT REPRESENTS
This object consists of the two functions encode and decode.
These functions allow you to encode and decode data to and from
the Base64 Content-Transfer-Encoding defined in section 6.8 of
rfc2045.
!*/
public:
class decode_error : public dlib::error {};
base64 (
);
/*!
ensures
- #*this is properly initialized
throws
- std::bad_alloc
!*/
virtual ~base64 (
);
/*!
ensures
- all memory associated with *this has been released
!*/
void encode (
std::istream& in,
std::ostream& out
) const;
/*!
ensures
- reads all data from in (until EOF is reached) and encodes it
and writes it to out
throws
- std::ios_base::failure
if there was a problem writing to out then this exception will
be thrown.
- any other exception
this exception may be thrown if there is any other problem
!*/
void decode (
std::istream& in,
std::ostream& out
) const;
/*!
ensures
- reads data from in (until EOF is reached) and decodees it
and writes it to out.
throws
- std::ios_base::failure
if there was a problem writing to out then this exception will
be thrown.
- decode_error
if an error was detected in the encoded data that prevented
it from being correctly decoded then this exception is
thrown.
- any other exception
this exception may be thrown if there is any other problem
!*/
private:
// restricted functions
base64(base64&); // copy constructor
base64& operator=(base64&); // assignment operator
};
}
#endif // DLIB_BASE64_KERNEl_ABSTRACT_
// Copyright (C) 2007 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_BAYES_UTILs_H_
#define DLIB_BAYES_UTILs_H_
#include "bayes_utils/bayes_utils.h"
#endif // DLIB_BAYES_UTILs_H_
This diff is collapsed.
This diff is collapsed.
// Copyright (C) 2003 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_BIGINt_
#define DLIB_BIGINt_
#include "bigint/bigint_kernel_1.h"
#include "bigint/bigint_kernel_2.h"
#include "bigint/bigint_kernel_c.h"
namespace dlib
{
class bigint
{
bigint() {}
public:
//----------- kernels ---------------
// kernel_1a
typedef bigint_kernel_1
kernel_1a;
typedef bigint_kernel_c<kernel_1a>
kernel_1a_c;
// kernel_2a
typedef bigint_kernel_2
kernel_2a;
typedef bigint_kernel_c<kernel_2a>
kernel_2a_c;
};
}
#endif // DLIB_BIGINt_
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Copyright (C) 2003 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_BINARY_SEARCH_TREe_
#define DLIB_BINARY_SEARCH_TREe_
#include "binary_search_tree/binary_search_tree_kernel_1.h"
#include "binary_search_tree/binary_search_tree_kernel_2.h"
#include "binary_search_tree/binary_search_tree_kernel_c.h"
#include "memory_manager.h"
#include <functional>
namespace dlib
{
template <
typename domain,
typename range,
typename mem_manager = memory_manager<char>::kernel_1a,
typename compare = std::less<domain>
>
class binary_search_tree
{
binary_search_tree() {}
public:
//----------- kernels ---------------
// kernel_1a
typedef binary_search_tree_kernel_1<domain,range,mem_manager,compare>
kernel_1a;
typedef binary_search_tree_kernel_c<kernel_1a>
kernel_1a_c;
// kernel_2a
typedef binary_search_tree_kernel_2<domain,range,mem_manager,compare>
kernel_2a;
typedef binary_search_tree_kernel_c<kernel_2a>
kernel_2a_c;
};
}
#endif // DLIB_BINARY_SEARCH_TREe_
This diff is collapsed.
This diff is collapsed.
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