USRP Hardware Driver and USRP Manual  Version: 3.15.0.HEAD-0-gaea0e2de
UHD and USRP Manual
ref_vector.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2011 Ettus Research LLC
3 // Copyright 2018 Ettus Research, a National Instruments Company
4 //
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 
8 #ifndef INCLUDED_UHD_TYPES_REF_VECTOR_HPP
9 #define INCLUDED_UHD_TYPES_REF_VECTOR_HPP
10 
11 #include <uhd/config.hpp>
12 #include <cstddef>
13 
14 namespace uhd {
15 
21 template <typename T> class UHD_API ref_vector
22 {
23 public:
29  template <typename Ptr>
30  ref_vector(Ptr* ptr) : _ptr(T(ptr)), _mem(_mem_t(&_ptr)), _size(1)
31  {
32  /* NOP */
33  }
34 
40  template <typename Vector>
41  ref_vector(const Vector& vec)
42  : _ptr(T()), _mem(_mem_t(&vec.front())), _size(vec.size())
43  {
44  /* NOP */
45  }
46 
53  ref_vector(const T* mem, size_t len) : _ptr(T()), _mem(_mem_t(mem)), _size(len)
54  {
55  /* NOP */
56  }
57 
59  const T& operator[](size_t index) const
60  {
61  return _mem[index];
62  }
63 
65  size_t size(void) const
66  {
67  return _size;
68  }
69 
70 private:
71  const T _ptr;
72  typedef T* _mem_t;
73  const _mem_t _mem;
74  const size_t _size;
75 };
76 
77 } // namespace uhd
78 
79 #endif /* INCLUDED_UHD_TYPES_REF_VECTOR_HPP */
ref_vector(Ptr *ptr)
Definition: ref_vector.hpp:30
size_t size(void) const
The number of elements in this container.
Definition: ref_vector.hpp:65
ref_vector(const T *mem, size_t len)
Definition: ref_vector.hpp:53
Definition: build_info.hpp:13
Definition: ref_vector.hpp:21
ref_vector(const Vector &vec)
Definition: ref_vector.hpp:41
#define UHD_API
Definition: config.h:68
const T & operator[](size_t index) const
Index operator gets the value of rv[index].
Definition: ref_vector.hpp:59