ForeverZer0

RMXP Table Class

Feb 18th, 2012
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2.  
  3. namespace RMXP.Builtins
  4. {
  5.     class Table
  6.     {
  7.         private int _xsize;
  8.         private int _ysize;
  9.         private int _zsize;
  10.         private int[] _data;
  11.  
  12.         public int XSize { get { return _xsize; } }
  13.         public int YSize { get { return _ysize; } }
  14.         public int ZSize { get { return _zsize; } }
  15.  
  16.         public Table(int xsize, int ysize, int zsize)
  17.         {
  18.             if (xsize < 1 || ysize < 1 || zsize < 1)
  19.                 throw (new ArgumentException("Table dimensions cannot be less than 1"));
  20.             else
  21.             {
  22.                 _xsize = xsize;
  23.                 _ysize = ysize;
  24.                 _zsize = zsize;
  25.                 _data = new int[xsize * ysize * zsize];
  26.             }
  27.         }
  28.  
  29.         public Table(int xsize, int ysize) : this(xsize, ysize, 1) { }
  30.  
  31.         public Table(int xsize) : this(xsize, 1, 1) { }
  32.  
  33.         public Table() : this(1, 1, 1) { }
  34.  
  35.         public int GetData(int x, int y, int z)
  36.         {
  37.             return _data[x + y * _xsize + z * _xsize * _ysize];
  38.         }
  39.  
  40.         public int GetData(int x, int y) { return GetData(x, y, 0); }
  41.  
  42.         public int GetData(int x) { return GetData(x, 0, 0); }
  43.  
  44.         public void SetData(int value, int x, int y, int z)
  45.         {
  46.             if (x > _xsize || y > _ysize || z > _zsize)
  47.                 throw (new ArgumentException("Index outside bounds of table"));
  48.             else
  49.                 _data[x + y * _xsize + z * _xsize * _ysize] = value;
  50.         }
  51.  
  52.         public void SetData(int value, int x, int y) { SetData(value, x, y, 0); }
  53.  
  54.         public void SetData(int value, int x) { SetData(value, x, 0, 0); }
  55.  
  56.         public void Resize(int xsize, int ysize, int zsize)
  57.         {
  58.             if (xsize < 1 || ysize < 1 || zsize < 1)
  59.                 throw (new ArgumentException("Table dimensions cannot be less than 1"));
  60.             else
  61.             {
  62.                 _xsize = xsize;
  63.                 _ysize = ysize;
  64.                 _zsize = zsize;
  65.                 int[] temp = new int[xsize * ysize * zsize];
  66.                 _data.CopyTo(temp, 0);
  67.                 _data = temp;
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment