UHD  003.004.001-23-stable
include/uhd/types/ref_vector.hpp
Go to the documentation of this file.
00001 //
00002 // Copyright 2011 Ettus Research LLC
00003 //
00004 // This program is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #ifndef INCLUDED_UHD_TYPES_REF_VECTOR_HPP
00019 #define INCLUDED_UHD_TYPES_REF_VECTOR_HPP
00020 
00021 #include <uhd/config.hpp>
00022 
00023 namespace uhd{
00024 
00030 template <typename T> class UHD_API ref_vector{
00031 public:
00037     template <typename Ptr> ref_vector(Ptr *ptr):
00038         _ptr(T(ptr)), _mem(_mem_t(&_ptr)), _size(1)
00039     {
00040         /* NOP */
00041     }
00042 
00048     template <typename Vector> ref_vector(const Vector &vec):
00049         _ptr(T()), _mem(_mem_t(&vec.front())), _size(vec.size())
00050     {
00051         /* NOP */
00052     }
00053 
00060     ref_vector(const T *mem, size_t len):
00061         _ptr(T()), _mem(_mem_t(mem)), _size(len)
00062     {
00063         /* NOP */
00064     }
00065 
00067     const T &operator[](size_t index) const{
00068         return _mem[index];
00069     }
00070 
00072     size_t size(void) const{
00073         return _size;
00074     }
00075 
00076 private:
00077     const T      _ptr;
00078     typedef T*   _mem_t;
00079     const _mem_t _mem;
00080     const size_t _size;
00081 };
00082 
00083 } //namespace uhd
00084 
00085 #endif /* INCLUDED_UHD_TYPES_REF_VECTOR_HPP */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines