[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN/internal membase.hh
From: |
Tom Drummond |
Subject: |
[Toon-members] TooN/internal membase.hh |
Date: |
Fri, 30 Jan 2009 14:51:23 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Tom Drummond <twd20> 09/01/30 14:51:23
Modified files:
internal : membase.hh
Log message:
Fixed up membase to be suitable for matrices
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/membase.hh?cvsroot=toon&r1=1.1&r2=1.2
Patches:
Index: membase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/membase.hh,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- membase.hh 27 Jan 2009 12:01:51 -0000 1.1
+++ membase.hh 30 Jan 2009 14:51:23 -0000 1.2
@@ -3,17 +3,38 @@
static const int TOON_MAX_STACK_SIZE=10;
#endif
-template <int Rows, int Cols>
-struct MMemSize{
- static const int size=Rows*Cols;
+template <int Rows, int Cols, typename Precision, int
Place=(Rows*Cols>TOON_MAX_STACK_SIZE?1:0)>
+struct MMemBase;
+
+// Place=0 => stack
+template <int Rows, int Cols, typename Precision>
+struct MMemBase<Rows, Cols, Precision, 0> {
+ Precision my_data[Rows*Cols];
+};
+
+
+// Place=1 => heap
+template <int Rows, int Cols, typename Precision>
+struct MMemBase <Rows, Cols, Precision, 1>{
+ MMemBase() : my_data(new Precision[Rows*Cols]) {}
+ ~MMemBase() {delete[] my_data}
+ Precision* const my_data;
};
-template<>
-struct MMemSize<-1,-1> {
- static const int size=-1;
+
+// Rows=Cols=-1 => dynamic
+tempate<typename Precision>
+struct MMembase<-1,-1,Precision,0> {
+ MMemBase(unsigned int r, unsigned int c) : my_data(new Precision[r*c]),
my_rows(r), my_cols(c){}
+ ~MMemBase() {delete[] my_data;}
+ Precision* my_data;
+ unsigned int my_rows;
+ unsigned int my_cols;
};
+
+
template<int Size, typename Precision, int
Place=(Size>TOON_MAX_STACK_SIZE?1:0)>
struct MemBase;