dynamic_1D.h

Go to the documentation of this file.
00001 /* -*- C++ -*- ------------------------------------------------------------
00002  
00003 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
00004 
00005 The Configurable Math Library (CML) is distributed under the terms of the
00006 Boost Software License, v1.0 (see cml/LICENSE for details).
00007 
00008  *-----------------------------------------------------------------------*/
00013 #ifndef dynamic_1D_h
00014 #define dynamic_1D_h
00015 
00016 #include <vector>
00017 #include <cml/core/common.h>
00018 #include <cml/dynamic.h>
00019 
00020 namespace cml {
00021 
00029 template<typename Element, class Alloc>
00030 class dynamic_1D
00031 {
00032   public:
00033 
00034     /* Record the allocator type: */
00035     typedef typename Alloc::template rebind<Element>::other allocator_type;
00036 
00037     /* Record the generator: */
00038     typedef dynamic<Alloc> generator_type;
00039 
00040     /* Array implementation: */
00041     typedef std::vector<Element,allocator_type> array_impl;
00042 
00043     /* Standard: */
00044     typedef typename array_impl::value_type value_type;
00045     typedef typename array_impl::pointer pointer; 
00046     typedef typename array_impl::reference reference; 
00047     typedef typename array_impl::const_reference const_reference; 
00048     typedef typename array_impl::const_pointer const_pointer; 
00049 
00050     /* For matching by memory type: */
00051     typedef dynamic_memory_tag memory_tag;
00052 
00053     /* For matching by size type: */
00054     typedef dynamic_size_tag size_tag;
00055 
00056     /* For matching by resizability: */
00057     typedef resizable_tag resizing_tag;
00058 
00059     /* For matching by dimensions: */
00060     typedef oned_tag dimension_tag;
00061 
00062 
00063   public:
00064 
00066     enum { array_size = -1 };
00067 
00068 
00069   public:
00070 
00072     dynamic_1D() {}
00073 
00075     explicit dynamic_1D(size_t size) : m_data(size) {}
00076 
00077 
00078   public:
00079 
00081     size_t size() const { return this->m_data.size(); }
00082 
00090     reference operator[](size_t i) { return this->m_data[i]; }
00091 
00099     const_reference operator[](size_t i) const { return this->m_data[i]; }
00100 
00102     pointer data() { return &m_data[0]; }
00103 
00105     const_pointer data() const { return &m_data[0]; }
00106 
00107 
00108   public:
00109 
00114     void resize(size_t s) { this->m_data.resize(s); }
00115 
00116 
00117   protected:
00118 
00119     array_impl                  m_data;
00120 };
00121 
00122 } // namespace cml
00123 
00124 #endif
00125 
00126 // -------------------------------------------------------------------------
00127 // vim:ft=cpp

Generated on Sat Jul 18 19:35:20 2009 for CML 1.0 by  doxygen 1.5.9