USRP Hardware Driver and USRP Manual  Version: 003.009.005-0-g32951af2
UHD and USRP Manual
ref_vector.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2011 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_UHD_TYPES_REF_VECTOR_HPP
19 #define INCLUDED_UHD_TYPES_REF_VECTOR_HPP
20 
21 #include <uhd/config.hpp>
22 #include <cstddef>
23 
24 namespace uhd{
25 
31 template <typename T> class UHD_API ref_vector{
32 public:
38  template <typename Ptr> ref_vector(Ptr *ptr):
39  _ptr(T(ptr)), _mem(_mem_t(&_ptr)), _size(1)
40  {
41  /* NOP */
42  }
43 
49  template <typename Vector> ref_vector(const Vector &vec):
50  _ptr(T()), _mem(_mem_t(&vec.front())), _size(vec.size())
51  {
52  /* NOP */
53  }
54 
61  ref_vector(const T *mem, size_t len):
62  _ptr(T()), _mem(_mem_t(mem)), _size(len)
63  {
64  /* NOP */
65  }
66 
68  const T &operator[](size_t index) const{
69  return _mem[index];
70  }
71 
73  size_t size(void) const{
74  return _size;
75  }
76 
77 private:
78  const T _ptr;
79  typedef T* _mem_t;
80  const _mem_t _mem;
81  const size_t _size;
82 };
83 
84 } //namespace uhd
85 
86 #endif /* INCLUDED_UHD_TYPES_REF_VECTOR_HPP */
ref_vector(Ptr *ptr)
Definition: ref_vector.hpp:38
size_t size(void) const
The number of elements in this container.
Definition: ref_vector.hpp:73
ref_vector(const T *mem, size_t len)
Definition: ref_vector.hpp:61
Definition: convert.hpp:28
Definition: ref_vector.hpp:31
ref_vector(const Vector &vec)
Definition: ref_vector.hpp:49
#define UHD_API
Definition: config.h:66
const T & operator[](size_t index) const
Index operator gets the value of rv[index].
Definition: ref_vector.hpp:68