Mercurial > hg > octave-lyh
diff liboctave/dim-vector.h @ 4543:79df15d4470c
[project @ 2003-10-18 03:53:52 by jwe]
author | jwe |
---|---|
date | Sat, 18 Oct 2003 03:53:53 +0000 |
parents | 01ee68d18069 |
children | 820323598f4f |
line wrap: on
line diff
--- a/liboctave/dim-vector.h +++ b/liboctave/dim-vector.h @@ -28,6 +28,9 @@ #endif #include <cassert> +#include <string> + +#include "lo-sstream.h" class dim_vector @@ -116,12 +119,80 @@ ndims = n; } + std::string str (void) const + { + OSSTREAM buf; + + for (int i = 0; i < ndims; i++) + { + buf << dims[i]; + + if (i < ndims - 1) + buf << "x"; + } + + buf << OSSTREAM_ENDS; + + std::string retval = OSSTREAM_STR (buf); + + OSSTREAM_FREEZE (buf); + + return retval; + } + + bool all_zero (void) const + { + bool retval = true; + + for (int i = 0; i < ndims; i++) + { + if (dims[i] != 0) + { + retval = false; + break; + } + } + + return retval; + } + private: int ndims; int *dims; }; +static inline bool +operator == (const dim_vector& a, const dim_vector& b) +{ + bool retval = true; + + int a_len = a.length (); + int b_len = b.length (); + + if (a_len != b_len) + retval = false; + else + { + for (int i = 0; i < a_len; i++) + { + if (a(i) != b(i)) + { + retval = false; + break; + } + } + } + + return retval; +} + +static inline bool +operator != (const dim_vector& a, const dim_vector& b) +{ + return ! operator == (a, b); +} + #endif /*