[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN TooN.h internal/debug.hh internal/size_ass...
From: |
Edward Rosten |
Subject: |
[Toon-members] TooN TooN.h internal/debug.hh internal/size_ass... |
Date: |
Fri, 09 Jan 2009 14:24:03 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 09/01/09 14:24:03
Modified files:
. : TooN.h
Added files:
internal : debug.hh size_assert.hh slice_error.hh
vector.hh
Removed files:
. : size_assert.h vector.h
Log message:
Minor rearrangement: files not intended for direct inclusion now movet
to
internal/ and named .hh
Remove stride from SDVbase.
Removed delete[] from SDVBase.
Added in some bounds checking.
Added in some slicing, with static slice checking.
The splitting up of the slice checking in to s different include file
gives
slightly nicer error messages with gcc, since the file name appears in
the
first column:
./TooN/internal/slice_error.hh: In static member function 'static void
TooN::Internal::CheckSlice<Size, Start, Length>::check() [with int Size = 3,
int Start = 1, int Length = 2]':
./TooN/internal/vector.hh:61: instantiated from 'TooN::Vector<Length,
TooN::SVBase<Length, 1> > TooN::VBase<Size, 0>::slice() [with int Start = 1,
int Length = 2, int Size = 3]'
TooN/test/vec_test.cc:22: instantiated from here
./TooN/internal/slice_error.hh:16: error: incomplete type
'TooN::Internal::BadSlice<3, true>' used in nested name specifier
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/TooN.h?cvsroot=toon&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/TooN/size_assert.h?cvsroot=toon&r1=1.1&r2=0
http://cvs.savannah.gnu.org/viewcvs/TooN/vector.h?cvsroot=toon&r1=1.1&r2=0
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/debug.hh?cvsroot=toon&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/size_assert.hh?cvsroot=toon&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/slice_error.hh?cvsroot=toon&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vector.hh?cvsroot=toon&rev=1.1
Patches:
Index: TooN.h
===================================================================
RCS file: /cvsroot/toon/TooN/TooN.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- TooN.h 8 Jan 2009 11:33:18 -0000 1.12
+++ TooN.h 9 Jan 2009 14:24:02 -0000 1.13
@@ -1,6 +1,14 @@
//-*- c++ -*-
#ifndef TOON_INCLUDE_TOON_H
#define TOON_INCLUDE_TOON_H
-#include <vector.h>
-#include <operators.h>
+#include <iostream>
+#include <cstdlib>
+namespace TooN
+{
+ #include <TooN/internal/size_assert.hh>
+ #include <TooN/internal/slice_error.hh>
+ #include <TooN/internal/debug.hh>
+ #include <TooN/internal/vector.hh>
+ #include <TooN/operators.h>
+}
#endif
Index: internal/debug.hh
===================================================================
RCS file: internal/debug.hh
diff -N internal/debug.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ internal/debug.hh 9 Jan 2009 14:24:03 -0000 1.1
@@ -0,0 +1,13 @@
+namespace Internal
+{
+ static inline void check_index(int i, int s)
+ {
+ #ifdef TOON_CHECK_BOUNDS
+ if(i<0 || i >= s)
+ {
+ std::cerr << "Toon index out of range" <<
std::endl;
+ std::abort();
+ }
+ #endif
+ }
+}
Index: internal/size_assert.hh
===================================================================
RCS file: internal/size_assert.hh
diff -N internal/size_assert.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ internal/size_assert.hh 9 Jan 2009 14:24:03 -0000 1.1
@@ -0,0 +1,44 @@
+// -*- c++ -*-
+
+// class to generate compile time error
+// general case which doesn't exist
+template<int Size1, int Size2>
+struct SizeMismatch;
+
+// special cases which do exist
+template<int Size>
+struct SizeMismatch<Size,Size>{
+ static inline void test(int size1, int size2){}
+};
+
+template<int Size>
+struct SizeMismatch<-1,Size>{
+ static inline void test(int size1, int size2){
+ if(size1!=size2){
+ std::cerr << "Toon Size Mismatch" << std::endl;
+ std::abort();
+ }
+ }
+};
+
+template<int Size>
+struct SizeMismatch<Size,-1>{
+ static inline void test(int size1, int size2){
+ if(size1!=size2){
+ std::cerr << "Toon Size Mismatch" << std::endl;
+ std::abort();
+ }
+ }
+};
+
+template <>
+struct SizeMismatch<-1,-1>{
+ static inline void test(int size1, int size2){
+ if(size1!=size2){
+ std::cerr << "Toon Size Mismatch" << std::endl;
+ std::abort();
+ }
+ }
+};
+
+
Index: internal/slice_error.hh
===================================================================
RCS file: internal/slice_error.hh
diff -N internal/slice_error.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ internal/slice_error.hh 9 Jan 2009 14:24:03 -0000 1.1
@@ -0,0 +1,35 @@
+namespace Internal
+{
+ template<int Size, bool StaticBad>
+ struct BadSlice;
+
+ template<int Size>
+ struct BadSlice<Size, 0>{
+ static void check(){}
+ };
+
+ template<int Size=-1, int Start=-1, int Length=-1>
+ struct CheckSlice
+ {
+ static void check()
+ {
+ BadSlice<Size, (Start+Length>=Size)>::check();
+ }
+ };
+
+ template<int Start, int Length>
+ struct CheckSlice<-1, Start, Length>
+ {
+ static void check(int size, int start, int length)
+ {
+ if(start + length >= size)
+ {
+ std::cerr << "Toon slice out of range" <<
std::endl;
+ std::abort();
+ }
+ }
+ };
+
+
+
+}
Index: internal/vector.hh
===================================================================
RCS file: internal/vector.hh
diff -N internal/vector.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ internal/vector.hh 9 Jan 2009 14:24:03 -0000 1.1
@@ -0,0 +1,365 @@
+//-*- c++ -*-
+// forward declarations
+template<int Size, typename Base>
+class Vector;
+
+template<int Size, int Stride>
+class SVBase;
+
+// forward declaration
+template<typename T>
+class Operator;
+
+// VBase owns its data
+// Size is the static number of elements in the vector
+// Stride is the static gap between elements
+// Type is a hack so that x?y:z expressions work
+// Type=0 means the data is internal to the object
+// Type=1 means the data is external to the object
+template <int Size, int Type>
+class VBase;
+
+class SDVBase;
+
+
+template<int Size>
+class VBase<Size, 0> {
+public:
+ inline VBase(){}
+ inline VBase(const VBase& from){}
+
+ // construction from 1-ary operator
+ template <class T, class Op>
+ inline VBase(const T&, const Operator<Op>&){}
+
+ // constructor from 2-ary operator
+ template <class LHS, class RHS, class Op>
+ inline VBase(const LHS& lhs, const RHS& rhs, const Operator<Op>&){}
+
+ // constructor from arbitrary vector
+ template<int Size2, class Base2>
+ inline VBase(const Vector<Size2,Base2>& from){}
+
+ double* data(){return my_data;}
+ const double* data() const {return my_data;}
+
+ static int size(){return Size;}
+ static int stride(){return 1;}
+
+ double& operator[](int i){
+ Internal::check_index(Size, i);
+ return my_data[i];
+ }
+ const double& operator[](int i) const {
+ Internal::check_index(Size, i);
+ return my_data[i];
+ }
+
+ template <int Start, int Length>
+ Vector<Length, SVBase<Length,1> >
+ slice(){
+ Internal::CheckSlice<Size, Start, Length>::check();
+ return Vector<Length, SVBase<Length,1> >(&(my_data[Start]));
+ }
+
+ Vector<-1, SDVBase>
+ slice(int start, int length);
+
+private:
+ double my_data[Size];
+};
+
+template<int Size>
+class VBase<Size,1>{
+public:
+ VBase()
+ : my_data(new double[Size]){
+ }
+
+ VBase(const VBase& from)
+ : my_data(new double[Size]){
+ }
+
+ VBase(int size_in)
+ : my_data(new double[Size]){
+ }
+
+ // construction from 1-ary operator
+ template <class T, class Op>
+ inline VBase(const T&, const Operator<Op>&):
+ my_data(new double[Size]){}
+
+ // constructor from 2-ary operator
+ template <class LHS, class RHS, class Op>
+ inline VBase(const LHS& lhs, const RHS& rhs, const Operator<Op>&):
+ my_data(new double[Size]){}
+
+ // constructor from arbitrary vector
+ template<int Size2, class Base2>
+ inline VBase(const Vector<Size2,Base2>& from):
+ my_data(new double[from.size()]) {}
+
+ ~VBase(){
+ delete[] my_data;
+ }
+
+ double* data(){return my_data;}
+ const double* data() const {return my_data;}
+
+ static int size(){return Size;}
+ static int stride(){return 1;}
+
+ double& operator[](int i){
+ Internal::check_index(Size, i);
+ return my_data[i];
+ }
+ const double& operator[](int i) const {
+ Internal::check_index(Size, i);
+ return my_data[i];
+ }
+
+ template <int Start, int Length>
+ Vector<Length, SVBase<Length,1> >
+ slice(){
+ Internal::CheckSlice<Size, Start, Length>::check();
+ return Vector<Length, SVBase<Length,1> >(&(my_data[Start]));
+ }
+
+ Vector<-1, SDVBase>
+ slice(int start, int length);
+
+private:
+ double* const my_data;
+};
+
+
+// SVBase does not own its data
+// and has a template stride parameter
+template<int Size, int Stride>
+class SVBase{
+public:
+ SVBase(double* data_in):
+ my_data(data_in){
+ }
+
+ SVBase(const SVBase& from):
+ my_data(from.my_data){
+ }
+
+ double* data(){return my_data;}
+ const double* data() const {return my_data;}
+
+ int size() const {return Size;}
+ int stride() const {return Stride;}
+
+ double& operator[](int i){
+ return my_data[i*Stride];
+ }
+ const double& operator[](int i) const {
+ return my_data[i*Stride];
+ }
+
+ template <int Start, int Length>
+ Vector<Length, SVBase<Length,Stride> >
+ slice(){
+ return Vector<Length, SVBase<Length,1> >(&(my_data[Start*Stride]));
+ }
+
+private:
+ double* const my_data;
+};
+
+
+
+
+// DVBase is for vectors whose size is determined dynamically at runtime
+// They own their data
+class DVBase{
+public:
+ DVBase(int size_in):
+ my_data(new double[size_in]),
+ my_size(size_in){
+ }
+
+ DVBase(const DVBase& from):
+ my_data(new double[from.my_size]),
+ my_size(from.my_size) {
+ }
+
+ // construction from 1-ary operator
+ template <class T, class Op>
+ inline DVBase(const T& arg, const Operator<Op>&):
+ my_data(new double[Op::size(arg)]),
+ my_size(Op::size(arg)) {
+ }
+
+ // constructor from 2-ary operator
+ template <class LHS, class RHS, class Op>
+ inline DVBase(const LHS& lhs, const RHS& rhs, const Operator<Op>&):
+ my_data(new double[Op::size(lhs,rhs)]),
+ my_size(Op::size(lhs,rhs)) {
+ }
+
+ // constructor from arbitrary vector
+ template<int Size2, class Base2>
+ inline DVBase(const Vector<Size2,Base2>& from):
+ my_data(new double[from.size()]),
+ my_size(from.size()) {
+ }
+
+ ~DVBase(){
+ delete[] my_data;
+ }
+
+ double* data(){return my_data;}
+ const double* data() const {return my_data;}
+
+ int size() const {return my_size;}
+ int stride() const {return 1;}
+
+ double& operator[](int i){
+ return my_data[i];
+ }
+ const double& operator[](int i) const {
+ return my_data[i];
+ }
+private:
+ double* const my_data;
+ int my_size;
+};
+
+// SDVBase is for dynamically sized vectors that do not own their data
+// They have an additional stride member
+class SDVBase{
+public:
+ SDVBase(double* data_in, int size_in):
+ my_data(data_in) {
+ my_size=size_in;
+ };
+
+ SDVBase(const SDVBase& from)
+ : my_data(from.my_data),
+ my_size(from.my_size){
+ }
+
+ ~SDVBase(){
+ }
+
+ double* data(){return my_data;}
+ const double* data() const {return my_data;}
+
+ int size() const {return my_size;}
+ int stride() const {return 1;}
+
+ double& operator[](int i){
+ return my_data[i];
+ }
+ const double& operator[](int i) const {
+ return my_data[i];
+ }
+private:
+ double* const my_data;
+ int my_size;
+};
+
+// traits classes that help with building the vectors you actually
+// construct in code
+static const int MAX_SIZE=10;
+
+template<int Size>
+struct VectorSelector{
+ typedef VBase<Size, (Size>MAX_SIZE)?1:0 > Type;
+};
+
+template<>
+struct VectorSelector<-1>{
+ typedef DVBase Type;
+};
+
+
+////////////////////////////////////////////////////////////////////////////////
+// The actual Vector classes
+////////////////////////////////////////////////////////////////////////////////
+
+
+
+template<int Size=-1, typename Base= typename VectorSelector<Size>::Type>
+class Vector : public Base {
+public:
+ // sneaky hack: only one of these constructors will work with any given base
+ // class but they don't generate errors unless the user tries to use one of
them
+ // although the error message may be less than helpful - maybe this can be
changed?
+ inline Vector(){}
+ inline Vector(double* data) : Base (data) {}
+ inline Vector(int size_in) : Base(size_in) {}
+ inline Vector(double* data_in, int size_in) : Base(data_in, size_in) {}
+ inline Vector(double* data_in, int size_in, int stride_in) : Base(data_in,
size_in, stride_in) {}
+
+
+ // constructors to allow return value optimisations
+ // construction from 1-ary operator
+ template <class T, class Op>
+ inline Vector(const T& arg, const Operator<Op>& op) : Base(arg,op) {
+ Op::eval(*this,arg);
+ }
+
+ // constructor from 2-ary operator
+ template <class LHS, class RHS, class Op>
+ inline Vector(const LHS& lhs, const RHS& rhs, const Operator<Op>& op)
+ : Base(lhs,rhs,op) {
+ Op::eval(*this,lhs,rhs);
+ }
+
+ // copy constructor listed explicitly
+ inline Vector(const Vector<Size,Base>& from)
+ : Base(from) {
+ (*this)=from;
+ }
+
+ // constructor from arbitrary vector
+ template<int Size2, class Base2>
+ inline Vector(const Vector<Size2,Base2>& from):
+ Base(from) {
+ operator=(from);
+ }
+
+ // operator = from copy
+ inline Vector<Size,Base >& operator= (const Vector& from){
+ SizeMismatch<Size,Size>::test(Base::size(), from.size());
+ const int s=Base::size();
+ for(int i=0; i<s; i++){
+ (*this)[i]=from[i];
+ }
+ return *this;
+ }
+
+ // operator =
+ template<int Size2, typename Base2>
+ Vector<Size,Base >& operator= (const Vector<Size2, Base2>& from){
+ SizeMismatch<Size,Size2>::test(Base::size(), from.size());
+ const int s=Base::size();
+ for(int i=0; i<s; i++){
+ (*this)[i]=from[i];
+ }
+ return *this;
+ }
+
+};
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Fill in function calls, now everything is visible
+
+template<int Size>
+Vector<-1, SDVBase> VBase<Size, 0>:: slice(int start, int length){
+ Internal::CheckSlice<>::check(Size, start, length);
+ return Vector<-1, SDVBase>(my_data + start, length);
+}
+
+template<int Size>
+Vector<-1, SDVBase> VBase<Size, 1>:: slice(int start, int length){
+ Internal::CheckSlice<>::check(Size, start, length);
+ return Vector<-1, SDVBase>(my_data + start, length);
+}
Index: size_assert.h
===================================================================
RCS file: size_assert.h
diff -N size_assert.h
--- size_assert.h 7 Jan 2009 14:23:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,45 +0,0 @@
-// -*- c++ -*-
-
-#include<iostream>
-
-// class to generate compile time error
-// general case which doesn't exist
-template<int Size1, int Size2>
-struct SizeMismatch;
-
-// special cases which do exist
-template<int Size>
-struct SizeMismatch<Size,Size>{
- static inline void test(int size1, int size2){}
-};
-
-template<int Size>
-struct SizeMismatch<-1,Size>{
- static inline void test(int size1, int size2){
- if(size1!=size2){
- std::cerr << "Toon Size Mismatch" << std::endl;
- abort();
- }
- }
-};
-
-template<int Size>
-struct SizeMismatch<Size,-1>{
- static inline void test(int size1, int size2){
- if(size1!=size2){
- std::cerr << "Toon Size Mismatch" << std::endl;
- abort();
- }
- }
-};
-
-template <>
-struct SizeMismatch<-1,-1>{
- static inline void test(int size1, int size2){
- if(size1!=size2){
- std::cerr << "Toon Size Mismatch" << std::endl;
- abort();
- }
- }
-};
-
Index: vector.h
===================================================================
RCS file: vector.h
diff -N vector.h
--- vector.h 7 Jan 2009 14:23:53 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,344 +0,0 @@
-//-*- c++ -*-
-#ifndef TOON_VECTOR_H
-#define TOON_VECTOR_H
-
-#include "size_assert.h"
-
-// forward declarations
-template<int Size, typename Base>
-class Vector;
-
-template<int Size, int Stride>
-class SVBase;
-
-// forward declaration
-template<typename T>
-class Operator;
-
-// VBase owns its data
-// Size is the static number of elements in the vector
-// Stride is the static gap between elements
-// Type is a hack so that x?y:z expressions work
-// Type=0 means the data is internal to the object
-// Type=1 means the data is external to the object
-template <int Size, int Type>
-class VBase;
-
-
-template<int Size>
-class VBase<Size, 0> {
-public:
- inline VBase(){}
- inline VBase(const VBase& from){}
-
- // construction from 1-ary operator
- template <class T, class Op>
- inline VBase(const T&, const Operator<Op>&){}
-
- // constructor from 2-ary operator
- template <class LHS, class RHS, class Op>
- inline VBase(const LHS& lhs, const RHS& rhs, const Operator<Op>&){}
-
- // constructor from arbitrary vector
- template<int Size2, class Base2>
- inline VBase(const Vector<Size2,Base2>& from){}
-
- double* data(){return my_data;}
- const double* data() const {return my_data;}
-
- static int size(){return Size;}
- static int stride(){return 1;}
-
- double& operator[](int i){
- return my_data[i];
- }
- const double& operator[](int i) const {
- return my_data[i];
- }
-
- template <int Start, int Length>
- Vector<Length, SVBase<Length,1> >
- slice(){
- return Vector<Length, SVBase<Length,1> >(&(my_data[Start]));
- }
-
-
-private:
- double my_data[Size];
-};
-
-template<int Size>
-class VBase<Size,1>{
-public:
- VBase()
- : my_data(new double[Size]){
- }
-
- VBase(const VBase& from)
- : my_data(new double[Size]){
- }
-
- VBase(int size_in)
- : my_data(new double[Size]){
- }
-
- // construction from 1-ary operator
- template <class T, class Op>
- inline VBase(const T&, const Operator<Op>&):
- my_data(new double[Size]){}
-
- // constructor from 2-ary operator
- template <class LHS, class RHS, class Op>
- inline VBase(const LHS& lhs, const RHS& rhs, const Operator<Op>&):
- my_data(new double[Size]){}
-
- // constructor from arbitrary vector
- template<int Size2, class Base2>
- inline VBase(const Vector<Size2,Base2>& from):
- my_data(new double[from.size()]) {}
-
- ~VBase(){
- delete[] my_data;
- }
-
- double* data(){return my_data;}
- const double* data() const {return my_data;}
-
- static int size(){return Size;}
- static int stride(){return 1;}
-
- double& operator[](int i){
- return my_data[i];
- }
- const double& operator[](int i) const {
- return my_data[i];
- }
-
- template <int Start, int Length>
- Vector<Length, SVBase<Length,1> >
- slice(){
- return Vector<Length, SVBase<Length,1> >(&(my_data[Start]));
- }
-
-private:
- double* const my_data;
-};
-
-
-// SVBase does not own its data
-// and has a template stride parameter
-template<int Size, int Stride>
-class SVBase{
-public:
- SVBase(double* data_in):
- my_data(data_in){
- }
-
- SVBase(const SVBase& from):
- my_data(from.my_data){
- }
-
- double* data(){return my_data;}
- const double* data() const {return my_data;}
-
- int size() const {return Size;}
- int stride() const {return Stride;}
-
- double& operator[](int i){
- return my_data[i*Stride];
- }
- const double& operator[](int i) const {
- return my_data[i*Stride];
- }
-
- template <int Start, int Length>
- Vector<Length, SVBase<Length,Stride> >
- slice(){
- return Vector<Length, SVBase<Length,1> >(&(my_data[Start*Stride]));
- }
-
-private:
- double* const my_data;
-};
-
-
-
-
-// DVBase is for vectors whose size is determined dynamically at runtime
-// They own their data
-class DVBase{
-public:
- DVBase(int size_in):
- my_data(new double[size_in]),
- my_size(size_in){
- }
-
- DVBase(const DVBase& from):
- my_data(new double[from.my_size]),
- my_size(from.my_size) {
- }
-
- // construction from 1-ary operator
- template <class T, class Op>
- inline DVBase(const T& arg, const Operator<Op>&):
- my_data(new double[Op::size(arg)]),
- my_size(Op::size(arg)) {
- }
-
- // constructor from 2-ary operator
- template <class LHS, class RHS, class Op>
- inline DVBase(const LHS& lhs, const RHS& rhs, const Operator<Op>&):
- my_data(new double[Op::size(lhs,rhs)]),
- my_size(Op::size(lhs,rhs)) {
- }
-
- // constructor from arbitrary vector
- template<int Size2, class Base2>
- inline DVBase(const Vector<Size2,Base2>& from):
- my_data(new double[from.size()]),
- my_size(from.size()) {
- }
-
- ~DVBase(){
- delete[] my_data;
- }
-
- double* data(){return my_data;}
- const double* data() const {return my_data;}
-
- int size() const {return my_size;}
- int stride() const {return 1;}
-
- double& operator[](int i){
- return my_data[i];
- }
- const double& operator[](int i) const {
- return my_data[i];
- }
-private:
- double* const my_data;
- int my_size;
-};
-
-// SDVBase is for dynamically sized vectors that do not own their data
-// They have an additional stride member
-class SDVBase{
-public:
- SDVBase(double* data_in, int size_in, int stride_in):
- my_data(data_in) {
- my_size=size_in;
- my_stride=stride_in;
- };
-
- SDVBase(const SDVBase& from)
- : my_data(from.my_data),
- my_size(from.my_size),
- my_stride(from.my_stride){
- }
-
- ~SDVBase(){
- delete[] my_data;
- }
-
- double* data(){return my_data;}
- const double* data() const {return my_data;}
-
- int size() const {return my_size;}
- int stride() const {return my_stride;}
-
- double& operator[](int i){
- return my_data[i];
- }
- const double& operator[](int i) const {
- return my_data[i];
- }
-private:
- double* const my_data;
- int my_size;
- int my_stride;
-};
-
-// traits classes that help with building the vectors you actually
-// construct in code
-static const int MAX_SIZE=10;
-
-template<int Size>
-struct VectorSelector{
- typedef VBase<Size, (Size>MAX_SIZE)?1:0 > Type;
-};
-
-template<>
-struct VectorSelector<-1>{
- typedef DVBase Type;
-};
-
-
-////////////////////////////////////////////////////////////////////////////////
-// The actual Vector classes
-////////////////////////////////////////////////////////////////////////////////
-
-
-
-template<int Size=-1, typename Base= typename VectorSelector<Size>::Type>
-class Vector : public Base {
-public:
- // sneaky hack: only one of these constructors will work with any given base
- // class but they don't generate errors unless the user tries to use one of
them
- // although the error message may be less than helpful - maybe this can be
changed?
- inline Vector(){}
- inline Vector(double* data) : Base (data) {}
- inline Vector(int size_in) : Base(size_in) {}
- inline Vector(double* data_in, int size_in, int stride_in) : Base(data_in,
size_in, stride_in) {}
-
-
- // constructors to allow return value optimisations
- // construction from 1-ary operator
- template <class T, class Op>
- inline Vector(const T& arg, const Operator<Op>& op) : Base(arg,op) {
- Op::eval(*this,arg);
- }
-
- // constructor from 2-ary operator
- template <class LHS, class RHS, class Op>
- inline Vector(const LHS& lhs, const RHS& rhs, const Operator<Op>& op)
- : Base(lhs,rhs,op) {
- Op::eval(*this,lhs,rhs);
- }
-
- // copy constructor listed explicitly
- inline Vector(const Vector<Size,Base>& from)
- : Base(from) {
- (*this)=from;
- }
-
- // constructor from arbitrary vector
- template<int Size2, class Base2>
- inline Vector(const Vector<Size2,Base2>& from):
- Base(from) {
- operator=(from);
- }
-
- // operator = from copy
- inline Vector<Size,Base >& operator= (const Vector& from){
- SizeMismatch<Size,Size>::test(Base::size(), from.size());
- const int s=Base::size();
- for(int i=0; i<s; i++){
- (*this)[i]=from[i];
- }
- return *this;
- }
-
- // operator =
- template<int Size2, typename Base2>
- Vector<Size,Base >& operator= (const Vector<Size2, Base2>& from){
- SizeMismatch<Size,Size2>::test(Base::size(), from.size());
- const int s=Base::size();
- for(int i=0; i<s; i++){
- (*this)[i]=from[i];
- }
- return *this;
- }
-
-};
-
-#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Toon-members] TooN TooN.h internal/debug.hh internal/size_ass...,
Edward Rosten <=