<html><!-- Created using the cpp_pretty_printer from the dlib C++ library. See http://dlib.net for updates. --><head><title>dlib C++ Library - stack_kernel_abstract.h</title></head><body bgcolor='white'><pre> <font color='#009900'>// Copyright (C) 2003 Davis E. King (davis@dlib.net) </font><font color='#009900'>// License: Boost Software License See LICENSE.txt for the full license. </font><font color='#0000FF'>#undef</font> DLIB_STACK_KERNEl_ABSTRACT_ <font color='#0000FF'>#ifdef</font> DLIB_STACK_KERNEl_ABSTRACT_ <font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../interfaces/enumerable.h.html'>../interfaces/enumerable.h</a>" <font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../interfaces/remover.h.html'>../interfaces/remover.h</a>" <font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../serialize.h.html'>../serialize.h</a>" <font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../algs.h.html'>../algs.h</a>" <font color='#0000FF'>namespace</font> dlib <b>{</b> <font color='#0000FF'>template</font> <font color='#5555FF'><</font> <font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> mem_manager <font color='#5555FF'>=</font> default_memory_manager <font color='#5555FF'>></font> <font color='#0000FF'>class</font> <b><a name='stack'></a>stack</b> : <font color='#0000FF'>public</font> enumerable<font color='#5555FF'><</font>T<font color='#5555FF'>></font>, <font color='#0000FF'>public</font> remover<font color='#5555FF'><</font>T<font color='#5555FF'>></font> <b>{</b> <font color='#009900'>/*! REQUIREMENTS ON T T must be swappable by a global swap() and 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() and current() functions do not invalidate pointers or references to internal data. All other functions have no such guarantee. INITIAL VALUE size() == 0 ENUMERATION ORDER The enumerator will iterate over the elements in the stack in the same order they would be removed in by repeated calls to pop(). (e.g. current() would be the first element enumerated) WHAT THIS OBJECT REPRESENTS This is a last in first out stack containing items of type T. e.g. if the stack is {b,c,d,e} then a is put in the stack becomes {a,b,c,d,e} and then pop takes a back out returning the stack to {b,c,d,e} Also note that unless specified otherwise, no member functions of this object throw exceptions. !*/</font> <font color='#0000FF'>public</font>: <font color='#0000FF'>typedef</font> T type; <font color='#0000FF'>typedef</font> mem_manager mem_manager_type; <b><a name='stack'></a>stack</b> <font face='Lucida Console'>(</font> <font face='Lucida Console'>)</font>; <font color='#009900'>/*! ensures - #*this is properly initialized throws - std::bad_alloc or any exception thrown by T's constructor !*/</font> <font color='#0000FF'>virtual</font> ~<b><a name='stack'></a>stack</b> <font face='Lucida Console'>(</font> <font face='Lucida Console'>)</font>; <font color='#009900'>/*! ensures - all memory associated with *this has been released !*/</font> <font color='#0000FF'><u>void</u></font> <b><a name='clear'></a>clear</b><font face='Lucida Console'>(</font> <font face='Lucida Console'>)</font>; <font color='#009900'>/*! ensures - #*this has its initial value throws - std::bad_alloc or any exception thrown by T's constructor if this exception is thrown then *this is unusable until clear() is called and succeeds !*/</font> <font color='#0000FF'><u>void</u></font> <b><a name='push'></a>push</b> <font face='Lucida Console'>(</font> T<font color='#5555FF'>&</font> item <font face='Lucida Console'>)</font>; <font color='#009900'>/*! ensures - item has been swapped onto the top of the stack - #current() == item - #item has an initial value for its type - #size() == size() + 1 - #at_start() == true throws - std::bad_alloc or any exception thrown by T's constructor if push() throws then it has no effect !*/</font> <font color='#0000FF'><u>void</u></font> <b><a name='pop'></a>pop</b> <font face='Lucida Console'>(</font> T<font color='#5555FF'>&</font> item <font face='Lucida Console'>)</font>; <font color='#009900'>/*! requires - size() != 0 ensures - #size() == size() - 1 - #item == current() i.e. the top element of *this has been removed and swapped into #item - #at_start() == true !*/</font> T<font color='#5555FF'>&</font> <b><a name='current'></a>current</b> <font face='Lucida Console'>(</font> <font face='Lucida Console'>)</font>; <font color='#009900'>/*! requires - size() != 0 ensures - returns a const reference to the element at the top of *this !*/</font> <font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> <b><a name='current'></a>current</b> <font face='Lucida Console'>(</font> <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>; <font color='#009900'>/*! requires - size() != 0 ensures - returns a non-const reference to the element at the top of *this !*/</font> <font color='#0000FF'><u>void</u></font> <b><a name='swap'></a>swap</b> <font face='Lucida Console'>(</font> stack<font color='#5555FF'>&</font> item <font face='Lucida Console'>)</font>; <font color='#009900'>/*! ensures - swaps *this and item !*/</font> <font color='#0000FF'>private</font>: <font color='#009900'>// restricted functions </font> <b><a name='stack'></a>stack</b><font face='Lucida Console'>(</font>stack<font color='#5555FF'>&</font><font face='Lucida Console'>)</font>; <font color='#009900'>// copy constructor </font> stack<font color='#5555FF'>&</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>stack<font color='#5555FF'>&</font><font face='Lucida Console'>)</font>; <font color='#009900'>// assignment operator </font> <b>}</b>; <font color='#0000FF'>template</font> <font color='#5555FF'><</font> <font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> mem_manager <font color='#5555FF'>></font> <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='swap'></a>swap</b> <font face='Lucida Console'>(</font> stack<font color='#5555FF'><</font>T,mem_manager<font color='#5555FF'>></font><font color='#5555FF'>&</font> a, stack<font color='#5555FF'><</font>T,mem_manager<font color='#5555FF'>></font><font color='#5555FF'>&</font> b <font face='Lucida Console'>)</font> <b>{</b> a.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>b<font face='Lucida Console'>)</font>; <b>}</b> <font color='#009900'>/*! provides a global swap function !*/</font> <font color='#0000FF'>template</font> <font color='#5555FF'><</font> <font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> mem_manager <font color='#5555FF'>></font> <font color='#0000FF'><u>void</u></font> <b><a name='deserialize'></a>deserialize</b> <font face='Lucida Console'>(</font> stack<font color='#5555FF'><</font>T,mem_manager<font color='#5555FF'>></font><font color='#5555FF'>&</font> item, std::istream<font color='#5555FF'>&</font> in <font face='Lucida Console'>)</font>; <font color='#009900'>/*! provides deserialization support !*/</font> <b>}</b> <font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_STACK_KERNEl_ABSTRACT_ </font> </pre></body></html>