"sgl-kernel/git@developer.sourcefind.cn:change/sglang.git" did not exist on "36a6b8dbfcd0fefd38e4391a93b2c496a3d77ccf"
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
#
# This is a CMake makefile. You can find the cmake utility and
# information about it at http://www.cmake.org
#
# setting this makes CMake allow normal looking IF ELSE statements
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
# make macros that can add #define directives to the entire project. Not just
# to the dlib library itself. I.e. to dlib and to any projects that depend
# on dlib.
MACRO ( add_global_define def_name )
if (NOT CMAKE_CXX_FLAGS MATCHES "-D${def_name}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${def_name}"
CACHE STRING "Flags used by the compiler during all C++ builds."
FORCE)
endif ()
ENDMACRO()
MACRO ( remove_global_define def_name )
if (CMAKE_CXX_FLAGS MATCHES " -D${def_name}")
string (REGEX REPLACE " -D${def_name}" "" temp_var ${CMAKE_CXX_FLAGS})
set (CMAKE_CXX_FLAGS "${temp_var}"
CACHE STRING "Flags used by the compiler during all C++ builds."
FORCE)
endif ()
ENDMACRO()
# Make sure ENABLE_ASSERTS is defined for debug builds
if (NOT CMAKE_CXX_FLAGS_DEBUG MATCHES "-DENABLE_ASSERTS")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DENABLE_ASSERTS"
CACHE STRING "Flags used by the compiler during C++ debug builds."
FORCE)
endif ()
set (DLIB_ISO_CPP_ONLY_STR
"Enable this if you don't want to compile any non-ISO C++ code (i.e. you don't use any of the API Wrappers)" )
set (DLIB_NO_GUI_SUPPORT_STR
"Enable this if you don't want to compile any of the dlib GUI code" )
OPTION(DLIB_ISO_CPP_ONLY ${DLIB_ISO_CPP_ONLY_STR} OFF)
OPTION(DLIB_NO_GUI_SUPPORT ${DLIB_NO_GUI_SUPPORT_STR} OFF)
add_library(dlib all/source.cpp )
IF (NOT DLIB_ISO_CPP_ONLY)
# we want to link to the right stuff depending on our platform.
IF (WIN32) ###############################################################################
if (DLIB_NO_GUI_SUPPORT)
set (dlib_needed_libraries ws2_32)
else()
set (dlib_needed_libraries ws2_32 comctl32 gdi32)
endif()
ELSEIF(APPLE) ############################################################################
FIND_LIBRARY(pthreadlib pthread)
set (dlib_needed_libraries ${pthreadlib})
if (NOT DLIB_NO_GUI_SUPPORT)
FIND_LIBRARY(xlib X11)
# make sure X11 is in the include path
FIND_PATH(xlib_path Xlib.h
PATHS
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include
PATH_SUFFIXES X11
)
if (xlib AND xlib_path)
GET_FILENAME_COMPONENT(x11_path ${xlib_path} PATH CACHE)
INCLUDE_DIRECTORIES(${x11_path})
set(dlib_needed_libraries ${dlib_needed_libraries} ${xlib} )
else()
message(" ***********************************************************************************")
message(" ****** DLIB GUI SUPPORT DISABLED BECAUSE X11 DEVELOPMENT LIBRARIES NOT FOUND ******")
message(" ****** Make sure libx11-dev is installed if you want GUI support ******")
message(" ***********************************************************************************")
set(DLIB_NO_GUI_SUPPORT ON CACHE STRING ${DLIB_NO_GUI_SUPPORT_STR} FORCE )
endif()
endif()
MARK_AS_ADVANCED(pthreadlib xlib xlib_path x11_path)
ELSE () ##################################################################################
FIND_LIBRARY(pthreadlib pthread)
set (dlib_needed_libraries ${pthreadlib})
# link to the nsl library if it exists. this is something you need sometimes
FIND_LIBRARY(nsllib nsl)
if (nsllib)
set (dlib_needed_libraries ${dlib_needed_libraries} ${nsllib})
endif ()
# link to the socket library if it exists. this is something you need on solaris
FIND_LIBRARY(socketlib socket)
if (socketlib)
set (dlib_needed_libraries ${dlib_needed_libraries} ${socketlib})
endif ()
if (NOT DLIB_NO_GUI_SUPPORT)
INCLUDE(FindX11)
if (X11_FOUND)
INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${X11_LIBRARIES})
else()
message(" ***********************************************************************************")
message(" ****** DLIB GUI SUPPORT DISABLED BECAUSE X11 DEVELOPMENT LIBRARIES NOT FOUND ******")
message(" ****** Make sure libx11-dev is installed if you want GUI support ******")
message(" ***********************************************************************************")
set(DLIB_NO_GUI_SUPPORT ON CACHE STRING ${DLIB_NO_GUI_SUPPORT_STR} FORCE )
endif()
endif()
MARK_AS_ADVANCED(nsllib pthreadlib socketlib)
ENDIF () #################################################################################
INCLUDE(FindPNG)
if (PNG_FOUND)
INCLUDE_DIRECTORIES(${PNG_PNG_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${PNG_LIBRARY})
add_global_define(DLIB_PNG_SUPPORT)
else()
# we could print a message but doing so is sort of irritating when it occurs by default
#message(" *************************************************************************")
#message(" ****** PNG IMAGE FILE SUPPORT NOT ENABLED BECAUSE libpng NOT FOUND ******")
#message(" ****** Make sure libpng is installed if you want PNG support ******")
#message(" *************************************************************************")
endif()
TARGET_LINK_LIBRARIES(dlib ${dlib_needed_libraries} )
ENDIF ()
#test for some things that really should be true about the compiler
INCLUDE(TestForSTDNamespace)
INCLUDE(TestForANSIStreamHeaders)
if (DLIB_ISO_CPP_ONLY)
set(DLIB_NO_GUI_SUPPORT ON CACHE STRING ${DLIB_NO_GUI_SUPPORT_STR} FORCE )
add_global_define(DLIB_ISO_CPP_ONLY)
else()
remove_global_define(DLIB_ISO_CPP_ONLY)
endif()
if (DLIB_NO_GUI_SUPPORT)
add_global_define(DLIB_NO_GUI_SUPPORT)
else()
remove_global_define(DLIB_NO_GUI_SUPPORT)
endif()
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
\ No newline at end of file
dlib C++ library
This project is a modern C++ library with a focus on portability
and program correctness. It strives to be easy to use right and
hard to use wrong. Thus, it comes with extensive documentation and
thorough debugging modes. The library provides a platform abstraction
layer for common tasks such as interfacing with network services,
handling threads, or creating graphical user interfaces. Additionally,
the library implements many useful algorithms such as data compression
routines, linked lists, binary search trees, linear algebra and matrix
utilities, machine learning algorithms, XML and text parsing, and many
other general utilities.
Documentation:
There should be HTML documentation accompanying this library. But
if there isn't you can download it from http://dclib.sourceforge.net
Installation :
To use this library all you have to do is extract the library
somewhere, make sure the folder *containing* the dlib folder is in
your include path, and finally add dlib/all/source.cpp to your
project.
An example makefile that uses this library can be found here:
dlib/test/makefile. It is the makefile used to build the regression
test suite for this library. There is also a CMake makefile that
builds the regression test suite at dlib/test/CMakeLists.txt and
another CMake makefile that builds all the example programs in
the examples folder.
For further information see the accompanying HTML documentation or
visit http://dclib.sourceforge.net
The license for this library can be found in LICENSE.txt. But the
long and short of the license is that you can use this code however
you like, even in closed source commercial software.
// Copyright (C) 2003 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ALGs_
#define DLIB_ALGs_
// this file contains miscellaneous stuff
#include <algorithm> // for std::swap
#include <new> // for std::bad_alloc
#include <string> // for the exceptions
#include <cstdlib>
#include "platform.h"
#include "assert.h"
#include "error.h"
#include "noncopyable.h"
#include "enable_if.h"
#include "uintn.h"
#ifdef _MSC_VER
// Disable the following warnings for Visual Studio
// this is to disable the "'this' : used in base member initializer list"
// warning you get from some of the GUI objects since all the objects
// require that their parent class be passed into their constructor.
// In this case though it is totally safe so it is ok to disable this warning.
#pragma warning(disable : 4355)
// This is a warning you get sometimes when Visual Studio performs a Koenig Lookup.
// This is a bug in visual studio. It is a totally legitimate thing to
// expect from a compiler.
#pragma warning(disable : 4675)
// This is a warning you get from visual studio 2005 about things in the standard C++
// library being "deprecated." I checked the C++ standard and it doesn't say jack
// about any of them (I checked the searchable PDF). So this warning is total Bunk.
#pragma warning(disable : 4996)
// This is a warning you get from visual studio 2003:
// warning C4345: behavior change: an object of POD type constructed with an initializer
// of the form () will be default-initialized.
// I love it when this compiler gives warnings about bugs in previous versions of itself.
#pragma warning(disable : 4345)
#endif
#ifdef __BORLANDC__
// Disable the following warnings for the Borland Compilers
//
// These warnings just say that the compiler is refusing to inline functions with
// loops or try blocks in them.
//
#pragma option -w-8027
#pragma option -w-8026
#endif
// ----------------------------------------------------------------------------------------
/*!A _dT !*/
template <typename charT>
inline const charT _dTcast (const char a, const wchar_t b);
template <>
inline const char _dTcast<char> (const char a, const wchar_t ) { return a; }
template <>
inline const wchar_t _dTcast<wchar_t> (const char , const wchar_t b) { return b; }
template <typename charT>
inline const charT* _dTcast ( const char* a, const wchar_t* b);
template <>
inline const char* _dTcast<char> ( const char* a, const wchar_t* ) { return a; }
template <>
inline const wchar_t* _dTcast<wchar_t> ( const char* , const wchar_t* b) { return b; }
#define _dT(charT,str) _dTcast<charT>(str,L##str)
/*!
requires
- charT == char or wchar_t
- str == a string or character literal
ensures
- returns the literal in the form of a charT type literal.
!*/
// ----------------------------------------------------------------------------------------
namespace dlib
{
// ----------------------------------------------------------------------------------------
/*!A swap !*/
// make swap available in the dlib namespace
using std::swap;
// ----------------------------------------------------------------------------------------
/*!
Here is where I define my return codes. It is
important that they all be < 0.
!*/
enum general_return_codes
{
TIMEOUT = -1,
WOULDBLOCK = -2,
OTHER_ERROR = -3,
SHUTDOWN = -4,
PORTINUSE = -5
};
// ----------------------------------------------------------------------------------------
inline unsigned long square_root (
unsigned long value
)
/*!
requires
- value <= 2^32 - 1
ensures
- returns the square root of value. if the square root is not an
integer then it will be rounded up to the nearest integer.
!*/
{
unsigned long x;
// set the initial guess for what the root is depending on
// how big value is
if (value < 3)
return value;
else if (value < 4096) // 12
x = 45;
else if (value < 65536) // 16
x = 179;
else if (value < 1048576) // 20
x = 717;
else if (value < 16777216) // 24
x = 2867;
else if (value < 268435456) // 28
x = 11469;
else // 32
x = 45875;
// find the root
x = (x + value/x)>>1;
x = (x + value/x)>>1;
x = (x + value/x)>>1;
x = (x + value/x)>>1;
if (x*x < value)
return x+1;
else
return x;
}
// ----------------------------------------------------------------------------------------
template <
typename T
>
void median (
T& one,
T& two,
T& three
);
/*!
requires
- T implements operator<
- T is swappable by a global swap()
ensures
- #one is the median
- #one, #two, and #three is some permutation of one, two, and three.
!*/
template <
typename T
>
void median (
T& one,
T& two,
T& three
)
{
using std::swap;
using dlib::swap;
if ( one < two )
{
// one < two
if ( two < three )
{
// one < two < three : two
swap(one,two);
}
else
{
// one < two >= three
if ( one < three)
{
// three
swap(three,one);
}
}
}
else
{
// one >= two
if ( three < one )
{
// three <= one >= two
if ( three < two )
{
// two
swap(two,one);
}
else
{
// three
swap(three,one);
}
}
}
}
// ----------------------------------------------------------------------------------------
namespace relational_operators
{
template <
typename A,
typename B
>
bool operator> (
const A& a,
const B& b
) { return b < a; }
// ---------------------------------
template <
typename A,
typename B
>
bool operator!= (
const A& a,
const B& b
) { return !(a == b); }
// ---------------------------------
template <
typename A,
typename B
>
bool operator<= (
const A& a,
const B& b
) { return !(b < a); }
// ---------------------------------
template <
typename A,
typename B
>
bool operator>= (
const A& a,
const B& b
) { return !(a < b); }
}
// ----------------------------------------------------------------------------------------
template <
typename T
>
void exchange (
T& a,
T& b
)
/*!
This function does the exact same thing that global swap does and it does it by
just calling swap. But a lot of compilers have problems doing a Koenig Lookup
and the fact that this has a different name (global swap has the same name as
the member functions called swap) makes them compile right.
So this is a workaround but not too ugly of one. But hopefully I get get
rid of this in a few years. So this function is alredy deprecated.
This also means you should NOT use this function in your own code unless
you have to support an old buggy compiler that benefits from this hack.
!*/
{
using std::swap;
using dlib::swap;
swap(a,b);
}
// ----------------------------------------------------------------------------------------
/*!A is_pointer_type
This is a template where is_pointer_type<T>::value == true when T is a pointer
type ane false otherwise.
!*/
template <
typename T
>
class is_pointer_type
{
public:
enum { value = false };
private:
is_pointer_type();
};
template <
typename T
>
class is_pointer_type<T*>
{
public:
enum { value = true };
private:
is_pointer_type();
};
// ----------------------------------------------------------------------------------------
/*!A is_same_type
This is a template where is_same_type<T,U>::value == true when T and U are the
same type and false otherwise.
!*/
template <
typename T,
typename U
>
class is_same_type
{
public:
enum {value = false};
private:
is_same_type();
};
template <typename T>
class is_same_type<T,T>
{
public:
enum {value = true};
private:
is_same_type();
};
// ----------------------------------------------------------------------------------------
/*!A is_signed_type
This is a template where is_signed_type<T>::value == true when T is a signed
integral type and false when T is an unsigned integral type.
!*/
template <
typename T
>
struct is_signed_type
{
static const bool value = static_cast<T>((static_cast<T>(0)-static_cast<T>(1))) < 0;
};
// ----------------------------------------------------------------------------------------
/*!A is_unsigned_type
This is a template where is_unsigned_type<T>::value == true when T is an unsigned
integral type and false when T is a signed integral type.
!*/
template <
typename T
>
struct is_unsigned_type
{
static const bool value = static_cast<T>((static_cast<T>(0)-static_cast<T>(1))) > 0;
};
// ----------------------------------------------------------------------------------------
template <
typename T
>
class copy_functor
{
public:
void operator() (
const T& source,
T& destination
) const
{
destination = source;
}
};
// ----------------------------------------------------------------------------------------
/*!A static_switch
To use this template you give it some number of boolean expressions and it
tells you which one of them is true. If more than one of them is true then
it causes a compile time error.
for example:
static_switch<1 + 1 == 2, 4 - 1 == 4>::value == 1 // because the first expression is true
static_switch<1 + 1 == 3, 4 == 4>::value == 2 // because the second expression is true
static_switch<1 + 1 == 3, 4 == 5>::value == 0 // 0 here because none of them are true
static_switch<1 + 1 == 2, 4 == 4>::value == compiler error // because more than one expression is true
!*/
template < bool v1 = 0, bool v2 = 0, bool v3 = 0, bool v4 = 0, bool v5 = 0,
bool v6 = 0, bool v7 = 0, bool v8 = 0, bool v9 = 0, bool v10 = 0,
bool v11 = 0, bool v12 = 0, bool v13 = 0, bool v14 = 0, bool v15 = 0 >
struct static_switch;
template <> struct static_switch<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0> { const static int value = 0; };
template <> struct static_switch<1,0,0,0,0,0,0,0,0,0,0,0,0,0,0> { const static int value = 1; };
template <> struct static_switch<0,1,0,0,0,0,0,0,0,0,0,0,0,0,0> { const static int value = 2; };
template <> struct static_switch<0,0,1,0,0,0,0,0,0,0,0,0,0,0,0> { const static int value = 3; };
template <> struct static_switch<0,0,0,1,0,0,0,0,0,0,0,0,0,0,0> { const static int value = 4; };
template <> struct static_switch<0,0,0,0,1,0,0,0,0,0,0,0,0,0,0> { const static int value = 5; };
template <> struct static_switch<0,0,0,0,0,1,0,0,0,0,0,0,0,0,0> { const static int value = 6; };
template <> struct static_switch<0,0,0,0,0,0,1,0,0,0,0,0,0,0,0> { const static int value = 7; };
template <> struct static_switch<0,0,0,0,0,0,0,1,0,0,0,0,0,0,0> { const static int value = 8; };
template <> struct static_switch<0,0,0,0,0,0,0,0,1,0,0,0,0,0,0> { const static int value = 9; };
template <> struct static_switch<0,0,0,0,0,0,0,0,0,1,0,0,0,0,0> { const static int value = 10; };
template <> struct static_switch<0,0,0,0,0,0,0,0,0,0,1,0,0,0,0> { const static int value = 11; };
template <> struct static_switch<0,0,0,0,0,0,0,0,0,0,0,1,0,0,0> { const static int value = 12; };
template <> struct static_switch<0,0,0,0,0,0,0,0,0,0,0,0,1,0,0> { const static int value = 13; };
template <> struct static_switch<0,0,0,0,0,0,0,0,0,0,0,0,0,1,0> { const static int value = 14; };
template <> struct static_switch<0,0,0,0,0,0,0,0,0,0,0,0,0,0,1> { const static int value = 15; };
// ----------------------------------------------------------------------------------------
/*!A is_built_in_scalar_type
This is a template that allows you to determine if the given type is a built
in scalar type such as an int, char, float, short, etc...
For example, is_built_in_scalar_type<char>::value == true
For example, is_built_in_scalar_type<std::string>::value == false
!*/
template <typename T> struct is_built_in_scalar_type { const static bool value = false; };
template <> struct is_built_in_scalar_type<float> { const static bool value = true; };
template <> struct is_built_in_scalar_type<double> { const static bool value = true; };
template <> struct is_built_in_scalar_type<long double> { const static bool value = true; };
template <> struct is_built_in_scalar_type<short> { const static bool value = true; };
template <> struct is_built_in_scalar_type<int> { const static bool value = true; };
template <> struct is_built_in_scalar_type<long> { const static bool value = true; };
template <> struct is_built_in_scalar_type<unsigned short> { const static bool value = true; };
template <> struct is_built_in_scalar_type<unsigned int> { const static bool value = true; };
template <> struct is_built_in_scalar_type<unsigned long> { const static bool value = true; };
template <> struct is_built_in_scalar_type<uint64> { const static bool value = true; };
template <> struct is_built_in_scalar_type<char> { const static bool value = true; };
template <> struct is_built_in_scalar_type<signed char> { const static bool value = true; };
template <> struct is_built_in_scalar_type<unsigned char> { const static bool value = true; };
// Don't define one for wchar_t when using a version of visual studio
// older than 8.0 (visual studio 2005) since before then they improperly set
// wchar_t to be a typedef rather than its own type as required by the C++
// standard.
#if !defined(_MSC_VER) || _NATIVE_WCHAR_T_DEFINED
template <> struct is_built_in_scalar_type<wchar_t> { const static bool value = true; };
#endif
// ----------------------------------------------------------------------------------------
/*!A assign_zero_if_built_in_scalar_type
This function assigns its argument the value of 0 if it is a built in scalar
type according to the is_built_in_scalar_type<> template. If it isn't a
built in scalar type then it does nothing.
!*/
template <typename T> inline typename disable_if<is_built_in_scalar_type<T>,void>::type assign_zero_if_built_in_scalar_type (T&){}
template <typename T> inline typename enable_if<is_built_in_scalar_type<T>,void>::type assign_zero_if_built_in_scalar_type (T& a){a=0;}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ALGs_
// Copyright (C) 2006 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ALL_SOURCe_
#define DLIB_ALL_SOURCe_
// ISO C++ code
#include "../base64/base64_kernel_1.cpp"
#include "../bigint/bigint_kernel_1.cpp"
#include "../bigint/bigint_kernel_2.cpp"
#include "../bit_stream/bit_stream_kernel_1.cpp"
#include "../entropy_decoder/entropy_decoder_kernel_1.cpp"
#include "../entropy_decoder/entropy_decoder_kernel_2.cpp"
#include "../entropy_encoder/entropy_encoder_kernel_1.cpp"
#include "../entropy_encoder/entropy_encoder_kernel_2.cpp"
#include "../md5/md5_kernel_1.cpp"
#include "../pixel.cpp"
#include "../tokenizer/tokenizer_kernel_1.cpp"
#ifndef DLIB_ISO_CPP_ONLY
// Code that depends on OS specific APIs
// include this first so that it can disable the older version
// of the winsock API when compiled in windows.
#include "../sockets/sockets_kernel_1.cpp"
#include "../dir_nav/dir_nav_kernel_1.cpp"
#include "../dir_nav/dir_nav_kernel_2.cpp"
#include "../linker/linker_kernel_1.cpp"
#include "../logger/extra_logger_headers.cpp"
#include "../logger/logger_kernel_1.cpp"
#include "../logger/logger_config_file.cpp"
#include "../misc_api/misc_api_kernel_1.cpp"
#include "../misc_api/misc_api_kernel_2.cpp"
#include "../sockets/sockets_extensions.cpp"
#include "../sockets/sockets_kernel_2.cpp"
#include "../sockstreambuf/sockstreambuf_kernel_1.cpp"
#include "../sockstreambuf/sockstreambuf_kernel_2.cpp"
#include "../threads/multithreaded_object_extension.cpp"
#include "../threads/threaded_object_extension.cpp"
#include "../threads/threads_kernel_1.cpp"
#include "../threads/threads_kernel_2.cpp"
#include "../threads/threads_kernel_shared.cpp"
#include "../timer/timer_kernel_2.cpp"
#ifdef DLIB_PNG_SUPPORT
#include "../image_loader/png_loader.cpp"
#endif
#ifndef DLIB_NO_GUI_SUPPORT
#include "../gui_widgets/fonts.cpp"
#include "../gui_widgets/widgets.cpp"
#include "../gui_widgets/drawable.cpp"
#include "../gui_widgets/canvas_drawing.cpp"
#include "../gui_widgets/style.cpp"
#include "../gui_widgets/base_widgets.cpp"
#include "../gui_core/gui_core_kernel_1.cpp"
#include "../gui_core/gui_core_kernel_2.cpp"
#endif // DLIB_NO_GUI_SUPPORT
#endif // DLIB_ISO_CPP_ONLY
#endif // DLIB_ALL_SOURCe_
// Copyright (C) 2006 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ALL_CONSOLe_
#define DLIB_ALL_CONSOLe_
#error "This file has been replaced. Instead you should add dlib/all/source.cpp to your project"
#endif // DLIB_ALL_CONSOLe_
// Copyright (C) 2006 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ALL_GUi_
#define DLIB_ALL_GUi_
#error "This file has been replaced. Instead you should add dlib/all/source.cpp to your project"
#endif // DLIB_ALL_GUi_
// Copyright (C) 2003 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAy_
#define DLIB_ARRAy_
#include "array/array_kernel_1.h"
#include "array/array_kernel_2.h"
#include "array/array_kernel_c.h"
#include "array/array_sort_1.h"
#include "array/array_sort_2.h"
#include "array/array_expand_1.h"
#include "array/array_expand_c.h"
#include "memory_manager.h"
namespace dlib
{
template <
typename T,
typename mem_manager = memory_manager<char>::kernel_1a
>
class array
{
array() {}
public:
//----------- kernels ---------------
// kernel_1a
typedef array_kernel_1<T,mem_manager>
kernel_1a;
typedef array_kernel_c<kernel_1a >
kernel_1a_c;
// kernel_2a
typedef array_kernel_2<T,mem_manager>
kernel_2a;
typedef array_kernel_c<kernel_2a >
kernel_2a_c;
//---------- extensions ------------
// sort_1 extend kernel_1a
typedef array_sort_1<kernel_1a>
sort_1a;
typedef array_sort_1<kernel_1a_c>
sort_1a_c;
// sort_1 extend kernel_2a
typedef array_sort_1<kernel_2a>
sort_1b;
typedef array_sort_1<kernel_2a_c>
sort_1b_c;
// sort_2 extend kernel_1a
typedef array_sort_2<kernel_1a>
sort_2a;
typedef array_sort_2<kernel_1a_c>
sort_2a_c;
// sort_2 extend kernel_2a
typedef array_sort_2<kernel_2a>
sort_2b;
typedef array_sort_2<kernel_2a_c>
sort_2b_c;
// expand_1 extend sort_1a
typedef array_expand_1<sort_1a>
expand_1a;
typedef array_expand_c<array_kernel_c<expand_1a> >
expand_1a_c;
// expand_1 extend sort_1b
typedef array_expand_1<sort_1b>
expand_1b;
typedef array_expand_c<array_kernel_c<expand_1b> >
expand_1b_c;
// expand_1 extend sort_2a
typedef array_expand_1<sort_2a>
expand_1c;
typedef array_expand_c<array_kernel_c<expand_1c> >
expand_1c_c;
// expand_1 extend sort_2b
typedef array_expand_1<sort_2b>
expand_1d;
typedef array_expand_c<array_kernel_c<expand_1d> >
expand_1d_c;
};
}
#endif // DLIB_ARRAy_
// Copyright (C) 2006 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY_EXPANd_1_
#define DLIB_ARRAY_EXPANd_1_
#include "array_expand_abstract.h"
namespace dlib
{
template <
typename array_base
>
class array_expand_1 : public array_base
{
typedef typename array_base::type T;
public:
void expand (
unsigned long new_size
);
const T& back (
) const;
T& back (
);
void pop_back (
);
void pop_back (
T& item
);
void push_back (
T& item
);
};
template <
typename array_base
>
inline void swap (
array_expand_1<array_base>& a,
array_expand_1<array_base>& b
) { a.swap(b); }
/*!
provides a global swap function
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
void array_expand_1<array_base>::
expand (
unsigned long new_size
)
{
if (this->max_size() < new_size)
{
array_base temp;
temp.set_max_size(new_size);
temp.set_size(new_size);
for (unsigned long i = 0; i < this->size(); ++i)
{
exchange((*this)[i],temp[i]);
}
temp.swap(*this);
}
else
{
this->set_size(new_size);
}
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
typename array_base::type& array_expand_1<array_base>::
back (
)
{
return (*this)[this->size()-1];
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
const typename array_base::type& array_expand_1<array_base>::
back (
) const
{
return (*this)[this->size()-1];
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
void array_expand_1<array_base>::
pop_back (
typename array_base::type& item
)
{
exchange(item,(*this)[this->size()-1]);
this->set_size(this->size()-1);
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
void array_expand_1<array_base>::
pop_back (
)
{
this->set_size(this->size()-1);
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
void array_expand_1<array_base>::
push_back (
typename array_base::type& item
)
{
if (this->max_size() == this->size())
{
// double the size of the array
array_base temp;
temp.set_max_size(this->size()*2 + 1);
temp.set_size(this->size()+1);
for (unsigned long i = 0; i < this->size(); ++i)
{
exchange((*this)[i],temp[i]);
}
exchange(item,temp[temp.size()-1]);
temp.swap(*this);
}
else
{
this->set_size(this->size()+1);
exchange(item,(*this)[this->size()-1]);
}
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_EXPANd_1_
// Copyright (C) 2006 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_ARRAY_EXPANd_ABSTRACT_
#ifdef DLIB_ARRAY_EXPANd_ABSTRACT_
#include "array_kernel_abstract.h"
namespace dlib
{
template <
typename array_base
>
class array_expand : public array_base
{
/*!
REQUIREMENTS ON ARRAY_BASE
must be an implementation of array/array_kernel_abstract.h
POINTERS AND REFERENCES
expand() may invalidate pointers and references to internal data.
WHAT THIS EXTENSION DOES FOR ARRAY
This extension gives an array the ability to expand its size() beyond
its max_size() without clearing out all its elements. It also adds
a std::vector style push/pop back set of functions.
!*/
typedef typename array_base::type T;
public:
void expand (
unsigned long new_size
);
/*!
ensures
- #size() == new_size
- #max_size() == max(new_size,max_size())
- for all i < size():
- #(*this)[i] == (*this)[i]
(i.e. all the original elements of *this are still present
and at their same positions.)
- for all valid i >= size():
- #(*this)[i] has an undefined value
(i.e. any new elements of the array have an undefined value)
throws
- std::bad_alloc or any exception thrown by T's constructor.
If an exception is thrown then it has no effect on *this.
!*/
const T& back (
) const;
/*!
requires
- size() != 0
ensures
- returns a const reference to (*this)[size()-1]
!*/
T& back (
);
/*!
requires
- size() != 0
ensures
- returns a non-const reference to (*this)[size()-1]
!*/
void pop_back (
T& item
);
/*!
requires
- size() != 0
ensures
- #size() == size() - 1
- swaps (*this)[size()-1] into item
- All elements with an index less than size()-1 are
unmodified by this operation.
!*/
void pop_back (
);
/*!
requires
- size() != 0
ensures
- #size() == size() - 1
- All elements with an index less than size()-1 are
unmodified by this operation.
!*/
void push_back (
T& item
);
/*!
ensures
- #size() == size()+1
- swaps item into (*this)[#size()-1]
- #back() == item
- #item has some undefined value (whatever happens to
get swapped out of the array)
throws
- std::bad_alloc or any exception thrown by T's constructor.
If an exception is thrown then it has no effect on *this.
!*/
};
template <
typename array_base
>
inline void swap (
array_expand<array_base>& a,
array_expand<array_base>& b
) { a.swap(b); }
/*!
provides a global swap function
!*/
}
#endif // DLIB_ARRAY_EXPANd_ABSTRACT_
// Copyright (C) 2008 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY_EXPAND_C_
#define DLIB_ARRAY_EXPAND_C_
#include "array_expand_abstract.h"
#include "../algs.h"
#include "../assert.h"
namespace dlib
{
template <
typename array_base
>
class array_expand_c : public array_base
{
typedef typename array_base::type T;
public:
const T& back (
) const;
T& back (
);
void pop_back (
);
void pop_back (
T& item
);
};
template <
typename array_base
>
inline void swap (
array_expand_c<array_base>& a,
array_expand_c<array_base>& b
) { a.swap(b); }
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
typename array_base::type& array_expand_c<array_base>::
back (
)
{
// make sure requires clause is not broken
DLIB_CASSERT( this->size() > 0 ,
"\tT& array_expand::back()"
<< "\n\tsize() must be bigger than 0"
<< "\n\tsize(): " << this->size()
<< "\n\tthis: " << this
);
// call the real function
return array_base::back();
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
const typename array_base::type& array_expand_c<array_base>::
back (
) const
{
// make sure requires clause is not broken
DLIB_CASSERT( this->size() > 0 ,
"\tconst T& array_expand::back()"
<< "\n\tsize() must be bigger than 0"
<< "\n\tsize(): " << this->size()
<< "\n\tthis: " << this
);
// call the real function
return array_base::back();
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
void array_expand_c<array_base>::
pop_back (
)
{
// make sure requires clause is not broken
DLIB_CASSERT( this->size() > 0 ,
"\tvoid array_expand::pop_back()"
<< "\n\tsize() must be bigger than 0"
<< "\n\tsize(): " << this->size()
<< "\n\tthis: " << this
);
// call the real function
return array_base::pop_back();
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
void array_expand_c<array_base>::
pop_back (
typename array_base::type& item
)
{
// make sure requires clause is not broken
DLIB_CASSERT( this->size() > 0 ,
"\tvoid array_expand::pop_back()"
<< "\n\tsize() must be bigger than 0"
<< "\n\tsize(): " << this->size()
<< "\n\tthis: " << this
);
// call the real function
return array_base::pop_back(item);
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_EXPAND_C_
// Copyright (C) 2003 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY_KERNEl_1_
#define DLIB_ARRAY_KERNEl_1_
#include "array_kernel_abstract.h"
#include "../interfaces/enumerable.h"
#include "../algs.h"
#include "../serialize.h"
#include "../memory_manager.h"
namespace dlib
{
template <
typename T,
typename mem_manager = memory_manager<char>::kernel_1a
>
class array_kernel_1 : public enumerable<T>
{
/*!
INITIAL VALUE
- array_size == 0
- array_nodes == 0
- max_array_size == 0
- number_of_nodes == 0
- mask == 0
- mask_size == 0
- _at_start == true
- pos == 0
CONVENTION
- current_element_valid() == (pos != array_size)
- at_start() == _at_start
- if (pos != array_size)
- element() == (*this)[pos]
array_size == number of elements in the array.
array_nodes == pointer to array of number_of_nodes pointers.
max_array_size == the maximum allowed number of elements in the array.
mask_size == the number of bits set to 1 in mask
if (array_size > 0)
{
Only array_nodes[0] though array_nodes[(array_size-1)/number_of_nodes]
point to valid addresses. All other elements in array_nodes
are set to 0.
}
else
{
for all x: array_nodes[x] == 0
}
operator[](pos) == array_nodes[pos>>mask_size][pos&mask]
if (max_array_size == 0)
{
number_of_nodes == 0
array_nodes == 0
array_size == 0
}
!*/
public:
typedef T type;
typedef mem_manager mem_manager_type;
array_kernel_1 (
) :
array_nodes(0)
{
update_max_array_size(0);
}
virtual ~array_kernel_1 (
);
void clear (
);
inline const T& operator[] (
unsigned long pos
) const;
inline T& operator[] (
unsigned long pos
);
void set_size (
unsigned long size
);
inline unsigned long max_size(
) const;
void set_max_size(
unsigned long max
);
void swap (
array_kernel_1& item
);
// functions from the enumerable interface
inline unsigned long size (
) const;
inline bool at_start (
) const;
inline void reset (
) const;
bool current_element_valid (
) const;
inline const T& element (
) const;
inline T& element (
);
bool move_next (
) const;
private:
void update_max_array_size (
unsigned long new_max_array_size
);
/*!
ensures
- everything in the CONVENTION is satisfied
- #max_array_size == new_max_array_size
- #array_size == 0
- mask_size, mask, and number_of_nodes have been set proper
values for the new max array size
- if (new_max_array_size != 0) then
- #array_nodes == pointer to an array of size #number_of_nodes
- else
- #array_nodes == 0
- #at_start() == true
!*/
// data members
T** array_nodes;
unsigned long max_array_size;
unsigned long array_size;
unsigned long number_of_nodes;
mutable unsigned long pos;
unsigned long mask;
unsigned long mask_size;
mutable bool _at_start;
// restricted functions
array_kernel_1(array_kernel_1<T>&); // copy constructor
array_kernel_1<T>& operator=(array_kernel_1<T>&); // assignment operator
};
template <
typename T,
typename mem_manager
>
inline void swap (
array_kernel_1<T,mem_manager>& a,
array_kernel_1<T,mem_manager>& b
) { a.swap(b); }
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void serialize (
const array_kernel_1<T,mem_manager>& item,
std::ostream& out
)
{
try
{
serialize(item.max_size(),out);
serialize(item.size(),out);
for (unsigned long i = 0; i < item.size(); ++i)
serialize(item[i],out);
}
catch (serialization_error e)
{
throw serialization_error(e.info + "\n while serializing object of type array_kernel_1");
}
}
template <
typename T,
typename mem_manager
>
void deserialize (
array_kernel_1<T,mem_manager>& item,
std::istream& in
)
{
try
{
unsigned long max_size, size;
deserialize(max_size,in);
deserialize(size,in);
item.set_max_size(max_size);
item.set_size(size);
for (unsigned long i = 0; i < size; ++i)
deserialize(item[i],in);
}
catch (serialization_error e)
{
item.clear();
throw serialization_error(e.info + "\n while deserializing object of type array_kernel_1");
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
array_kernel_1<T,mem_manager>::
~array_kernel_1 (
)
{
update_max_array_size(0);
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array_kernel_1<T,mem_manager>::
clear (
)
{
update_max_array_size(0);
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
const T& array_kernel_1<T,mem_manager>::
operator[] (
unsigned long pos
) const
{
return array_nodes[pos>>mask_size][pos&mask];
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
T& array_kernel_1<T,mem_manager>::
operator[] (
unsigned long pos
)
{
return array_nodes[pos>>mask_size][pos&mask];
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
unsigned long array_kernel_1<T,mem_manager>::
max_size (
) const
{
return max_array_size;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array_kernel_1<T,mem_manager>::
set_max_size (
unsigned long max
)
{
update_max_array_size(max);
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array_kernel_1<T,mem_manager>::
set_size (
unsigned long size
)
{
if (array_size == 0 && size != 0)
{
const unsigned long new_biggest_node = (size-1)/(mask+1);
try
{
// we need to initialize some array nodes
for (unsigned long i = 0; i <= new_biggest_node; ++i)
array_nodes[i] = new T[mask+1];
}
catch (...)
{
// undo any changes
for (unsigned long i = 0; i <= new_biggest_node; ++i)
{
if (array_nodes[i] != 0)
delete [] array_nodes[i];
array_nodes[i] = 0;
}
throw;
}
}
else if (size == 0)
{
// free all nodes
for (unsigned long i = 0; i < number_of_nodes; ++i)
{
if (array_nodes[i] != 0)
delete [] array_nodes[i];
array_nodes[i] = 0;
}
}
else
{
const unsigned long biggest_node = (array_size-1)/(mask+1);
const unsigned long new_biggest_node = (size-1)/(mask+1);
try
{
if (biggest_node < new_biggest_node)
{
// we need to initialize more array nodes
for (unsigned long i = biggest_node+1; i <= new_biggest_node; ++i)
array_nodes[i] = new T[mask+1];
}
else if (biggest_node > new_biggest_node)
{
// we need to free some array nodes
for (unsigned long i = new_biggest_node+1; i <= biggest_node; ++i)
{
delete [] array_nodes[i];
array_nodes[i] = 0;
}
}
}
catch (...)
{
// undo any changes
for (unsigned long i = biggest_node+1; i <= new_biggest_node; ++i)
{
if (array_nodes[i] != 0)
delete [] array_nodes[i];
array_nodes[i] = 0;
}
throw;
}
}
array_size = size;
reset();
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array_kernel_1<T,mem_manager>::
swap (
array_kernel_1<T,mem_manager>& item
)
{
exchange(_at_start,item._at_start);
exchange(pos,item.pos);
exchange(mask_size,item.mask_size);
exchange(mask,item.mask);
unsigned long max_array_size_temp = item.max_array_size;
unsigned long array_size_temp = item.array_size;
unsigned long number_of_nodes_temp = item.number_of_nodes;
T** array_nodes_temp = item.array_nodes;
item.max_array_size = max_array_size;
item.array_size = array_size;
item.number_of_nodes = number_of_nodes;
item.array_nodes = array_nodes;
max_array_size = max_array_size_temp;
array_size = array_size_temp;
number_of_nodes = number_of_nodes_temp;
array_nodes = array_nodes_temp;
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// private member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array_kernel_1<T,mem_manager>::
update_max_array_size (
unsigned long new_max_array_size
)
{
max_array_size = new_max_array_size;
// first free all memory
if (array_nodes != 0)
{
for (unsigned long i = 0; i < number_of_nodes; ++i)
{
if (array_nodes[i] != 0)
delete [] array_nodes[i];
else
break;
}
delete [] array_nodes;
}
if (max_array_size > 0)
{
// select new values for number_of_nodes, mask_size, and mask
if (max_array_size <= 0x1000)
{
number_of_nodes = 0x10;
mask = 0xFF;
mask_size = 8;
}
else if (max_array_size <= 0x10000)
{
number_of_nodes = 0x100;
mask = 0xFF;
mask_size = 8;
}
else if (max_array_size <= 0x100000)
{
number_of_nodes = 1024;
mask = 0x3FF;
mask_size = 10;
}
else if (max_array_size <= 0x1000000)
{
number_of_nodes = 4096;
mask = 0xFFF;
mask_size = 12;
}
else if (max_array_size <= 0x10000000)
{
number_of_nodes = 16384;
mask = 0x3FFF;
mask_size = 14;
}
else if (max_array_size <= 0x40000000)
{
number_of_nodes = 32768;
mask = 0x7FFF;
mask_size = 15;
}
else
{
number_of_nodes = 65536;
mask = 0xFFFF;
mask_size = 16;
}
try
{
array_nodes = new T*[number_of_nodes];
for (unsigned long i = 0; i < number_of_nodes; ++i)
array_nodes[i] = 0;
}
catch (...)
{
max_array_size = 0;
array_nodes = 0;
number_of_nodes = 0;
array_size = 0;
reset();
throw;
}
}
else
{
array_nodes = 0;
number_of_nodes = 0;
}
array_size = 0;
reset();
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// enumerable function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
bool array_kernel_1<T,mem_manager>::
at_start (
) const
{
return _at_start;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array_kernel_1<T,mem_manager>::
reset (
) const
{
_at_start = true;
pos = array_size;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
bool array_kernel_1<T,mem_manager>::
current_element_valid (
) const
{
return (pos != array_size);
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
const T& array_kernel_1<T,mem_manager>::
element (
) const
{
return operator[](pos);
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
T& array_kernel_1<T,mem_manager>::
element (
)
{
return operator[](pos);
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
bool array_kernel_1<T,mem_manager>::
move_next (
) const
{
if (!_at_start)
{
if (pos+1 < array_size)
{
++pos;
return true;
}
else
{
pos = array_size;
return false;
}
}
else
{
_at_start = false;
pos = 0;
if (array_size == 0)
return false;
else
return true;
}
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
unsigned long array_kernel_1<T,mem_manager>::
size (
) const
{
return array_size;
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_KERNEl_1_
// Copyright (C) 2003 Davis E. King (davisking@users.sourceforge.net)
// License: GNU LGPL See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY_KERNEl_2_
#define DLIB_ARRAY_KERNEl_2_
#include "array_kernel_abstract.h"
#include "../interfaces/enumerable.h"
#include "../algs.h"
#include "../serialize.h"
namespace dlib
{
template <
typename T,
typename mem_manager = memory_manager<char>::kernel_1a
>
class array_kernel_2 : public enumerable<T>
{
/*!
INITIAL VALUE
- array_size == 0
- max_array_size == 0
- array_elements == 0
- pos == 0
- last_pos == 0
- _at_start == true
CONVENTION
- array_size == size()
- max_array_size == max_size()
- if (max_array_size > 0)
- array_elements == pointer to max_array_size elements of type T
- else
- array_elements == 0
- if (array_size > 0)
- last_pos == array_elements + array_size - 1
- else
- last_pos == 0
- at_start() == _at_start
- current_element_valid() == pos != 0
- if (current_element_valid()) then
- *pos == element()
!*/
public:
typedef T type;
typedef mem_manager mem_manager_type;
array_kernel_2 (
) :
array_size(0),
max_array_size(0),
array_elements(0),
pos(0),
last_pos(0),
_at_start(true)
{}
virtual ~array_kernel_2 (
);
void clear (
);
inline const T& operator[] (
unsigned long pos
) const;
inline T& operator[] (
unsigned long pos
);
void set_size (
unsigned long size
);
inline unsigned long max_size(
) const;
void set_max_size(
unsigned long max
);
void swap (
array_kernel_2& item
);
// functions from the enumerable interface
inline unsigned long size (
) const;
inline bool at_start (
) const;
inline void reset (
) const;
bool current_element_valid (
) const;
inline const T& element (
) const;
inline T& element (
);
bool move_next (
) const;
private:
typename mem_manager::template rebind<T>::other pool;
// data members
unsigned long array_size;
unsigned long max_array_size;
T* array_elements;
mutable T* pos;
T* last_pos;
mutable bool _at_start;
// restricted functions
array_kernel_2(array_kernel_2<T>&); // copy constructor
array_kernel_2<T>& operator=(array_kernel_2<T>&); // assignment operator
};
template <
typename T,
typename mem_manager
>
inline void swap (
array_kernel_2<T,mem_manager>& a,
array_kernel_2<T,mem_manager>& b
) { a.swap(b); }
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void serialize (
const array_kernel_2<T,mem_manager>& item,
std::ostream& out
)
{
try
{
serialize(item.max_size(),out);
serialize(item.size(),out);
for (unsigned long i = 0; i < item.size(); ++i)
serialize(item[i],out);
}
catch (serialization_error e)
{
throw serialization_error(e.info + "\n while serializing object of type array_kernel_2");
}
}
template <
typename T,
typename mem_manager
>
void deserialize (
array_kernel_2<T,mem_manager>& item,
std::istream& in
)
{
try
{
unsigned long max_size, size;
deserialize(max_size,in);
deserialize(size,in);
item.set_max_size(max_size);
item.set_size(size);
for (unsigned long i = 0; i < size; ++i)
deserialize(item[i],in);
}
catch (serialization_error e)
{
item.clear();
throw serialization_error(e.info + "\n while deserializing object of type array_kernel_2");
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
array_kernel_2<T,mem_manager>::
~array_kernel_2 (
)
{
if (array_elements)
{
pool.deallocate_array(array_elements);
}
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array_kernel_2<T,mem_manager>::
clear (
)
{
reset();
last_pos = 0;
array_size = 0;
if (array_elements)
{
pool.deallocate_array(array_elements);
}
array_elements = 0;
max_array_size = 0;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
const T& array_kernel_2<T,mem_manager>::
operator[] (
unsigned long pos
) const
{
return array_elements[pos];
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
T& array_kernel_2<T,mem_manager>::
operator[] (
unsigned long pos
)
{
return array_elements[pos];
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array_kernel_2<T,mem_manager>::
set_size (
unsigned long size
)
{
reset();
array_size = size;
if (size > 0)
last_pos = array_elements + size - 1;
else
last_pos = 0;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
unsigned long array_kernel_2<T,mem_manager>::
size (
) const
{
return array_size;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array_kernel_2<T,mem_manager>::
set_max_size(
unsigned long max
)
{
reset();
array_size = 0;
last_pos = 0;
if (max != 0)
{
// if new max size is different
if (max != max_array_size)
{
if (array_elements)
{
pool.deallocate_array(array_elements);
}
// try to get more memroy
try { array_elements = pool.allocate_array(max); }
catch (...) { array_elements = 0; max_array_size = 0; throw; }
max_array_size = max;
}
}
// if the array is being made to be zero
else
{
if (array_elements)
pool.deallocate_array(array_elements);
max_array_size = 0;
array_elements = 0;
}
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
unsigned long array_kernel_2<T,mem_manager>::
max_size (
) const
{
return max_array_size;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array_kernel_2<T,mem_manager>::
swap (
array_kernel_2<T,mem_manager>& item
)
{
unsigned long array_size_temp = item.array_size;
unsigned long max_array_size_temp = item.max_array_size;
T* array_elements_temp = item.array_elements;
item.array_size = array_size;
item.max_array_size = max_array_size;
item.array_elements = array_elements;
array_size = array_size_temp;
max_array_size = max_array_size_temp;
array_elements = array_elements_temp;
exchange(_at_start,item._at_start);
exchange(pos,item.pos);
exchange(last_pos,item.last_pos);
pool.swap(item.pool);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// enumerable function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
bool array_kernel_2<T,mem_manager>::
at_start (
) const
{
return _at_start;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array_kernel_2<T,mem_manager>::
reset (
) const
{
_at_start = true;
pos = 0;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
bool array_kernel_2<T,mem_manager>::
current_element_valid (
) const
{
return pos != 0;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
const T& array_kernel_2<T,mem_manager>::
element (
) const
{
return *pos;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
T& array_kernel_2<T,mem_manager>::
element (
)
{
return *pos;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
bool array_kernel_2<T,mem_manager>::
move_next (
) const
{
if (!_at_start)
{
if (pos < last_pos)
{
++pos;
return true;
}
else
{
pos = 0;
return false;
}
}
else
{
_at_start = false;
if (array_size > 0)
{
pos = array_elements;
return true;
}
else
{
return false;
}
}
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_KERNEl_2_
// Copyright (C) 2003 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_ARRAY_KERNEl_ABSTRACT_
#ifdef DLIB_ARRAY_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 array : 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
swap(), max_size(), set_size(), and operator[] functions do
not invalidate pointers or references to internal data.
All other functions have no such guarantee.
INITIAL VALUE
size() == 0
max_size() == 0
ENUMERATION ORDER
The enumerator will iterate over the elements of the array in the
order (*this)[0], (*this)[1], (*this)[2], ...
WHAT THIS OBJECT REPRESENTS
array contains items of type T
This object represents an ordered array of items, each item is
associated with an integer value.
The items are numbered from 0 though size() - 1 and
the operator[] functions run in constant time
!*/
public:
typedef T type;
typedef mem_manager mem_manager_type;
array (
);
/*!
ensures
- #*this is properly initialized
throws
- std::bad_alloc or any exception thrown by T's constructor
!*/
virtual ~array (
);
/*!
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 T's constructor
if this exception is thrown then the array object is unusable
until clear() is called and succeeds
!*/
const T& operator[] (
unsigned long pos
) const;
/*!
requires
- pos < size()
ensures
- returns a const reference to the element at position pos
!*/
T& operator[] (
unsigned long pos
);
/*!
requires
- pos < size()
ensures
- returns a non-const reference to the element at position pos
!*/
void set_size (
unsigned long size
);
/*!
requires
- size <= max_size()
ensures
- #size() == size
- any element with index between 0 and size - 1 which was in the
array before the call to set_size() retains its value and index.
All other elements have undetermined (but valid for their type)
values. (e.g. this object might buffer old T objects and reuse
them without reinitializing them between calls to set_size())
- #at_start() == true
throws
- std::bad_alloc or any exception thrown by T's constructor
may throw this exception if there is not enough memory and
if it does throw then the call to set_size() has no effect
!*/
unsigned long max_size(
) const;
/*!
ensures
- returns the maximum size of *this
!*/
void set_max_size(
unsigned long max
);
/*!
ensures
- #max_size() == max
- #size() == 0
- #at_start() == true
throws
- std::bad_alloc or any exception thrown by T's constructor
may throw this exception if there is not enough
memory and if it does throw then max_size() == 0
!*/
void swap (
array<T>& item
);
/*!
ensures
- swaps *this and item
!*/
private:
// restricted functions
array(array<T>&); // copy constructor
array<T>& operator=(array<T>&); // assignment operator
};
template <
typename T
>
inline void swap (
array<T>& a,
array<T>& b
) { a.swap(b); }
/*!
provides a global swap function
!*/
template <
typename T
>
void serialize (
const array<T>& item,
std::ostream& out
);
/*!
provides serialization support
!*/
template <
typename T
>
void deserialize (
array<T>& item,
std::istream& in
);
/*!
provides deserialization support
!*/
}
#endif // DLIB_ARRAY_KERNEl_ABSTRACT_
// Copyright (C) 2003 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY_KERNEl_C_
#define DLIB_ARRAY_KERNEl_C_
#include "array_kernel_abstract.h"
#include "../algs.h"
#include "../assert.h"
namespace dlib
{
template <
typename array_base
>
class array_kernel_c : public array_base
{
typedef typename array_base::type T;
public:
const T& operator[] (
unsigned long pos
) const;
T& operator[] (
unsigned long pos
);
void set_size (
unsigned long size
);
const T& element (
) const;
T& element(
);
};
template <
typename array_base
>
inline void swap (
array_kernel_c<array_base>& a,
array_kernel_c<array_base>& b
) { a.swap(b); }
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
const typename array_base::type& array_kernel_c<array_base>::
operator[] (
unsigned long pos
) const
{
// make sure requires clause is not broken
DLIB_CASSERT( pos < this->size() ,
"\tconst T& array::operator[]"
<< "\n\tpos must < size()"
<< "\n\tpos: " << pos
<< "\n\tsize(): " << this->size()
<< "\n\tthis: " << this
);
// call the real function
return array_base::operator[](pos);
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
typename array_base::type& array_kernel_c<array_base>::
operator[] (
unsigned long pos
)
{
// make sure requires clause is not broken
DLIB_CASSERT( pos < this->size() ,
"\tT& array::operator[]"
<< "\n\tpos must be < size()"
<< "\n\tpos: " << pos
<< "\n\tsize(): " << this->size()
<< "\n\tthis: " << this
);
// call the real function
return array_base::operator[](pos);
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
void array_kernel_c<array_base>::
set_size (
unsigned long size
)
{
// make sure requires clause is not broken
DLIB_CASSERT(( size <= this->max_size() ),
"\tvoid array::set_size"
<< "\n\tsize must be <= max_size()"
<< "\n\tsize: " << size
<< "\n\tmax size: " << this->max_size()
<< "\n\tthis: " << this
);
// call the real function
array_base::set_size(size);
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
const typename array_base::type& array_kernel_c<array_base>::
element (
) const
{
// make sure requires clause is not broken
DLIB_CASSERT(this->current_element_valid(),
"\tconst T& array::element()"
<< "\n\tThe current element must be valid if you are to access it."
<< "\n\tthis: " << this
);
// call the real function
return array_base::element();
}
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
typename array_base::type& array_kernel_c<array_base>::
element (
)
{
// make sure requires clause is not broken
DLIB_CASSERT(this->current_element_valid(),
"\tT& array::element()"
<< "\n\tThe current element must be valid if you are to access it."
<< "\n\tthis: " << this
);
// call the real function
return array_base::element();
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_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_ARRAY_SORt_1_
#define DLIB_ARRAY_SORt_1_
#include "array_sort_abstract.h"
#include "../algs.h"
#include "../sort.h"
namespace dlib
{
template <
typename array_base
>
class array_sort_1 : public array_base
{
typedef typename array_base::type T;
public:
/*!
this is a median of three version of the QuickSort algorithm and
it swaps the entire array into a temporary C style array and sorts that and
this uses the dlib::qsort_array function
!*/
void sort (
);
};
template <
typename array_base
>
inline void swap (
array_sort_1<array_base>& a,
array_sort_1<array_base>& b
) { a.swap(b); }
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
void array_sort_1<array_base>::
sort (
)
{
if (this->size() > 1)
{
T* temp = new T[this->size()];
for (unsigned long i = 0; i < this->size(); ++i)
exchange(temp[i],(*this)[i]);
// call the quick sort function for arrays that is in algs.h
dlib::qsort_array(temp,0,this->size()-1);
for (unsigned long i = 0; i < this->size(); ++i)
exchange((*this)[i],temp[i]);
delete [] temp;
}
this->reset();
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_SORt_1_
// Copyright (C) 2003 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY_SORt_2_
#define DLIB_ARRAY_SORt_2_
#include "array_sort_abstract.h"
#include "../algs.h"
#include "../sort.h"
namespace dlib
{
template <
typename array_base
>
class array_sort_2 : public array_base
{
public:
/*!
this is a median of three version of the QuickSort algorithm and
this uses the dlib::qsort_array function
!*/
void sort (
);
};
template <
typename array_base
>
inline void swap (
array_sort_2<array_base>& a,
array_sort_2<array_base>& b
) { a.swap(b); }
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename array_base
>
void array_sort_2<array_base>::
sort (
)
{
if (this->size() > 1)
{
// call the quick sort function for arrays that is in algs.h
dlib::qsort_array(*this,0,this->size()-1);
}
this->reset();
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_SORt_2_
// Copyright (C) 2003 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_ARRAY_SORt_ABSTRACT_
#ifdef DLIB_ARRAY_SORt_ABSTRACT_
#include "array_kernel_abstract.h"
namespace dlib
{
template <
typename array_base
>
class array_sort : public array_base
{
/*!
REQUIREMENTS ON ARRAY_BASE
must be an implementation of array/array_kernel_abstract.h
POINTERS AND REFERENCES
sort() may invalidate pointers and references to internal data.
WHAT THIS EXTENSION DOES FOR ARRAY
This gives an array the ability to sort its contents by calling sort().
!*/
public:
void sort (
);
/*!
ensures
- for all elements in #*this the ith element is <= the i+1 element
- #at_start() == true
throws
- std::bad_alloc or any exception thrown by T's constructor
data may be lost if sort() throws
!*/
};
template <
typename array_base
>
inline void swap (
array_sort<array_base>& a,
array_sort<array_base>& b
) { a.swap(b); }
/*!
provides a global swap function
!*/
}
#endif // DLIB_ARRAY_SORt_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_
#define DLIB_ARRAY2d_
#include "array2d/array2d_kernel_1.h"
#include "array2d/array2d_kernel_c.h"
#include "memory_manager.h"
namespace dlib
{
template <
typename T,
typename mem_manager = memory_manager<char>::kernel_1a
>
class array2d
{
array2d() {}
public:
//----------- kernels ---------------
// kernel_1a
typedef array2d_kernel_1<T,mem_manager>
kernel_1a;
typedef array2d_kernel_c<kernel_1a>
kernel_1a_c;
};
}
#endif // DLIB_ARRAY2d_
// 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_1_
#define DLIB_ARRAY2D_KERNEl_1_
#include "array2d_kernel_abstract.h"
#include "../algs.h"
#include "../interfaces/enumerable.h"
#include "../serialize.h"
#include "../memory_manager.h"
namespace dlib
{
template <
typename T,
typename mem_manager = memory_manager<char>::kernel_1a
>
class array2d_kernel_1 : public enumerable<T>
{
/*!
INITIAL VALUE
- nc_ == 0
- nr_ == 0
- data == 0
- rows == 0
- at_start_ == true
- cur == 0
- last == 0
CONVENTION
- nc_ == nc()
- nr_ == nc()
- if (data != 0) then
- last == a pointer to the last element in the data array
- data == pointer to an array of nc_*nr_ T objects
- rows == pointer to an array of nr_ row objects
- for all x < nr_:
- rows[x].data == data + x*nc_
- rows[x].nc_ == nc_
- else
- nc_ == 0
- nr_ == 0
- data == 0
- rows == 0
- last == 0
- nr_ * nc_ == size()
- if (cur == 0) then
- current_element_valid() == false
- else
- current_element_valid() == true
- *cur == element()
- at_start_ == at_start()
!*/
class row_helper;
public:
typedef T type;
typedef mem_manager mem_manager_type;
// -----------------------------------
class row
{
/*!
CONVENTION
- nc_ == nc()
- for all x < nc_:
- (*this)[x] == data[x]
!*/
friend class array2d_kernel_1;
friend class row_helper;
public:
long nc (
) const { return nc_; }
const T& operator[] (
long column
) const { return data[column]; }
T& operator[] (
long column
) { return data[column]; }
private:
long nc_;
T* data;
// restricted functions
row(){}
row(row&);
row& operator=(row&);
};
// -----------------------------------
array2d_kernel_1 (
) :
nc_(0),
nr_(0),
rows(0),
data(0),
cur(0),
last(0),
at_start_(true)
{
}
virtual ~array2d_kernel_1 (
) { clear(); }
long nc (
) const { return nc_; }
long nr (
) const { return nr_; }
row& operator[] (
long row
) { return rows[row]; }
const row& operator[] (
long row
) const { return rows[row]; }
void swap (
array2d_kernel_1& item
)
{
exchange(data,item.data);
exchange(rows,item.rows);
exchange(nr_,item.nr_);
exchange(nc_,item.nc_);
exchange(at_start_,item.at_start_);
exchange(cur,item.cur);
exchange(last,item.last);
pool.swap(item.pool);
rpool.swap(item.rpool);
}
void clear (
)
{
if (data != 0)
{
rpool.deallocate_array(reinterpret_cast<row_helper*>(rows));
pool.deallocate_array(data);
nc_ = 0;
nr_ = 0;
rows = 0;
data = 0;
at_start_ = true;
cur = 0;
last = 0;
}
}
void set_size (
long nr__,
long nc__
);
bool at_start (
) const { return at_start_; }
void reset (
) const { at_start_ = true; cur = 0; }
bool current_element_valid (
) const { return (cur != 0); }
const T& element (
) const { return *cur; }
T& element (
) { return *cur; }
bool move_next (
) const
{
if (cur != 0)
{
if (cur != last)
{
++cur;
return true;
}
cur = 0;
return false;
}
else if (at_start_)
{
cur = data;
at_start_ = false;
return (data != 0);
}
else
{
return false;
}
}
unsigned long size (
) const { return static_cast<unsigned long>(nc_ * nr_); }
private:
// this object exists just so we can have a row type object that
// has a public default constructor so the memory_manager can construct it.
// I would have made rpool a friend of row but some compilers can't handle
// that without crapping out.
class row_helper : public row {};
typename mem_manager::template rebind<T>::other pool;
typename mem_manager::template rebind<row_helper>::other rpool;
long nc_;
long nr_;
row* rows;
T* data;
mutable T* cur;
T* last;
mutable bool at_start_;
// restricted functions
array2d_kernel_1(array2d_kernel_1&); // copy constructor
array2d_kernel_1& operator=(array2d_kernel_1&); // assignment operator
};
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
inline void swap (
array2d_kernel_1<T,mem_manager>& a,
array2d_kernel_1<T,mem_manager>& b
) { a.swap(b); }
template <
typename T,
typename mem_manager
>
void serialize (
const array2d_kernel_1<T,mem_manager>& 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_1");
}
}
template <
typename T
>
void deserialize (
array2d_kernel_1<T>& 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_1");
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename T,
typename mem_manager
>
void array2d_kernel_1<T,mem_manager>::
set_size (
long nr__,
long nc__
)
{
// set the enumerator back at the start
at_start_ = true;
cur = 0;
// don't do anything if we are already the right size.
if (nc_ == nc__ && nr_ == nr__)
{
return;
}
nc_ = nc__;
nr_ = nr__;
// free any existing memory
if (data != 0)
{
pool.deallocate_array(data);
rpool.deallocate_array(reinterpret_cast<row_helper*>(rows));
data = 0;
rows = 0;
}
// now setup this object to have the new size
try
{
if (nr_ > 0)
{
rows = rpool.allocate_array(nr_);
data = pool.allocate_array(nr_*nc_);
last = data + nr_*nc_ - 1;
}
}
catch (...)
{
if (rows)
rpool.deallocate_array(reinterpret_cast<row_helper*>(rows));
if (data)
pool.deallocate_array(data);
rows = 0;
data = 0;
nc_ = 0;
nr_ = 0;
last = 0;
throw;
}
// now set up all the rows
for (long i = 0; i < nr_; ++i)
{
rows[i].nc_ = nc_;
rows[i].data = data + i*nc_;
}
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY2D_KERNEl_1_
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