iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DenseDataImpl.H
Go to the documentation of this file.
1 /*! @file
2  @author Shane Grant <wgrant@usc.edu>
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 #ifndef INCLUDE_NRT_POINTCLOUD2_DETAILS_DENSEDATAIMPL_H
37 #define INCLUDE_NRT_POINTCLOUD2_DETAILS_DENSEDATAIMPL_H
38 
39 size_t const nrt::DenseData::size() const
40 {
41  return itsNumElems;
42 }
43 
44 std::string const & nrt::DenseData::name() const
45 {
46  return itsName;
47 }
48 
49 size_t const nrt::DenseData::convertIndex( size_t const index ) const
50 {
51  return index * itsElemSize;
52 }
53 
54 template <class T> inline
55 T & nrt::DenseData::get( size_t index )
56 {
57  if( index >= itsNumElems )
58  throw nrt::exception::DenseDataBoundsException( index, itsNumElems, itsName );
59 
60  return *reinterpret_cast<T*>( &itsData[convertIndex( index )] );
61 }
62 
63 template <class T> inline
64 T const & nrt::DenseData::get( size_t index ) const
65 {
66  if( index >= itsNumElems )
67  throw nrt::exception::DenseDataBoundsException( index, itsNumElems, itsName );
68 
69  return *reinterpret_cast<T const * const>( &itsData[convertIndex( index )] );
70 }
71 
72 template <class T> inline
73 T * const nrt::DenseData::ptr( size_t index )
74 {
75  if( index >= itsNumElems )
76  throw nrt::exception::DenseDataBoundsException( index, itsNumElems, itsName );
77 
78  return reinterpret_cast<T * const>( &itsData[convertIndex( index )] );
79 }
80 
81 template <class T> inline
82 T const * const nrt::DenseData::ptr( size_t index ) const
83 {
84  if( index >= itsNumElems )
85  throw nrt::exception::DenseDataBoundsException( index, itsNumElems, itsName );
86 
87  return reinterpret_cast<T const * const>( &itsData[convertIndex( index )] );
88 }
89 
90 template <class T> inline
92 {
93  return reinterpret_cast<T *>( &itsData[0] );
94 }
95 
96 template <class T> inline
97 T const * nrt::DenseData::begin() const
98 {
99  return reinterpret_cast<T const *>( &itsData[0] );
100 }
101 
102 template <class T> inline
104 {
105  return reinterpret_cast<T *>( &itsData[itsData.size()] );
106 }
107 
108 template <class T> inline
109 T const * nrt::DenseData::end() const
110 {
111  return reinterpret_cast<T const *>( &itsData[itsData.size()] );
112 }
113 
114 template <class T> inline
115 size_t nrt::DenseData::insert( T const & data )
116 {
117  itsData.insert( itsData.end(), itsElemSize, 0 );
118  *reinterpret_cast<T*>( &itsData[convertIndex( itsNumElems )] ) = data;
119  ++itsNumElems;
120 
121  return itsNumElems - 1;
122 }
123 
124 #endif // INCLUDE_NRT_POINTCLOUD2_DETAILS_DENSEDATAIMPL_H