diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-01-02 08:26:24 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-01-02 08:26:24 +0000 |
commit | 4712a37b93832933a46376ee99339f9040ba3670 (patch) | |
tree | 8a3de8500925061b0f2368fae2d50159dbea206f /scipy/weave/scxx/tuple.h | |
parent | b5ba0003def4cfa43b29d29df8f085d09609707b (diff) | |
download | numpy-4712a37b93832933a46376ee99339f9040ba3670.tar.gz |
Moved weave to scipy
Diffstat (limited to 'scipy/weave/scxx/tuple.h')
-rw-r--r-- | scipy/weave/scxx/tuple.h | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/scipy/weave/scxx/tuple.h b/scipy/weave/scxx/tuple.h deleted file mode 100644 index 895e50c8a..000000000 --- a/scipy/weave/scxx/tuple.h +++ /dev/null @@ -1,86 +0,0 @@ -#if !defined(TUPLE_H_INCLUDED_) -#define TUPLE_H_INCLUDED_ - -#include "sequence.h" -#include <string> - -namespace py { - -class tuple : public sequence -{ -public: - - //------------------------------------------------------------------------- - // constructors - //------------------------------------------------------------------------- - tuple(int sz=0) : sequence (PyTuple_New(sz)) { lose_ref(_obj); } - tuple(const tuple& other) : sequence(other) { } - tuple(PyObject* obj) : sequence(obj) { _violentTypeCheck(); } - tuple::tuple(const list& lst) - : sequence (PyList_AsTuple(lst)) { lose_ref(_obj); } - - //------------------------------------------------------------------------- - // destructor - //------------------------------------------------------------------------- - virtual ~tuple() {}; - - //------------------------------------------------------------------------- - // operator= - //------------------------------------------------------------------------- - virtual tuple& operator=(const tuple& other) { - grab_ref(other); - return *this; - }; - /*virtual*/ tuple& operator=(const object& other) { - grab_ref(other); - _violentTypeCheck(); - return *this; - }; - - //------------------------------------------------------------------------- - // type checking - //------------------------------------------------------------------------- - virtual void _violentTypeCheck() { - if (!PyTuple_Check(_obj)) { - grab_ref(0); - fail(PyExc_TypeError, "Not a Python Tuple"); - } - }; - - //------------------------------------------------------------------------- - // set_item - // - // We have to do a little extra checking here, because tuples can only - // be assigned to if there is only a single reference to them. - //------------------------------------------------------------------------- - virtual void set_item(int ndx, object& val) { - if (_obj->ob_refcnt != 1) - fail(PyExc_TypeError,"Tuples values can't be set if ref count > 1\n"); - int rslt = PyTuple_SetItem(_obj, ndx, val); - val.disown(); //when using PyTuple_SetItem, he steals my reference - if (rslt==-1) - throw 1; - }; - - //------------------------------------------------------------------------- - // operator[] -- const and non-const versions of element access. - //------------------------------------------------------------------------- - indexed_ref tuple::operator [] (int i) { - // get a "borrowed" refcount - PyObject* o = PyTuple_GetItem(_obj, i); - // don't throw error for when [] fails because it might be on left hand - // side (a[0] = 1). If the tuple was just created, it will be filled - // with NULL values, and setting the values should be ok. However, we - // do want to catch index errors that might occur on the right hand side - // (obj = a[4] when a has len==3). - if (!o) { - if (PyErr_ExceptionMatches(PyExc_IndexError)) - throw 1; - } - return indexed_ref(o, *this, i); // this increfs - }; -};// class tuple - -} // namespace - -#endif // TUPLE_H_INCLUDED_ |