Lunchbox  1.11.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/types.h>
24 #include <lunchbox/debug.h>
25 
26 namespace lunchbox
27 {
29 template< class T > class Array
30 {
31 public:
33  Array( T* data_, const size_t num_ ) : data( data_ ), num( num_ ) {}
34 
36  size_t getNumBytes() const { return num * sizeof( T ); }
37 
38  T* data;
39  size_t num;
40 };
41 
42 template<> inline size_t Array< void >::getNumBytes() const { return num; }
43 template<> inline size_t Array< const void >::getNumBytes() const { return num;}
44 
46 template< class T >
47 inline std::ostream& operator << ( std::ostream& os, const Array< T >& array )
48 {
49  return os << lunchbox::format( array.data, array.num );
50 }
51 
52 }
53 #endif // LUNCHBOX_ARRAY_H
A wrapper for C arrays without any memory management.
Definition: array.h:29
Array(T *data_, const size_t num_)
Create a new array wrapper for the given data.
Definition: array.h:33
Basic type definitions not provided by the operating system.
size_t getNumBytes() const
Definition: array.h:36
std::string format(const T *data, const size_t num)
Format the given array in a human-readable form.
Definition: debug.h:93
size_t num
The number of elements in the data.
Definition: array.h:39
T * data
The data.
Definition: array.h:38