USRP Hardware Driver and USRP Manual  Version: 003.009.002-0-gf18abe54
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 
23 namespace uhd{
24 
30 template <typename T> class UHD_API ref_vector{
31 public:
37  template <typename Ptr> ref_vector(Ptr *ptr):
38  _ptr(T(ptr)), _mem(_mem_t(&_ptr)), _size(1)
39  {
40  /* NOP */
41  }
42 
48  template <typename Vector> ref_vector(const Vector &vec):
49  _ptr(T()), _mem(_mem_t(&vec.front())), _size(vec.size())
50  {
51  /* NOP */
52  }
53 
60  ref_vector(const T *mem, size_t len):
61  _ptr(T()), _mem(_mem_t(mem)), _size(len)
62  {
63  /* NOP */
64  }
65 
67  const T &operator[](size_t index) const{
68  return _mem[index];
69  }
70 
72  size_t size(void) const{
73  return _size;
74  }
75 
76 private:
77  const T _ptr;
78  typedef T* _mem_t;
79  const _mem_t _mem;
80  const size_t _size;
81 };
82 
83 } //namespace uhd
84 
85 #endif /* INCLUDED_UHD_TYPES_REF_VECTOR_HPP */
ref_vector(Ptr *ptr)
Definition: ref_vector.hpp:37
size_t size(void) const
The number of elements in this container.
Definition: ref_vector.hpp:72
ref_vector(const T *mem, size_t len)
Definition: ref_vector.hpp:60
Definition: convert.hpp:28
Definition: ref_vector.hpp:30
ref_vector(const Vector &vec)
Definition: ref_vector.hpp:48
#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:67