Lunchbox  1.17.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
array.h
1 
2 /* Copyright (c) 2012-2014, Stefan Eilemann <eile@eyescale.ch>
3  *
4  * This file is part of Lunchbox <https://github.com/Eyescale/Lunchbox>
5  *
6  * This library is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 2.1 as published
8  * by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef LUNCHBOX_ARRAY_H
21 #define LUNCHBOX_ARRAY_H
22 
23 #include <lunchbox/debug.h>
24 #include <lunchbox/types.h>
25 
26 namespace lunchbox
27 {
29 template <class T>
30 class Array
31 {
32 public:
34  Array(T* data_, const size_t num_)
35  : data(data_)
36  , num(num_)
37  {
38  }
39 
41  size_t getNumBytes() const { return num * sizeof(T); }
42  T* data;
43  size_t num;
44 };
45 
46 template <>
47 inline size_t Array<void>::getNumBytes() const
48 {
49  return num;
50 }
51 template <>
52 inline size_t Array<const void>::getNumBytes() const
53 {
54  return num;
55 }
56 
58 template <class T>
59 inline std::ostream& operator<<(std::ostream& os, const Array<T>& array)
60 {
61  return os << lunchbox::format(array.data, array.num);
62 }
63 }
64 #endif // LUNCHBOX_ARRAY_H
A wrapper for C arrays without any memory management.
Definition: array.h:30
Array(T *data_, const size_t num_)
Create a new array wrapper for the given data.
Definition: array.h:34
Basic type definitions not provided by the operating system.
size_t getNumBytes() const
Definition: array.h:41
std::string format(const T *data, const size_t num)
Format the given array in a human-readable form.
Definition: debug.h:101
size_t num
The number of elements in the data.
Definition: array.h:43
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:29
T * data
The data.
Definition: array.h:42