external_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  *-----------------------------------------------------------------------*/
00018 #ifndef external_1D_h
00019 #define external_1D_h
00020 
00021 #include <cml/core/common.h>
00022 #include <cml/core/cml_meta.h>
00023 #include <cml/core/cml_assert.h>
00024 #include <cml/external.h>
00025 
00026 namespace cml {
00027 
00033 template<typename Element, int Size = -1>
00034 class external_1D
00035 {
00036   public:
00037 
00038     /* Require Size > 0: */
00039     CML_STATIC_REQUIRE(Size > 0);
00040 
00041     /* Record the generator: */
00042     typedef external<Size,-1> generator_type;
00043 
00044     /* Standard: */
00045     typedef Element value_type;
00046     typedef Element* pointer;
00047     typedef Element& reference;
00048     typedef const Element& const_reference;
00049     typedef const Element* const_pointer;
00050 
00051     /* Array implementation: */
00052     typedef value_type array_impl[Size];
00053 
00054     /* For matching by memory type: */
00055     typedef external_memory_tag memory_tag;
00056 
00057     /* For matching by size type: */
00058     typedef fixed_size_tag size_tag;
00059 
00060     /* For matching by resizability: */
00061     typedef not_resizable_tag resizing_tag;
00062 
00063     /* For matching by dimensions: */
00064     typedef oned_tag dimension_tag;
00065 
00066 
00067   public:
00068 
00070     enum { array_size = Size };
00071 
00072 
00073   public:
00074 
00075     external_1D(pointer const ptr)
00076         : m_data(ptr) {}
00077 
00078 
00079   public:
00080 
00082     size_t size() const { return size_t(array_size); }
00083 
00091     reference operator[](size_t i) { return m_data[i]; }
00092 
00100     const_reference operator[](size_t i) const { return m_data[i]; }
00101 
00103     pointer data() { return m_data; }
00104 
00106     const_pointer data() const { return m_data; }
00107 
00108 
00109   protected:
00110 
00111     pointer const               m_data;
00112 
00113 
00114   private:
00115 
00116     /* Initialization without an argument isn't allowed: */
00117     external_1D();
00118 };
00119 
00126 template<typename Element>
00127 class external_1D<Element,-1>
00128 {
00129   public:
00130 
00131     /* Record the generator.  Note: this is *not* unique, as it is the same
00132      * generator used by external_2D.  However, external_2D is used only by
00133      * matrix<> classes, so this is not a problem.
00134      */
00135     typedef external<> generator_type;
00136 
00137     /* Standard: */
00138     typedef Element value_type;
00139     typedef Element* pointer;
00140     typedef Element& reference;
00141     typedef const Element& const_reference;
00142     typedef const Element* const_pointer;
00143 
00144     /* For matching by memory type: */
00145     typedef external_memory_tag memory_tag;
00146 
00147     /* For matching by size type: */
00148     typedef dynamic_size_tag size_tag;
00149 
00150     /* For matching by resizability: */
00151     typedef not_resizable_tag resizing_tag;
00152 
00153     /* For matching by dimensions: */
00154     typedef oned_tag dimension_tag;
00155 
00156 
00157   public:
00158 
00160     enum { array_size = -1 };
00161 
00162 
00163   public:
00164 
00165     external_1D(pointer const ptr, size_t size)
00166         : m_data(ptr), m_size(size) {}
00167 
00168 
00169   public:
00170 
00172     size_t size() const { return m_size; }
00173 
00181     reference operator[](size_t i) { return m_data[i]; }
00182 
00190     const_reference operator[](size_t i) const { return m_data[i]; }
00191 
00193     pointer data() { return m_data; }
00194 
00196     const_pointer data() const { return m_data; }
00197 
00198 
00199   protected:
00200 
00201     pointer const               m_data;
00202     const size_t                m_size;
00203 
00204 
00205   private:
00206 
00207     /* Initialization without an argument isn't allowed: */
00208     external_1D();
00209 };
00210 
00211 } // namespace cml
00212 
00213 #endif
00214 
00215 // -------------------------------------------------------------------------
00216 // vim:ft=cpp

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