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

📄 oasisiterators.h

📁 使用stl技术,(还没看,是听说的)
💻 H
字号:
/******************************************************************************

 * This source file is part of Bad Camel Gaming

 * Copyright (C) 2003  Zephie Greyvenstein

 * See Readme.html for acknowledgements

 *

 * This library is free software; you can redistribute it and/or

 * modify it under the terms of the GNU Lesser General Public

 * License as published by the Free Software Foundation; either

 * version 2.1 of the License, or (at your option) any later version.

 *

 * This library is distributed in the hope that it will be useful,

 * but WITHOUT ANY WARRANTY; without even the implied warranty of

 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU

 * Lesser General Public License for more details.

 *

 * You should have received a copy of the GNU Lesser General Public

 * License along with this library; if not, write to the Free Software

 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 *****************************************************************************/



/******************************************************************************

 * FILENAME    : oasisIterators.h

 * DESCRIPTION : Container iterators

 * AUTHOR      : Zephie Greyvenstein

 *****************************************************************************/



/// Avoid double inclusion

#ifndef __ITERATORS_H__

#define __ITERATORS_H__



/// Include the common headers

#include "oasisCommon.h"



namespace Oasis {

  /// Allows the wrapping of containers in order to maintain abstraction

  /// of protected types while allowing users access to their values

  template < class T > class _oasisExport vectorIterator {   

  public:

    /// Constructor      

    vectorIterator( typename T::iterator startPoint,

		    typename T::const_iterator endPoint ) {

      current = startPoint;

      end = endPoint;

    }



    /// Checks for more elements

    const bool isEmpty( void ) const {

      return ( current == end );

    }

      

    /// Get the next elements  

    typename T::value_type getNext( void ) {

      return ( *current++ );

    }



    /// Gets the current element and does not advance

    typename T::value_type getCurrent( void ) {

      return ( *current );

    }



    /// Gets a pointer to the current element and does not advance

    typename T::pointer getCurrentPtr( void ) {

      return &( *current );

    }



    /// Move to next element

    void moveNext( void ) {

      current++;

    }

    

  protected:

    /// The current position in the vector

    typename T::iterator current;

    /// The end position in the vector

    typename T::const_iterator end;

    

  private:

    /// This constructor should not be used

    vectorIterator( ) {};

  };

  

  /// Allows the wrapping of containers in order to maintain abstraction

  /// of protected types while allowing users access to their values

  template < class T > class _oasisExport mapIterator {

  public:

    /// Contructor

    mapIterator( typename T::iterator startPoint,

		 typename T::iterator endPoint ) {

      current = startPoint;

      end = endPoint;

    }

    

    /// Checks for more elements

    const bool isEmpty( void ) {

      return ( current == end );

    }

    

    /// Gets the next key

    typename T::key_type getNextKey( void ) {

      return ( current++ )->first;

    }

    

    /// Gets the next value

    typename T::mapped_type getNextValue( void ) {

      return ( current++ )->second;

    }

    

    /// Gets the current key

    typename T::key_type getCurrentKey( void ) {

      return ( current )->first;

    }

    

    /// Gets the current value

    typename T::mapped_type getCurrentValue( void ) {

      return ( current )->second;

    }

    

  protected:

    /// The current position in the container

    typename T::iterator current;

    /// The end position in the container

    typename T::iterator end;

    

  private:

    /// This constructor should not be used

    mapIterator( ) {}

  };

};



#endif

⌨️ 快捷键说明

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