USRP Hardware Driver and USRP Manual  Version: 4.2.0.0-143-g2ad30980f
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 #pragma once
9 
10 #include <uhd/config.hpp>
11 #include <cstddef>
12 
13 namespace uhd {
14 
20 template <typename T>
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
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:12
Definition: ref_vector.hpp:21
ref_vector(const Vector &vec)
Definition: ref_vector.hpp:41
#define UHD_API
Definition: config.h:87
const T & operator[](size_t index) const
Index operator gets the value of rv[index].
Definition: ref_vector.hpp:59