HyperspaceExplorer 0.7.1
|
00001 /* 00002 Hyperspace Explorer - visualizing higher-dimensional geometry 00003 Copyright (C) 2010 Lene Preuss <lene.preuss@gmail.com> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 00019 */ 00020 00021 #ifndef ARRAYLIST_H 00022 #define ARRAYLIST_H 00023 00024 #include <string> 00025 00027 00030 template <unsigned size, typename T> class ArrayList { 00031 00032 public: 00033 00035 ArrayList(); 00037 ArrayList(const T &x); 00039 ArrayList(const T &head, const ArrayList<size-1, T> &tail); 00040 00042 const T &head() const; 00043 T &head(); 00045 const ArrayList<size-1, T> &tail() const; 00046 ArrayList<size-1, T> &tail(); 00047 00049 const T &operator[](unsigned i) const; 00051 T &operator[](unsigned i); 00052 00054 ArrayList<size-1, T> minusElement(unsigned i) const; 00055 00056 bool contains(const T &x) const; 00057 00059 std::string toString() const; 00060 00061 private: 00062 00064 std::pair<T, ArrayList<size-1, T> > _elements; 00065 }; 00066 00068 00070 template <typename T> class ArrayList<1, T> { 00071 00072 public: 00073 00075 ArrayList(); 00077 ArrayList(const T &x); 00078 ArrayList(T x, ArrayList<0, T>); 00079 00081 const T &head() const; 00082 T &head(); 00083 ArrayList<0, T> tail() const; 00084 00086 T &operator[](unsigned); 00088 const T &operator[](unsigned) const; 00089 00091 ArrayList<0, T> minusElement(unsigned) const; 00092 00093 bool contains (const T &x) const; 00094 00096 std::string toString() const; 00097 00098 private: 00099 00100 T element_; 00101 00102 }; 00103 00105 00107 template <typename T> class ArrayList<0, T> { 00108 00109 public: 00110 00112 ArrayList(); 00114 ArrayList(const T &); 00115 00117 std::string toString() const; 00118 00119 }; 00120 00121 template<unsigned size, typename T> 00122 bool isPermutation(const ArrayList<size, T> &list1, const ArrayList<size, T> &list2); 00123 template<typename T> 00124 bool isPermutation(const ArrayList<1, T> &list1, const ArrayList<1, T> &list2); 00125 00126 template<typename T> 00127 ArrayList<1, T> makeArrayList(const T &x0); 00128 template<typename T> 00129 ArrayList<2, T> makeArrayList(const T &x0, const T &x1); 00130 template<typename T> 00131 ArrayList<3, T> makeArrayList(const T &x0, const T &x1, const T &x2); 00132 template<typename T> 00133 ArrayList<4, T> makeArrayList(const T &x0, const T &x1, const T &x2, const T &x3); 00134 template<typename T> 00135 ArrayList<5, T> makeArrayList(const T &x0, const T &x1, const T &x2, const T &x3, const T &x4); 00136 template<typename T> 00137 ArrayList<6, T> makeArrayList(const T &x0, const T &x1, const T &x2, const T &x3, const T &x4, 00138 const T &x5); 00139 template<typename T> 00140 ArrayList<7, T> makeArrayList(const T &x0, const T &x1, const T &x2, const T &x3, const T &x4, 00141 const T &x5, const T &x6); 00142 template<typename T> 00143 ArrayList<8, T> makeArrayList(const T &x0, const T &x1, const T &x2, const T &x3, const T &x4, 00144 const T &x5, const T &x6, const T &x7); 00145 template<typename T> 00146 ArrayList<9, T> makeArrayList(const T &x0, const T &x1, const T &x2, const T &x3, const T &x4, 00147 const T &x5, const T &x6, const T &x7, const T &x8); 00148 template<typename T> 00149 ArrayList<10, T> makeArrayList(const T &x0, const T &x1, const T &x2, const T &x3, const T &x4, 00150 const T &x5, const T &x6, const T &x7, const T &x8, const T &x9); 00151 00152 #endif // ARRAYLIST_H