KHtml

array2d.h
1 /*
2  Large image displaying library.
3 
4  Copyright (C) 2004,2005 Maks Orlovich ([email protected])
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20  AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 
23 */
24 #ifndef ARRAY2D_H
25 #define ARRAY2D_H
26 
27 namespace khtmlImLoad
28 {
29 
34 template <typename T>
35 class Array2D
36 {
37 private:
38  T *data;
39  unsigned int cols;
40  unsigned int rows;
41 public:
42  Array2D(unsigned int _cols, unsigned int _rows):
43  data(new T[_cols *_rows]), cols(_cols), rows(_rows)
44  {}
45 
46  Array2D()
47  {
48  data = 0;
49  rows = 0;
50  cols = 0;
51  }
52 
53  ~Array2D()
54  {
55  delete[] data;
56  }
57 
58  //Note: this is meant to be used only on empty objects
59  Array2D &operator=(const Array2D &other)
60  {
61  assert(data == 0);
62  data = other.data;
63  cols = other.cols;
64  rows = other.rows;
65  return *this;
66  }
67 
68  T &at(unsigned int col, unsigned int row)
69  {
70  return data[row * cols + col];
71  }
72 
73  const T &at(unsigned int col, unsigned int row) const
74  {
75  return data[row * cols + col];
76  }
77 private:
78  Array2D(const Array2D &other);
79 };
80 
81 }
82 
83 #endif
A little helper template for nicer 2D arrays.
Definition: array2d.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 5 2020 22:46:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.