⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oflist.h

📁 转化为DIB位图再显示出来的dicom文件C++代码
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * *  Copyright (C) 1997-2005, OFFIS * *  This software and supporting documentation were developed by * *    Kuratorium OFFIS e.V. *    Healthcare Information and Communication Systems *    Escherweg 2 *    D-26121 Oldenburg, Germany * *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER. * *  Module:  ofstd * *  Author:  Andreas Barth * *  Purpose: *          Defines a template list class with interfaces similar to the C++ Standard * *  Last Update:      $Author: meichel $ *  Update Date:      $Date: 2005/12/08 16:05:58 $ *  Source File:      $Source: /share/dicom/cvs-depot/dcmtk/ofstd/include/dcmtk/ofstd/oflist.h,v $ *  CVS/RCS Revision: $Revision: 1.22 $ *  Status:           $State: Exp $ * *  CVS/RCS Log at end of file * */#ifndef OFLIST_H#define OFLIST_H// Usage (only non standard)://   OFListInsert(InputIterator_type, T_type, c, pos, first, last)//                      Inserts the elements of type T in//                      range [first, last) into list c,//   OFListRemoveIf(Predicate_Type, T_type, c, pred)//                      Erases all elements of type T in the list referred by//                      an iterator i where pred(*i) == true.//                      Predicate_Type is the function type of pred//// Additional Remarks://   In some template functions one template parameter is another function.//   Some compilers  cannot determine automatically the type of template//   function parameters, so you must give  them a hint casting//   the parameter function to the correct type (e.g. NeXT gcc 2.5.8)#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */#include "dcmtk/ofstd/oftypes.h"#include "dcmtk/ofstd/ofcast.h"#ifndef HAVE_CLASS_TEMPLATE#error Your C++ compiler cannot handle class templates:#endif#if defined(HAVE_STL) || defined(HAVE_STL_LIST)// It is possible to use the standard template library list class since the// interface is nearly identical.// Important: If you want to use the standard template library (STL), no// variable within a namespace using a class of the STL shall have a name// of one class of the STL#include <list>#ifdef HAVE_STD_NAMESPACE#define OFList std::list#define OFListIterator(x) std::list< x >::iterator#define OFListConstIterator(x) std::list< x >::const_iterator#else#define OFList list#define OFListIterator(x) list< x >::iterator#define OFListConstIterator(x) list< x >::const_iterator#endif#define OFListInsert(InputIterator, T, c, pos, first, last) (c).insert((pos), (first), (last))#define OFListRemoveIf(Predicate, T, c, pred) (c).remove_if((pred))// workaround for "implicit typename" warning on gcc 3.x#if defined(HAVE_TYPENAME)#define OFLIST_TYPENAME typename#else#define OFLIST_TYPENAME#endif#else#define INCLUDE_CASSERT#define INCLUDE_CSTDDEF#include "dcmtk/ofstd/ofstdinc.h"#define OFLIST_TYPENAME// OFListLinkBase, OFListLink and OFListBase are classes for internal// use only and shall not be used./* non-template double linked list. Base class fo OFListLink. * Implicitly used by OFList, should not be called by users. */struct OFListLinkBase{    OFListLinkBase * next;    OFListLinkBase * prev;    OFBool dummy;    OFListLinkBase(): next(NULL), prev(NULL), dummy(OFFalse) { }    virtual ~OFListLinkBase() {}  private:    /* undefined */ OFListLinkBase(const OFListLinkBase&);    /* undefined */ OFListLinkBase& operator=(const OFListLinkBase&);};/* non-template list. Base class fo OFList. * Implicitly used by OFList, should not be called by users. */class OFListBase{protected:    OFListLinkBase * afterLast;    size_t listSize;    void base_recalcListSize();public:    OFListBase();    virtual ~OFListBase();    OFListLinkBase * base_begin() const { return afterLast->next; }    OFListLinkBase * base_end() const { return afterLast; }    OFBool base_empty() const { return afterLast == afterLast->next; }    size_t base_size() const { return listSize; }    OFListLinkBase * base_insert(OFListLinkBase * pos, OFListLinkBase * newElem);    OFListLinkBase * base_erase(OFListLinkBase * pos);    void base_splice(OFListLinkBase * pos,                OFListLinkBase * begin, OFListLinkBase * end);    void base_clear();  private:    /* undefined */ OFListBase(const OFListBase&);    /* undefined */ OFListBase& operator=(const OFListBase&);};/* template class for double linked list entries. * Implicitly used by OFList, should not be called by users. */template <class T>struct OFListLink : public OFListLinkBase{    T info;    OFListLink(const T& i) : OFListLinkBase(), info(i)  { }    virtual ~OFListLink() {}  private:    /* undefined */ OFListLink(const OFListLink<T>&);    /* undefined */ OFListLink<T>& operator=(const OFListLink<T>&);};// Definition of OFList and OFIteratortemplate <class T> class OFList;/** iterator class for OFList. An iterator is a generalization of a pointer *  and allows a C++ program to work with different containers independently *  from their internal structure. Instances of this template class should *  be declared as OFListIterator(T) instead of OFListIterator<T>.  This *  allows to re-map OFList to the STL list class if available. */template <class T>class OFIterator{    friend class OFList<T>;protected:    /// list node referenced by the iterator    OFListLinkBase * node;    /** constructor.     *  @param x list node referenced by the iterator     */    OFIterator(OFListLinkBase * x) : node(x) { }public:    /** default constructor. Creates an iterator referencing nothing.     *  In general, iterators should always be copy-constructed     *  in user code.     */    OFIterator() : node(NULL)  { }    /** copy constructor     */    OFIterator(const OFIterator<T>& x) : node(x.node) { };    /** copy assignment operator     */    OFIterator<T>& operator=(const OFIterator<T>& x)    {        node = x.node;        return *this;    }    /** comparison of two iterators.  The iterators are equal if and only if     *  they reference the same element, independent from the element values.     *  @param x iterator to be compared     *  @return OFTrue if equal, OFFalse otherwise.     */    OFBool operator==(const OFIterator<T>& x) const { return node == x.node; }    /** comparison of two iterators.  The iterators are equal if and only if     *  they reference the same element, independent from the element values.     *  @param x iterator to be compared     *  @return OFTrue if not equal, OFFalse otherwise.     */    OFBool operator!=(const OFIterator<T>& x) const { return node != x.node; }    /** dereferences the iterator. May only be called if iterator references     *  a valid element of a list.     *  @return reference to the element "pointed to" by the iterator.     */    T& operator*() const    {        assert(!node->dummy);        return (OFstatic_cast(OFListLink<T> *,node))->info;    }    /** moves the iterator to the next element of the list.     *  The list is circular: the first element follows after the end of the list.     *  May only be called if iterator references a valid element or the end of a list.     *  @return reference to the incremented iterator.     */    OFIterator<T>& operator++()    {        node = node->next;        return *this;    }    /** moves the iterator to the next element of the list.     *  The list is circular: the first element follows after the end of the list.     *  May only be called if iterator references a valid element or the end of a list.     *  This is the post-increment operator.     *  @return previous iterator state, by value     */    OFIterator<T> operator++(int)    {        OFIterator<T> tmp(*this);        node = node->next;        return tmp;    }    /** moves the iterator to the previous element of the list.     *  The list is circular: the end of the list follows before the first element.     *  May only be called if iterator references a valid element or the end of a list.     *  @return reference to the decremented iterator.     */    OFIterator<T>& operator--()    {        node = node->prev;        return *this;    }    /** moves the iterator to the previous element of the list.     *  The list is circular: the end of the list follows before the first element.     *  May only be called if iterator references a valid element or the end of a list.     *  This is the post-decremented operator.     *  @return previous iterator state, by value     */    OFIterator<T> operator--(int)    {        OFIterator<T> tmp(*this);        node = node->prev;        return tmp;    }};/** double linked list template class. The interface is a subset of the STL *  list class. */template <class T>class OFList : private OFListBase{public:    /** inserts an element into the list before the given position.     *  @param position iterator to position before which the element is inserted     *  @param x value from which the new list entry is copy-constructed     *  @return iterator pointing to the new element in the list     */    OFIterator<T> insert(OFIterator<T> position, const T& x)    {      return OFIterator<T>(OFListBase::base_insert(position.node, new OFListLink<T>(x)));    }private:    /** inserts a copy of the given list into the current list.     *  @param oldList list to be copied     */    void copy(const OFList<T>& oldList)    {        OFIterator<T> vfirst(oldList.begin());        OFIterator<T> vend(oldList.end());        OFIterator<T> vpos(this->end());        while (vfirst != vend)        {            insert(vpos, *vfirst);            ++vfirst;        }    }    /** counts the elements in the list and adjusts the listSize     *  member variable.     */    void recalcListSize() { OFListBase::base_recalcListSize(); }public:    /** default constructor

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -