Code Search for Developers
 
 
  

bopointeriterator.h from Boson at Krugle


Show bopointeriterator.h syntax highlighted

/*
    This file is part of the Boson game
    Copyright (C) 2003 Andreas Beckermann (b_mann@gmx.de)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef BOPOINTERITERATOR_H
#define BOPOINTERITERATOR_H

/**
 * This iterator class operates on an array of pointers. The array must have n+1
 * elements, where n is the number of actual elements and the last element is
 * simply NULL. A NULL pointer in the array marks the last element. You can use
 * this class like this:
 *
 * <pre>
 * BosonWeapon** weapons = new BosonWeapon*[numberOfWeapons + 1];
 * for (int i = 0; i < numberOfWeapons; i++) {
 *     weapons[i] = new BosonWeapon(...);
 * }
 * weapons[numberOfWeapons] = 0; // last element
 * [...]
 * BoPointerIterator it(weapons);
 * for (; *it; ++it) {
 *     (*it)->shootAtSomething();
 * }
 * </pre>
 *
 * As you can see the loops exits once it reaches the NULL pointer, i.e. once
 * *it returns NULL.
 * @author Andreas Beckermann <b_mann@gmx.de>
 * @short An iterator that operates on an array of pointers
 **/
template<class T> class BoPointerIterator
{
public:
	/**
	 * Construct a NULL iterator. You should use the assignement operator to
	 * make this useful
	 **/
	BoPointerIterator()
	{
		mPointer = 0;
		mCurrentPointer = 0;
	}

	/**
	 * Construct an iterator that operates on @p pointer.
	 *
	 * @p pointer MUST be an array with n + 1 elements, where n is the
	 * number of actual pointers. The last element of the pointer array must
	 * be NULL.
	 **/
	BoPointerIterator(T** pointer)
	{
		mPointer = pointer;
		toFirst();
	}

	/**
	 * Move the iterator to the first element in the array.
	 * @return The first element in the array this iterator operates on.
	 **/
	T* toFirst()
	{
		mCurrentPointer = mPointer;
		return *mCurrentPointer;
	}

	/**
	 * @return The current element.
	 **/
	inline T* operator*()
	{
		return *mCurrentPointer;
	}

	/**
	 * Operate on @p pointer and make pointer[0] the current element.
	 **/
	BoPointerIterator& operator=(T** pointer)
	{
		mPointer = pointer;
		toFirst();
		return *this;
	}

	/**
	 * Go to the next element in the array. The iterator will be in
	 * undefined state if the current element is already the last element.
	 *
	 * Note that we don't provide the postfix operator, but the prefix
	 * operator only. I.e. you can it ++it, but not it++.
	 **/
	inline BoPointerIterator& operator++()
	{
		mCurrentPointer++;
		return *this;
	}

private:
	T** mPointer;
	T** mCurrentPointer;
};

#endif





See more files for this project here

Boson

Boson is an OpenGL real-time strategy game. It is designed to run on Unix (Linux) computers, and is built on top of the KDE, Qt and kdegames libraries.

Project homepage: http://sourceforge.net/projects/boson
Programming language(s): C,C++
License: other

  boufo/
  data/
  docs/
  gameengine/
  gameview/
  groundrenderer/
  imageio/
  info/
  modelrendering/
  optionsdialog/
  programs/
  sound/
  startupwidgets/
  tests/
  CMakeLists.txt
  TODO
  bo3dtools.cpp
  bo3dtools.h
  boaction.cpp
  boaction.h
  boapplication.cpp
  boapplication.h
  boautocamera.cpp
  boautocamera.h
  bobtfload.cpp
  bobtfload.h
  bocamera.cpp
  bocamera.h
  bocamerawidget.cpp
  bocamerawidget.h
  bocheckinstallation.cpp
  bocheckinstallation.h
  boconditionwidget.cpp
  boconditionwidget.h
  bodebuglogdialog.cpp
  bodebuglogdialog.h
  bofiledialog.h
  bofullscreen.cpp
  bofullscreen.h
  boglobal.cpp
  boglobal.h
  boglstatewidget.cpp
  boglstatewidget.h
  bogltooltip.cpp
  bogltooltip.h
  bogroundrenderer.cpp
  bogroundrenderer.h
  bogroundrenderermanager.cpp
  bogroundrenderermanager.h
  bolight.cpp
  bolight.h
  bomaterial.cpp
  bomaterial.h
  bomaterialwidget.cpp
  bomaterialwidget.h
  bomath.cpp
  bomath.h
  bomatrixwidget.cpp
  bomatrixwidget.h
  bomousemovediff.cpp
  bomousemovediff.h
  bonuminput.cpp
  bonuminput.h
  boorbiterwidget.cpp
  boorbiterwidget.h
  bopixmaprenderer.cpp
  bopixmaprenderer.h
  bopluginmanager.cpp
  bopluginmanager.h
  bopointeriterator.h
  borendertarget.cpp
  borendertarget.h
  boshader.cpp
  boshader.h
  bosonconfig.cpp
  bosonconfig.h
  bosonconfigentries.cpp
  bosoncursor.cpp
  bosoncursor.h
  bosondata.cpp
  bosondata.h
  bosondebugmodels.cpp
  bosondebugmodels.h
  bosondebugmodelsbase.ui
  bosondebugtextures.cpp
  bosondebugtextures.h
  bosondebugtexturesbase.ui
  bosonfpscounter.cpp
  bosonfpscounter.h
  bosongameviewpluginbase.cpp
  bosongameviewpluginbase.h
  bosongameviewpluginmanager.cpp
  bosongameviewpluginmanager.h
  bosongameviewstarting.cpp
  bosongameviewstarting.h
  bosongldriverworkarounds.cpp
  bosongldriverworkarounds.h
  bosonglwidget.cpp
  bosonglwidget.h
  bosongroundthemedata.cpp
  bosongroundthemedata.h
  bosonguistarting.cpp
  bosonguistarting.h