diff --git a/doomsday/libs/core/include/de/DataArray b/doomsday/libs/core/include/de/DataArray new file mode 100644 index 0000000000..8e01bf2345 --- /dev/null +++ b/doomsday/libs/core/include/de/DataArray @@ -0,0 +1 @@ +#include "data/dataarray.h" diff --git a/doomsday/libs/core/include/de/data/dataarray.h b/doomsday/libs/core/include/de/data/dataarray.h new file mode 100644 index 0000000000..f1a81000af --- /dev/null +++ b/doomsday/libs/core/include/de/data/dataarray.h @@ -0,0 +1,61 @@ +/** @file dataarray.h Block interpreted as an array of C structs. + * + * @authors Copyright (c) 2018 Jaakko Keränen + * + * @par License + * LGPL: http://www.gnu.org/licenses/lgpl.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 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 Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this program; if not, see: + * http://www.gnu.org/licenses + */ + +#ifndef LIBCORE_DATAARRAY_H +#define LIBCORE_DATAARRAY_H + +#include "../Block" + +namespace de { + +template +class DataArray +{ +public: + DataArray(Block data) + : _data(std::move(data)) + , _entries(reinterpret_cast(_data.constData())) + , _size(int(_data.size() / sizeof(T))) + {} + + int size() const + { + return _size; + } + + const T &at(int pos) const + { + DENG2_ASSERT(pos >= 0); + DENG2_ASSERT(pos < _size); + return _entries[pos]; + } + + const T &operator[](int pos) const + { + return at(pos); + } + +private: + Block _data; + const T *_entries; + int _size; +}; + +} // namespace de + +#endif // LIBCORE_DATAARRAY_H