PageRenderTime 1ms CodeModel.GetById 32ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/lltable.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 66 lines | 37 code | 4 blank | 25 comment | 7 complexity | f096db0dd9d34c82c1a7f568eb13c51a MD5 | raw file
 1/** 
 2 * @file lltable.h
 3 * @brief Description of LLTable template class
 4 *
 5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#ifndef LL_LLTABLE_H
28#define LL_LLTABLE_H
29
30template<class T> class LLTable
31{
32private:
33	T	*_tab;
34	U32	_w;
35	U32 _h;
36	U32 _size;
37public:
38	LLTable(U32 w, U32 h = 0) : _tab(0), _w(w), _h(h)
39	{
40		if (_w < 0) _w = 0;
41		if (_h < 0) _h = 0;
42		if (0 == h)
43			_h = _w;
44		_size = _w * _h;
45		if ((_w > 0) && (_h > 0))
46			_tab = new T[_size];
47	}
48
49	~LLTable()
50	{
51		delete[] _tab;
52		_tab = NULL;
53	}
54
55	void init(const T& t)
56	{
57		for (U32 i = 0; i < _size; ++i)
58			_tab[i] = t;
59	}
60	const T& at(U32 w, U32 h) const { return _tab[h * _w + w]; }
61	T& at(U32 w, U32 h) { return _tab[h * _w + w]; }
62	U32 size() const { return _size; }
63	U32 w() const { return _w; }
64	U32 h() const { return _h; }
65};
66#endif // LL_LLTABLE_H