summaryrefslogtreecommitdiff
path: root/doc/swig/test/Farray.cxx
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2014-03-13 11:56:50 -0600
committerCharles Harris <charlesr.harris@gmail.com>2014-03-13 11:56:50 -0600
commit9c4602f98096abed5632d5fd1f12549a2c5b360c (patch)
treeb154e4d7a7fff6e491216b2e3750d238645903e2 /doc/swig/test/Farray.cxx
parentdfe6c7ed74c087c0deabfd4f7a50224498840838 (diff)
parentf151004567f61c1a613dd78a87521adf795a4942 (diff)
downloadnumpy-9c4602f98096abed5632d5fd1f12549a2c5b360c.tar.gz
Merge pull request #4487 from charris/move-swig-to-tools-directory
Move swig to tools directory
Diffstat (limited to 'doc/swig/test/Farray.cxx')
-rw-r--r--doc/swig/test/Farray.cxx122
1 files changed, 0 insertions, 122 deletions
diff --git a/doc/swig/test/Farray.cxx b/doc/swig/test/Farray.cxx
deleted file mode 100644
index 3983c333b..000000000
--- a/doc/swig/test/Farray.cxx
+++ /dev/null
@@ -1,122 +0,0 @@
-#include "Farray.h"
-#include <sstream>
-
-// Size constructor
-Farray::Farray(int nrows, int ncols) :
- _nrows(nrows), _ncols(ncols), _buffer(0)
-{
- allocateMemory();
-}
-
-// Copy constructor
-Farray::Farray(const Farray & source) :
- _nrows(source._nrows), _ncols(source._ncols)
-{
- allocateMemory();
- *this = source;
-}
-
-// Destructor
-Farray::~Farray()
-{
- delete [] _buffer;
-}
-
-// Assignment operator
-Farray & Farray::operator=(const Farray & source)
-{
- int nrows = _nrows < source._nrows ? _nrows : source._nrows;
- int ncols = _ncols < source._ncols ? _ncols : source._ncols;
- for (int i=0; i < nrows; ++i)
- {
- for (int j=0; j < ncols; ++j)
- {
- (*this)(i,j) = source(i,j);
- }
- }
- return *this;
-}
-
-// Equals operator
-bool Farray::operator==(const Farray & other) const
-{
- if (_nrows != other._nrows) return false;
- if (_ncols != other._ncols) return false;
- for (int i=0; i < _nrows; ++i)
- {
- for (int j=0; j < _ncols; ++j)
- {
- if ((*this)(i,j) != other(i,j)) return false;
- }
- }
- return true;
-}
-
-// Length accessors
-int Farray::nrows() const
-{
- return _nrows;
-}
-
-int Farray::ncols() const
-{
- return _ncols;
-}
-
-// Set item accessor
-long & Farray::operator()(int i, int j)
-{
- if (i < 0 || i > _nrows) throw std::out_of_range("Farray row index out of range");
- if (j < 0 || j > _ncols) throw std::out_of_range("Farray col index out of range");
- return _buffer[offset(i,j)];
-}
-
-// Get item accessor
-const long & Farray::operator()(int i, int j) const
-{
- if (i < 0 || i > _nrows) throw std::out_of_range("Farray row index out of range");
- if (j < 0 || j > _ncols) throw std::out_of_range("Farray col index out of range");
- return _buffer[offset(i,j)];
-}
-
-// String output
-std::string Farray::asString() const
-{
- std::stringstream result;
- result << "[ ";
- for (int i=0; i < _nrows; ++i)
- {
- if (i > 0) result << " ";
- result << "[";
- for (int j=0; j < _ncols; ++j)
- {
- result << " " << (*this)(i,j);
- if (j < _ncols-1) result << ",";
- }
- result << " ]";
- if (i < _nrows-1) result << "," << std::endl;
- }
- result << " ]" << std::endl;
- return result.str();
-}
-
-// Get view
-void Farray::view(int* nrows, int* ncols, long** data) const
-{
- *nrows = _nrows;
- *ncols = _ncols;
- *data = _buffer;
-}
-
-// Private methods
-void Farray::allocateMemory()
-{
- if (_nrows <= 0) throw std::invalid_argument("Farray nrows <= 0");
- if (_ncols <= 0) throw std::invalid_argument("Farray ncols <= 0");
- _buffer = new long[_nrows*_ncols];
-}
-
-inline int Farray::offset(int i, int j) const
-{
- return i + j * _nrows;
-}