Code Search for Developers
 
 
  

array.h from Boson at Krugle


Show array.h syntax highlighted

#ifndef GFXARRAY_INCLUDED // -*- C++ -*-
#define GFXARRAY_INCLUDED
#if !defined(__GNUC__)
#  pragma once
#endif

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

  These array classes extend the STL vector<> template to provide
  convenient 2-D and 3-D arrays.

  NOTE: This package used to provide array<T> and varray<T> templates
  that were alternatives to the STL vector<T> template.  Its purpose was
  to support some legacy code written in the days when few compilers
  understood STL.  Now that STL support is common, that code has been
  removed.

  $Id: array.h 5690 2005-02-14 14:21:56Z rivol $

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

#include "gfx.h"
#include <vector>

template<class T>
class array2 : public std::vector<T>
{
private:
    int W, H;

protected:
    array2() { }

public:
    array2(int w, int h) : std::vector<T>(w*h), W(w), H(h) { }

    T&       operator()(int i, int j)       { return (*this)[j*W+i]; }
    const T& operator()(int i, int j) const { return (*this)[j*W+i]; }

    int width() const { return W; }
    int height() const { return H; }
};

template<class T>
class array3 : public std::vector<T>
{
private:
    int W, H, D;

protected:
    array3() { }

public:
    array3(int w, int h, int d) : std::vector<T>(w*h*d), W(w), H(h), D(d) { }

    T& operator()(int i, int j, int k) { return (*this)[k*W*H + j*W+i]; }
    const T& operator()(int i,int j,int k) const {return (*this)[k*W*H+j*W+i];}

    int width() const { return W; }
    int height() const { return H; }
    int depth() const { return D; }
};

// GFXARRAY_INCLUDED
#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

  arcball.h
  array.h
  baseball.h
  geom3d.h
  geom4d.h
  gfx.h
  gl.h
  glext.h
  gltools.h
  gui.h
  intvec.h
  mat2.h
  mat3.h
  mat4.h
  mfc.h
  quat.h
  raster.h
  script.h
  symmat3.h
  symmat4.h
  trackball.h
  vec2.h
  vec3.h
  vec4.h
  wintools.h