diff liboctave/Array.h @ 4902:bd043a433918

[project @ 2004-06-14 18:46:20 by jwe]
author jwe
date Mon, 14 Jun 2004 18:49:09 +0000
parents 8f669cc5a901
children c638c144d4da
line wrap: on
line diff
--- a/liboctave/Array.h	Mon Jun 14 18:33:02 2004 +0000
+++ b/liboctave/Array.h	Mon Jun 14 18:49:09 2004 +0000
@@ -133,13 +133,12 @@
 	rep->fill (val);
     }
 
-  typename Array<T>::ArrayRep *rep;
-
 public:
 
-  // !!! WARNING !!! -- this is public because template friends don't
-  // work properly with versions of gcc earlier than 3.3.  You should
-  // not access this data member directly!
+  // !!! WARNING !!! -- these should be protected, not public.  You
+  // should not access these data members directly!
+
+  typename Array<T>::ArrayRep *rep;
 
   dim_vector dimensions;
 
@@ -166,6 +165,18 @@
       return nr;
     }
 
+  template <class U>
+  T *
+  coerce (const U *a, int len)
+  {
+    T *retval = new T [len];
+
+    for (int i = 0; i < len; i++)
+      retval[i] = T (a[i]);
+
+    return retval;
+  }
+
 public:
 
   Array (void)
@@ -183,6 +194,15 @@
       fill (val);
     }
 
+  // Type conversion case.
+  template <class U>
+  Array (const Array<U>& a)
+    : rep (new typename Array<T>::ArrayRep (coerce (a.data (), a.length ()), a.length ())),
+      dimensions (a.dimensions), idx (0), idx_count (0)
+    {
+    }
+
+  // No type conversion case.
   Array (const Array<T>& a)
     : rep (a.rep), dimensions (a.dimensions), idx (0), idx_count (0)
     {
@@ -241,6 +261,8 @@
   int columns (void) const { return dim2 (); }
   int pages (void) const { return dim3 (); }
 
+  size_t byte_size (void) const { return numel () * sizeof (T); }
+
   dim_vector dims (void) const { return dimensions; }
 
   Array<T> squeeze (void) const;