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 fixed_1D_h 00014 #define fixed_1D_h 00015 00016 #include <cml/core/common.h> 00017 #include <cml/core/cml_meta.h> 00018 #include <cml/core/cml_assert.h> 00019 #include <cml/fixed.h> 00020 00021 namespace cml { 00022 00046 template<typename Element, int Size> 00047 class fixed_1D 00048 { 00049 public: 00050 00051 /* Require Size > 0: */ 00052 CML_STATIC_REQUIRE(Size > 0); 00053 00054 /* Record the generator: */ 00055 typedef fixed<Size,-1> generator_type; 00056 00057 /* Standard: */ 00058 typedef Element value_type; 00059 typedef Element* pointer; 00060 typedef Element& reference; 00061 typedef const Element& const_reference; 00062 typedef const Element* const_pointer; 00063 00064 /* Array implementation: */ 00065 typedef value_type array_impl[Size]; 00066 00067 /* For matching by memory type: */ 00068 typedef fixed_memory_tag memory_tag; 00069 00070 /* For matching by size type: */ 00071 typedef fixed_size_tag size_tag; 00072 00073 /* For matching by resizability: */ 00074 typedef not_resizable_tag resizing_tag; 00075 00076 /* For matching by dimensions: */ 00077 typedef oned_tag dimension_tag; 00078 00079 00080 public: 00081 00083 enum { array_size = Size }; 00084 00085 00086 public: 00087 00089 size_t size() const { return size_t(array_size); } 00090 00098 reference operator[](size_t i) { return m_data[i]; } 00099 00107 const_reference operator[](size_t i) const { return m_data[i]; } 00108 00110 pointer data() { return &m_data[0]; } 00111 00113 const_pointer data() const { return &m_data[0]; } 00114 00115 protected: 00116 00117 fixed_1D() {} 00118 00119 00120 protected: 00121 00122 array_impl m_data; 00123 }; 00124 00125 } // namespace cml 00126 00127 #endif 00128 00129 // ------------------------------------------------------------------------- 00130 // vim:ft=cpp