vcl_list.h
来自「DTMK软件开发包,此为开源软件,是一款很好的医学图像开发资源.」· C头文件 代码 · 共 645 行 · 第 1/2 页
H
645 行
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* Exception Handling:
* Copyright (c) 1997
* Mark of the Unicorn, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Mark of the Unicorn makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* Adaptation:
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Moscow Center for SPARC Technology makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef vcl_emulation_list_h
#define vcl_emulation_list_h
#include <vcl_new.h>
#include <vcl_cstddef.h>
#include "vcl_algobase.h"
#include "vcl_iterator.h"
#include "vcl_alloc.h"
# if defined ( __STL_USE_ABBREVS )
# define __list_iterator LIt
# define __list_const_iterator LcIt
# endif
template <class T> struct __list_iterator;
template <class T> struct __list_const_iterator;
template <class T>
struct __list_node {
typedef void* void_pointer;
void_pointer next;
void_pointer prev;
T data;
};
template<class T>
struct __list_iterator {
typedef __list_iterator<T> iterator;
typedef __list_const_iterator<T> const_iterator;
typedef T value_type;
typedef value_type* pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef vcl_size_t size_type;
typedef vcl_ptrdiff_t difference_type;
typedef __list_node<T>* link_type;
link_type node;
__list_iterator(link_type x) : node(x) {}
__list_iterator() {}
bool operator==(const iterator& x) const {
__stl_debug_check(__check_same_owner(*this,x));
return node == x.node;
}
bool operator!=(const iterator& x) const {
__stl_debug_check(__check_same_owner(*this,x));
return node != x.node;
}
reference operator*() const {
__stl_verbose_assert(node!=owner(), __STL_MSG_NOT_DEREFERENCEABLE);
return (*node).data;
}
iterator& operator++() {
__stl_verbose_assert(node!=owner(), __STL_MSG_INVALID_ADVANCE);
node = (link_type)((*node).next);
return *this;
}
iterator operator++(int) {
iterator tmp = *this;
++*this;
return tmp;
}
iterator& operator--() {
node = (link_type)((*node).prev);
__stl_verbose_assert(node!=owner(), __STL_MSG_INVALID_ADVANCE);
return *this;
}
iterator operator--(int) {
iterator tmp = *this;
--*this;
return tmp;
}
};
template<class T>
struct __list_const_iterator {
typedef __list_iterator<T> iterator;
typedef __list_const_iterator<T> const_iterator;
typedef T value_type;
typedef value_type* pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef vcl_size_t size_type;
typedef vcl_ptrdiff_t difference_type;
typedef __list_node<T>* link_type;
link_type node;
__list_const_iterator(link_type x) : node(x) {}
__list_const_iterator(const iterator& x) : node(x.node) {}
__list_const_iterator() {}
bool operator==(const const_iterator& x) const {
__stl_debug_check(__check_same_owner(*this,x));
return node == x.node;
}
bool operator!=(const const_iterator& x) const {
__stl_debug_check(__check_same_owner(*this,x));
return node != x.node;
}
const_reference operator*() const {
__stl_verbose_assert(node!=owner(), __STL_MSG_NOT_DEREFERENCEABLE);
return (*node).data; }
const_iterator& operator++() {
__stl_verbose_assert(node!=owner(), __STL_MSG_INVALID_ADVANCE);
node = (link_type)((*node).next);
return *this;
}
const_iterator operator++(int) {
const_iterator tmp = *this;
++*this;
return tmp;
}
const_iterator& operator--() {
node = (link_type)((*node).prev);
__stl_verbose_assert(node!=owner(), __STL_MSG_INVALID_ADVANCE);
return *this;
}
const_iterator operator--(int) {
const_iterator tmp = *this;
--*this;
return tmp;
}
};
template <class T>
inline vcl_bidirectional_iterator_tag
iterator_category(const __list_iterator<T>&) {
return vcl_bidirectional_iterator_tag();
}
template <class T>
inline T*
value_type(const __list_iterator<T>&) {
return (T*) 0;
}
template <class T>
inline vcl_ptrdiff_t*
distance_type(const __list_iterator<T>&) {
return (vcl_ptrdiff_t*) 0;
}
template <class T>
inline vcl_bidirectional_iterator_tag
iterator_category(const __list_const_iterator<T>&) {
return vcl_bidirectional_iterator_tag();
}
template <class T>
inline T*
value_type(const __list_const_iterator<T>&) {
return (T*) 0;
}
template <class T>
inline vcl_ptrdiff_t*
distance_type(const __list_const_iterator<T>&) {
return (vcl_ptrdiff_t*) 0;
}
template <class T, class Alloc>
class __list_base {
typedef __list_base<T,Alloc> self;
typedef T value_type;
typedef vcl_size_t size_type;
typedef __list_node<T> list_node;
typedef list_node* link_type;
protected:
typedef vcl_simple_alloc<list_node, Alloc> list_node_allocator;
link_type node;
size_type length;
public:
__list_base() {
node = get_node();
(*node).next = node;
(*node).prev = node;
length=0;
__stl_debug_do(iter_list.safe_init(node));
}
~__list_base() {
clear();
put_node(node);
__stl_debug_do(iter_list.invalidate());
}
protected:
link_type get_node() { return list_node_allocator::allocate(); }
void put_node(link_type p) { list_node_allocator::deallocate(p); }
inline void clear();
};
template <class T, class Alloc>
void __list_base<T, Alloc>::clear()
{
link_type cur = (link_type) node->next;
while (cur != node) {
link_type tmp = cur;
cur = (link_type) cur->next;
vcl_destroy(&(tmp->data));
put_node(tmp);
}
__stl_debug_do(invalidate_all());
}
__BEGIN_STL_FULL_NAMESPACE
# define list __WORKAROUND_RENAME(list)
template <class T, VCL_DFL_TYPE_PARAM_STLDECL(Alloc,vcl_alloc) >
class vcl_list : protected __list_base<T, Alloc> {
typedef __list_base<T, Alloc> super;
typedef vcl_list<T, Alloc> self;
protected:
typedef void* void_pointer;
public:
typedef T value_type;
typedef value_type* pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef __list_node<T> list_node;
typedef list_node* link_type;
typedef vcl_size_t size_type;
typedef vcl_ptrdiff_t difference_type;
typedef __list_iterator<T> iterator;
typedef __list_const_iterator<T> const_iterator;
typedef vcl_reverse_bidirectional_iterator<const_iterator, value_type,
const_reference, difference_type>
const_reverse_iterator;
typedef vcl_reverse_bidirectional_iterator<iterator, value_type, reference,
difference_type>
reverse_iterator;
protected:
link_type make_node(const T& x) {
link_type tmp = get_node();
IUEg__TRY {
vcl_construct(&((*tmp).data), x);
}
# if defined ( __STL_USE_EXCEPTIONS )
catch(...) {
put_node(tmp);
throw;
}
# endif
return tmp;
}
public:
vcl_list() {}
iterator begin() { return (link_type)((*node).next); }
const_iterator begin() const { return (link_type)((*node).next); }
iterator end() { return node; }
const_iterator end() const { return node; }
reverse_iterator rbegin() { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
bool empty() const { return length == 0; }
size_type size() const { return length; }
size_type max_size() const { return size_type(-1); }
reference front() { return *begin(); }
const_reference front() const { return *begin(); }
reference back() { return *(--end()); }
const_reference back() const { return *(--end()); }
void swap(vcl_list<T, Alloc>& x) {
__stl_debug_do(iter_list.swap_owners(x.iter_list));
vcl_swap(node, x.node);
vcl_swap(length, x.length);
}
iterator insert(iterator position, const T& x) {
__stl_debug_check(__check_if_owner(node,position));
link_type tmp = make_node(x);
(*tmp).next = position.node;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?