2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-27 19:12:16 +00:00

Support for MinGW-2.0

[SVN r15719]
This commit is contained in:
Dave Abrahams
2002-10-04 21:34:32 +00:00
parent f4d457998f
commit 5e8d775b87
12 changed files with 482 additions and 1636 deletions

View File

@@ -8,110 +8,126 @@
namespace boost { namespace python {
class dict : public object
class dict;
namespace detail
{
public:
struct BOOST_PYTHON_DECL dict_base : object
{
// D.clear() -> None. Remove all items from D.
void clear();
// D.copy() -> a shallow copy of D
dict copy();
// D.get(k[,d]) -> D[k] if D.has_key(k), else d. d defaults to None.
object get(object_cref k) const;
object get(object_cref k, object_cref d) const;
// D.has_key(k) -> 1 if D has a key k, else 0
bool has_key(object_cref k) const;
// D.items() -> list of D's (key, value) pairs, as 2-tuples
list items() const;
// D.iteritems() -> an iterator over the (key, value) items of D
object iteritems() const;
// D.iterkeys() -> an iterator over the keys of D
object iterkeys() const;
// D.itervalues() -> an iterator over the values of D
object itervalues() const;
// D.keys() -> list of D's keys
list keys() const;
// D.popitem() -> (k, v), remove and return some (key, value) pair as a
// 2-tuple; but raise KeyError if D is empty
tuple popitem();
// D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if not D.has_key(k)
object setdefault(object_cref k);
object setdefault(object_cref k, object_cref d);
// D.update(E) -> None. Update D from E: for k in E.keys(): D[k] = E[k]
void update(object_cref E);
// D.values() -> list of D's values
list values() const;
protected:
// dict() -> new empty dictionary.
// dict(mapping) -> new dictionary initialized from a mapping object's
// (key, value) pairs.
// dict(seq) -> new dictionary initialized as if via:
dict_base(); // new dict
explicit dict_base(object_cref data);
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict_base, object)
private:
static detail::new_reference call(object const&);
};
}
class dict : public detail::dict_base
{
typedef detail::dict_base base;
public:
// dict() -> new empty dictionary.
// dict(mapping) -> new dictionary initialized from a mapping object's
// (key, value) pairs.
// dict(seq) -> new dictionary initialized as if via:
BOOST_PYTHON_DECL dict(); // new dict
explicit BOOST_PYTHON_DECL dict(object_cref data);
dict() {} // new dict
template <class T>
explicit dict(T const& data)
: object(dict::call(object(data)))
: base(object(data))
{
}
// D.clear() -> None. Remove all items from D.
BOOST_PYTHON_DECL void clear();
// D.copy() -> a shallow copy of D
BOOST_PYTHON_DECL dict copy();
// D.get(k[,d]) -> D[k] if D.has_key(k), else d. d defaults to None.
BOOST_PYTHON_DECL object get(object_cref k) const;
template<class T>
object get(T const& k) const
{
return this->get(object(k));
return base::get(object(k));
}
BOOST_PYTHON_DECL object get(object_cref k, object_cref d) const;
template<class T1, class T2>
object get(T1 const& k, T2 const& d) const
{
return this->get(object(k),object(d));
return base::get(object(k),object(d));
}
// D.has_key(k) -> 1 if D has a key k, else 0
BOOST_PYTHON_DECL bool has_key(object_cref k) const;
template<class T>
bool has_key(T const& k) const
{
return this->has_key(object(k));
return base::has_key(object(k));
}
// D.items() -> list of D's (key, value) pairs, as 2-tuples
BOOST_PYTHON_DECL list items() const;
// D.iteritems() -> an iterator over the (key, value) items of D
BOOST_PYTHON_DECL object iteritems() const;
// D.iterkeys() -> an iterator over the keys of D
BOOST_PYTHON_DECL object iterkeys() const;
// D.itervalues() -> an iterator over the values of D
BOOST_PYTHON_DECL object itervalues() const;
// D.keys() -> list of D's keys
BOOST_PYTHON_DECL list keys() const;
// D.popitem() -> (k, v), remove and return some (key, value) pair as a
// 2-tuple; but raise KeyError if D is empty
BOOST_PYTHON_DECL tuple popitem();
// D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if not D.has_key(k)
BOOST_PYTHON_DECL object setdefault(object_cref k);
template<class T>
object setdefault(T const& k)
{
return this->setdefault(object(k));
return base::setdefault(object(k));
}
BOOST_PYTHON_DECL object setdefault(object_cref k, object_cref d);
template<class T1, class T2>
object setdefault(T1 const& k, T2 const& d)
{
return this->setdefault(object(k),object(d));
return base::setdefault(object(k),object(d));
}
// D.update(E) -> None. Update D from E: for k in E.keys(): D[k] = E[k]
BOOST_PYTHON_DECL void update(object_cref E);
template<class T>
void update(T const& E)
{
this->update(object(E));
base::update(object(E));
}
// D.values() -> list of D's values
BOOST_PYTHON_DECL list values() const;
public: // implementation detail -- for internal use only
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict, object)
private:
static BOOST_PYTHON_DECL detail::new_reference call(object const&);
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict, base)
};
//
// Converter Specializations
//

View File

@@ -11,93 +11,116 @@
namespace boost { namespace python {
class list : public object
namespace detail
{
struct BOOST_PYTHON_DECL list_base : object
{
void append(object_cref); // append object to end
long count(object_cref value) const; // return number of occurrences of value
void extend(object_cref sequence); // extend list by appending sequence elements
long index(object_cref value) const; // return index of first occurrence of value
void insert(int index, object_cref); // insert object before index
void insert(object const& index, object_cref);
object pop(); // remove and return item at index (default last)
object pop(long index);
object pop(object const& index);
void remove(object_cref value); // remove first occurrence of value
void reverse(); // reverse *IN PLACE*
void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
void sort(object_cref cmpfunc);
protected:
list_base(); // new list
explicit list_base(object_cref sequence); // new list initialized from sequence's items
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list_base, object)
private:
static detail::new_non_null_reference call(object const&);
};
}
class list : public detail::list_base
{
typedef detail::list_base base;
public:
BOOST_PYTHON_DECL list(); // new list
explicit BOOST_PYTHON_DECL list(object_cref sequence); // new list initialized from sequence's items
list() {} // new list
template <class T>
explicit list(T const& sequence)
: object(list::call(object(sequence)))
: base(object(sequence))
{
}
BOOST_PYTHON_DECL void append(object_cref); // append object to end
template <class T>
void append(T const& x)
{
this->append(object(x));
base::append(object(x));
}
BOOST_PYTHON_DECL long count(object_cref value) const; // return number of occurrences of value
template <class T>
long count(T const& value) const
{
return this->count(object(value));
return base::count(object(value));
}
BOOST_PYTHON_DECL void extend(object_cref sequence); // extend list by appending sequence elements
template <class T>
void extend(T const& x)
{
this->extend(object(x));
base::extend(object(x));
}
BOOST_PYTHON_DECL long index(object_cref value) const; // return index of first occurrence of value
template <class T>
long index(T const& x) const
{
return this->index(object(x));
return base::index(object(x));
}
BOOST_PYTHON_DECL void insert(int index, object_cref); // insert object before index
BOOST_PYTHON_DECL void insert(object const& index, object_cref);
template <class T>
void insert(int index, T const& x) // insert object before index
{
this->insert(index, object(x));
base::insert(index, object(x));
}
template <class T>
void insert(object const& index, T const& x) // insert object before index
{
this->insert(index, object(x));
base::insert(index, object(x));
}
BOOST_PYTHON_DECL object pop(); // remove and return item at index (default last)
BOOST_PYTHON_DECL object pop(long index);
BOOST_PYTHON_DECL object pop(object const& index);
BOOST_PYTHON_DECL void remove(object_cref value); // remove first occurrence of value
object pop() { return base::pop(); }
object pop(long index) { return base::pop(index); }
template <class T>
object pop(T const& index)
{
return base::pop(object(index));
}
template <class T>
void remove(T const& value)
{
this->remove(object(value));
base::remove(object(value));
}
void sort() { base::sort(); }
BOOST_PYTHON_DECL void reverse(); // reverse *IN PLACE*
BOOST_PYTHON_DECL void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
BOOST_PYTHON_DECL void sort(object_cref cmpfunc);
template <class T>
void sort(T const& value)
{
this->sort(object(value));
base::sort(object(value));
}
public: // implementation detail -- for internal use only
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, object)
private:
static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&);
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, base)
};
//

View File

@@ -11,31 +11,43 @@
namespace boost { namespace python {
class long_ : public object
namespace detail
{
struct BOOST_PYTHON_DECL long_base : object
{
protected:
long_base(); // new long_
explicit long_base(object_cref rhs);
explicit long_base(object_cref rhs, object_cref base);
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(long_base, object)
private:
static detail::new_non_null_reference call(object const&);
static detail::new_non_null_reference call(object const&, object const&);
};
}
class long_ : public detail::long_base
{
typedef detail::long_base base;
public:
BOOST_PYTHON_DECL long_(); // new long_
explicit BOOST_PYTHON_DECL long_(object_cref rhs);
long_() {} // new long_
template <class T>
explicit long_(T const& rhs)
: object(long_::call(object(rhs)))
: base(object(rhs))
{
}
explicit BOOST_PYTHON_DECL long_(object_cref rhs, object_cref base);
template <class T, class U>
explicit long_(T const& rhs, U const& base)
: object(long_::call(object(rhs), object(base)))
: base(object(rhs), object(base))
{
}
public: // implementation detail -- for internal use only
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(long_, object)
private:
static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&);
static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&, object const&);
public: // implementation detail -- for internal use only
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(long_, base)
};
//

View File

@@ -12,7 +12,7 @@
namespace boost { namespace python
{
struct instance_holder;
struct BOOST_PYTHON_DECL instance_holder;
}} // namespace boost::python
namespace boost { namespace python { namespace objects {

View File

@@ -15,347 +15,367 @@
namespace boost { namespace python {
class str : public object
{
public:
BOOST_PYTHON_DECL str(); // new str
BOOST_PYTHON_DECL str(const char* s); // new str
explicit BOOST_PYTHON_DECL str(object_cref other);
class str;
namespace detail
{
struct BOOST_PYTHON_DECL str_base : object
{
str capitalize() const;
str center(object_cref width) const;
long count(object_cref sub) const;
long count(object_cref sub, object_cref start) const;
long count(object_cref sub, object_cref start, object_cref end) const;
object decode() const;
object decode(object_cref encoding) const;
object decode(object_cref encoding, object_cref errors) const;
object encode() const;
object encode(object_cref encoding) const;
object encode(object_cref encoding, object_cref errors) const;
bool endswith(object_cref suffix) const;
bool endswith(object_cref suffix, object_cref start) const;
bool endswith(object_cref suffix, object_cref start, object_cref end) const;
str expandtabs() const;
str expandtabs(object_cref tabsize) const;
long find(object_cref sub) const;
long find(object_cref sub, object_cref start) const;
long find(object_cref sub, object_cref start, object_cref end) const;
long index(object_cref sub) const;
long index(object_cref sub, object_cref start) const;
long index(object_cref sub, object_cref start, object_cref end) const;
bool isalnum() const;
bool isalpha() const;
bool isdigit() const;
bool islower() const;
bool isspace() const;
bool istitle() const;
bool isupper() const;
str join(object_cref sequence) const;
str ljust(object_cref width) const;
str lower() const;
str lstrip() const;
str replace(object_cref old, object_cref new_) const;
str replace(object_cref old, object_cref new_, object_cref maxsplit) const;
long rfind(object_cref sub) const;
long rfind(object_cref sub, object_cref start) const;
long rfind(object_cref sub, object_cref start, object_cref end) const;
long rindex(object_cref sub) const;
long rindex(object_cref sub, object_cref start) const;
long rindex(object_cref sub, object_cref start, object_cref end) const;
str rjust(object_cref width) const;
str rstrip() const;
list split() const;
list split(object_cref sep) const;
list split(object_cref sep, object_cref maxsplit) const;
list splitlines() const;
list splitlines(object_cref keepends) const;
bool startswith(object_cref prefix) const;
bool startswith(object_cref prefix, object_cref start) const;
bool startswith(object_cref prefix, object_cref start, object_cref end) const;
str strip() const;
str swapcase() const;
str title() const;
str translate(object_cref table) const;
str translate(object_cref table, object_cref deletechars) const;
str upper() const;
protected:
str_base(); // new str
str_base(const char* s); // new str
explicit str_base(object_cref other);
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str_base, object)
private:
static new_reference call(object const&);
};
}
class str : public detail::str_base
{
typedef detail::str_base base;
public:
str() {} // new str
str(const char* s) : str_base(s) {} // new str
template <class T>
explicit str(T const& other)
: object(str::call(object(other)))
: str_base(object(other))
{
}
BOOST_PYTHON_DECL str capitalize() const ;
BOOST_PYTHON_DECL str center(object_cref width) const ;
template <class T>
str center(T const& width) const
{
return this->center(object(width));
return base::center(object(width));
}
BOOST_PYTHON_DECL long count(object_cref sub) const;
template<class T>
long count(T const& sub) const
{
return this->count(object(sub));
return base::count(object(sub));
}
BOOST_PYTHON_DECL long count(object_cref sub, object_cref start) const;
template<class T1, class T2>
long count(T1 const& sub,T2 const& start) const
{
return this->count(object(sub), object(start));
return base::count(object(sub), object(start));
}
BOOST_PYTHON_DECL long count(object_cref sub, object_cref start, object_cref end) const;
template<class T1, class T2, class T3>
long count(T1 const& sub,T2 const& start, T3 const& end) const
{
return this->count(object(sub), object(start));
return base::count(object(sub), object(start));
}
BOOST_PYTHON_DECL object decode() const;
BOOST_PYTHON_DECL object decode(object_cref encoding) const;
object decode() const { return base::decode(); }
template<class T>
object decode(T const& encoding) const
{
return this->decode(object(encoding));
return base::decode(object(encoding));
}
BOOST_PYTHON_DECL object decode(object_cref encoding, object_cref errors) const;
template<class T1, class T2>
object decode(T1 const& encoding, T2 const& errors) const
{
return this->decode(object(encoding),object(errors));
return base::decode(object(encoding),object(errors));
}
BOOST_PYTHON_DECL object encode() const;
BOOST_PYTHON_DECL object encode(object_cref encoding) const;
object encode() const { return base::encode(); }
template <class T>
object encode(T const& encoding) const
{
return this->encode(object(encoding));
return base::encode(object(encoding));
}
BOOST_PYTHON_DECL object encode(object_cref encoding, object_cref errors) const;
template <class T1, class T2>
object encode(T1 const& encoding, T2 const& errors) const
{
return this->encode(object(encoding),object(errors));
return base::encode(object(encoding),object(errors));
}
BOOST_PYTHON_DECL bool endswith(object_cref suffix) const;
template <class T>
bool endswith(T const& suffix) const
{
return this->endswith(object(suffix));
return base::endswith(object(suffix));
}
BOOST_PYTHON_DECL bool endswith(object_cref suffix, object_cref start) const;
template <class T1, class T2>
bool endswith(T1 const& suffix, T2 const& start) const
{
return this->endswith(object(suffix), object(start));
return base::endswith(object(suffix), object(start));
}
BOOST_PYTHON_DECL bool endswith(object_cref suffix, object_cref start, object_cref end) const;
template <class T1, class T2, class T3>
bool endswith(T1 const& suffix, T2 const& start, T3 const& end) const
{
return this->endswith(object(suffix), object(start), object(end));
return base::endswith(object(suffix), object(start), object(end));
}
BOOST_PYTHON_DECL str expandtabs() const;
BOOST_PYTHON_DECL str expandtabs(object_cref tabsize) const;
str expandtabs() const { return base::expandtabs(); }
template <class T>
str expandtabs(T const& tabsize) const
{
return this->expandtabs(object(tabsize));
return base::expandtabs(object(tabsize));
}
BOOST_PYTHON_DECL long find(object_cref sub) const;
template <class T>
long find(T const& sub) const
{
return this->find(object(sub));
return base::find(object(sub));
}
BOOST_PYTHON_DECL long find(object_cref sub, object_cref start) const;
template <class T1, class T2>
long find(T1 const& sub, T2 const& start) const
{
return this->find(object(sub), object(start));
return base::find(object(sub), object(start));
}
BOOST_PYTHON_DECL long find(object_cref sub, object_cref start, object_cref end) const;
template <class T1, class T2, class T3>
long find(T1 const& sub, T2 const& start, T3 const& end) const
{
return this->find(object(sub), object(start), object(end));
return base::find(object(sub), object(start), object(end));
}
BOOST_PYTHON_DECL long index(object_cref sub) const;
template <class T>
long index(T const& sub) const
{
return this->index(object(sub));
return base::index(object(sub));
}
BOOST_PYTHON_DECL long index(object_cref sub, object_cref start) const;
template <class T1, class T2>
long index(T1 const& sub, T2 const& start) const
{
return this->index(object(sub), object(start));
return base::index(object(sub), object(start));
}
BOOST_PYTHON_DECL long index(object_cref sub, object_cref start, object_cref end) const;
template <class T1, class T2, class T3>
long index(T1 const& sub, T2 const& start, T3 const& end) const
{
return this->index(object(sub), object(start), object(end));
return base::index(object(sub), object(start), object(end));
}
BOOST_PYTHON_DECL bool isalnum() const;
BOOST_PYTHON_DECL bool isalpha() const;
BOOST_PYTHON_DECL bool isdigit() const;
BOOST_PYTHON_DECL bool islower() const;
BOOST_PYTHON_DECL bool isspace() const;
BOOST_PYTHON_DECL bool istitle() const;
BOOST_PYTHON_DECL bool isupper() const;
BOOST_PYTHON_DECL str join(object_cref sequence) const;
template <class T>
str join(T const& sequence) const
{
return this->join(object(sequence));
return base::join(object(sequence));
}
BOOST_PYTHON_DECL str ljust(object_cref width) const;
template <class T>
str ljust(T const& width) const
{
return this->ljust(object(width));
return base::ljust(object(width));
}
BOOST_PYTHON_DECL str lower() const;
BOOST_PYTHON_DECL str lstrip() const;
BOOST_PYTHON_DECL str replace(object_cref old, object_cref new_) const ;
template <class T1, class T2>
str replace(T1 const& old, T2 const& new_) const
{
return this->replace(object(old),object(new_));
return base::replace(object(old),object(new_));
}
BOOST_PYTHON_DECL str replace(object_cref old, object_cref new_, object_cref maxsplit) const ;
template <class T1, class T2, class T3>
str replace(T1 const& old, T2 const& new_, T3 const& maxsplit) const
{
return this->replace(object(old),object(new_),object(maxsplit));
return base::replace(object(old),object(new_), object(maxsplit));
}
BOOST_PYTHON_DECL long rfind(object_cref sub) const;
template <class T>
long rfind(T const& sub) const
{
return this->rfind(object(sub));
return base::rfind(object(sub));
}
BOOST_PYTHON_DECL long rfind(object_cref sub, object_cref start) const;
template <class T1, class T2>
long rfind(T1 const& sub, T2 const& start) const
{
return this->rfind(object(sub), object(start));
return base::rfind(object(sub), object(start));
}
BOOST_PYTHON_DECL long rfind(object_cref sub, object_cref start, object_cref end) const;
template <class T1, class T2, class T3>
long rfind(T1 const& sub, T2 const& start, T3 const& end) const
{
return this->rfind(object(sub), object(start), object(end));
return base::rfind(object(sub), object(start), object(end));
}
BOOST_PYTHON_DECL long rindex(object_cref sub) const;
template <class T>
long rindex(T const& sub) const
{
return this->rindex(object(sub));
return base::rindex(object(sub));
}
BOOST_PYTHON_DECL long rindex(object_cref sub, object_cref start) const;
template <class T1, class T2>
long rindex(T1 const& sub, T2 const& start) const
{
return this->rindex(object(sub), object(start));
return base::rindex(object(sub), object(start));
}
BOOST_PYTHON_DECL long rindex(object_cref sub, object_cref start, object_cref end) const;
template <class T1, class T2, class T3>
long rindex(T1 const& sub, T2 const& start, T3 const& end) const
{
return this->rindex(object(sub), object(start), object(end));
return base::rindex(object(sub), object(start), object(end));
}
BOOST_PYTHON_DECL str rjust(object_cref width) const;
template <class T>
str rjust(T const& width) const
{
return this->rjust(object(width));
return base::rjust(object(width));
}
BOOST_PYTHON_DECL str rstrip() const;
BOOST_PYTHON_DECL list split() const;
BOOST_PYTHON_DECL list split(object_cref sep) const;
list split() const { return base::split(); }
template <class T>
list split(T const& sep) const
{
return this->split(object(sep));
return base::split(object(sep));
}
BOOST_PYTHON_DECL list split(object_cref sep, object_cref maxsplit) const;
template <class T1, class T2>
list split(T1 const& sep, T2 const& maxsplit) const
{
return this->split(object(sep), object(maxsplit));
return base::split(object(sep), object(maxsplit));
}
BOOST_PYTHON_DECL list splitlines() const;
BOOST_PYTHON_DECL list splitlines(object_cref keepends) const;
list splitlines() const { return base::splitlines(); }
template <class T>
list splitlines(T const& keepends) const
{
return this->splitlines(object(keepends));
return base::splitlines(object(keepends));
}
BOOST_PYTHON_DECL bool startswith(object_cref prefix) const ;
template <class T>
bool startswith(T const& prefix) const
{
return this->startswith(object(prefix));
return base::startswith(object(prefix));
}
BOOST_PYTHON_DECL bool startswith(object_cref prefix, object_cref start) const ;
template <class T1, class T2>
bool startswidth(T1 const& prefix, T2 const& start) const
{
return this->startswidth(object(prefix), object(start));
return base::startswidth(object(prefix), object(start));
}
BOOST_PYTHON_DECL bool startswith(object_cref prefix, object_cref start, object_cref end) const ;
template <class T1, class T2, class T3>
bool startswidth(T1 const& prefix, T2 const& start, T3 const& end) const
{
return this->startswidth(object(prefix), object(start), object(end));
return base::startswidth(object(prefix), object(start), object(end));
}
BOOST_PYTHON_DECL str strip() const ;
BOOST_PYTHON_DECL str swapcase() const ;
BOOST_PYTHON_DECL str title() const ;
BOOST_PYTHON_DECL str translate(object_cref table) const;
template <class T>
str translate(T const& table) const
{
return this->translate(object(table));
return base::translate(object(table));
}
BOOST_PYTHON_DECL str translate(object_cref table, object_cref deletechars) const;
template <class T1, class T2>
str translate(T1 const& table, T2 const& deletechars) const
{
return this->translate(object(table), object(deletechars));
return base::translate(object(table), object(deletechars));
}
BOOST_PYTHON_DECL str upper() const;
public: // implementation detail -- for internal use only
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str, object)
private:
static BOOST_PYTHON_DECL detail::new_reference call(object const&);
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str, base)
};
//

View File

@@ -8,26 +8,35 @@
namespace boost { namespace python {
class tuple : public object
namespace detail
{
public:
// tuple() -> an empty tuple
BOOST_PYTHON_DECL tuple();
struct BOOST_PYTHON_DECL tuple_base : object
{
protected:
tuple_base();
tuple_base(object_cref sequence);
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(tuple_base, object)
// tuple(sequence) -> tuple initialized from sequence's items
BOOST_PYTHON_DECL tuple(object_cref sequence);
private:
static detail::new_reference call(object const&);
};
}
class tuple : public detail::tuple_base
{
typedef detail::tuple_base base;
public:
tuple() {}
template <class T>
explicit tuple(T const& sequence)
: object(tuple::call(object(sequence)))
: tuple_base(object(sequence))
{
}
public: // implementation detail -- for internal use only
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(tuple, object)
private:
static BOOST_PYTHON_DECL detail::new_reference call(object const&);
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(tuple, base)
};
//

View File

@@ -1,8 +1,7 @@
#include <boost/python/dict.hpp>
#include <boost/python/extract.hpp>
namespace boost { namespace python {
namespace boost { namespace python { namespace detail {
namespace
{
// When returning list objects from methods, it may turn out that the
@@ -18,28 +17,28 @@ namespace
}
// No PyDict_CheckExact; roll our own.
inline bool check_exact(dict const* p)
inline bool check_exact(dict_base const* p)
{
return p->ptr()->ob_type == &PyDict_Type;
}
}
detail::new_reference dict::call(object const& arg_)
detail::new_reference dict_base::call(object const& arg_)
{
return (detail::new_reference)PyObject_CallFunction(
(PyObject*)&PyDict_Type, "(O)",
arg_.ptr());
}
dict::dict()
dict_base::dict_base()
: object(detail::new_reference(PyDict_New()))
{}
dict::dict(object_cref data)
: object(dict::call(data))
dict_base::dict_base(object_cref data)
: object(call(data))
{}
void dict::clear()
void dict_base::clear()
{
if (check_exact(this))
PyDict_Clear(this->ptr());
@@ -47,7 +46,7 @@ void dict::clear()
this->attr("clear")();
}
dict dict::copy()
dict dict_base::copy()
{
if (check_exact(this))
{
@@ -62,7 +61,7 @@ dict dict::copy()
}
}
object dict::get(object_cref k) const
object dict_base::get(object_cref k) const
{
if (check_exact(this))
{
@@ -75,17 +74,17 @@ object dict::get(object_cref k) const
}
}
object dict::get(object_cref k, object_cref d) const
object dict_base::get(object_cref k, object_cref d) const
{
return this->attr("get")(k,d);
}
bool dict::has_key(object_cref k) const
bool dict_base::has_key(object_cref k) const
{
return extract<bool>(this->attr("has_key")(k));
}
list dict::items() const
list dict_base::items() const
{
if (check_exact(this))
{
@@ -98,22 +97,22 @@ list dict::items() const
}
}
object dict::iteritems() const
object dict_base::iteritems() const
{
return this->attr("iteritems")();
}
object dict::iterkeys() const
object dict_base::iterkeys() const
{
return this->attr("iterkeys")();
}
object dict::itervalues() const
object dict_base::itervalues() const
{
return this->attr("itervalues")();
}
list dict::keys() const
list dict_base::keys() const
{
if (check_exact(this))
{
@@ -126,24 +125,24 @@ list dict::keys() const
}
}
tuple dict::popitem()
tuple dict_base::popitem()
{
return tuple(detail::borrowed_reference(
this->attr("popitem")().ptr()
));
}
object dict::setdefault(object_cref k)
object dict_base::setdefault(object_cref k)
{
return this->attr("setdefault")(k);
}
object dict::setdefault(object_cref k, object_cref d)
object dict_base::setdefault(object_cref k, object_cref d)
{
return this->attr("setdefault")(k,d);
}
void dict::update(object_cref other)
void dict_base::update(object_cref other)
{
if (check_exact(this))
{
@@ -156,7 +155,7 @@ void dict::update(object_cref other)
}
}
list dict::values() const
list dict_base::values() const
{
if (check_exact(this))
{
@@ -169,4 +168,4 @@ list dict::values() const
}
}
}} // namespace boost::python
}}} // namespace boost::python

View File

@@ -5,9 +5,9 @@
// to its suitability for any purpose.
#include <boost/python/list.hpp>
namespace boost { namespace python {
namespace boost { namespace python { namespace detail {
detail::new_non_null_reference list::call(object const& arg_)
detail::new_non_null_reference list_base::call(object const& arg_)
{
return (detail::new_non_null_reference)
(expect_non_null)(
@@ -16,15 +16,15 @@ detail::new_non_null_reference list::call(object const& arg_)
arg_.ptr()));
}
list::list()
list_base::list_base()
: object(detail::new_reference(PyList_New(0)))
{}
list::list(object_cref sequence)
: object(list::call(sequence))
list_base::list_base(object_cref sequence)
: object(list_base::call(sequence))
{}
void list::append(object_cref x)
void list_base::append(object_cref x)
{
if (PyList_CheckExact(this->ptr()))
{
@@ -37,7 +37,7 @@ void list::append(object_cref x)
}
}
long list::count(object_cref value) const
long list_base::count(object_cref value) const
{
object result_obj(this->attr("count")(value));
long result = PyInt_AsLong(result_obj.ptr());
@@ -46,12 +46,12 @@ long list::count(object_cref value) const
return result;
}
void list::extend(object_cref sequence)
void list_base::extend(object_cref sequence)
{
this->attr("extend")(sequence);
}
long list::index(object_cref value) const
long list_base::index(object_cref value) const
{
object result_obj(this->attr("index")(value));
long result = PyInt_AsLong(result_obj.ptr());
@@ -60,7 +60,7 @@ long list::index(object_cref value) const
return result;
}
void list::insert(int index, object_cref item)
void list_base::insert(int index, object_cref item)
{
if (PyList_CheckExact(this->ptr()))
{
@@ -73,7 +73,7 @@ void list::insert(int index, object_cref item)
}
}
void list::insert(object const& index, object_cref x)
void list_base::insert(object const& index, object_cref x)
{
long index_ = PyInt_AsLong(index.ptr());
if (index_ == -1 && PyErr_Occurred())
@@ -81,27 +81,27 @@ void list::insert(object const& index, object_cref x)
this->insert(index_, x);
}
object list::pop()
object list_base::pop()
{
return this->attr("pop")();
}
object list::pop(long index)
object list_base::pop(long index)
{
return this->pop(object(index));
}
object list::pop(object const& index)
object list_base::pop(object const& index)
{
return this->attr("pop")(index);
}
void list::remove(object_cref value)
void list_base::remove(object_cref value)
{
this->attr("remove")(value);
}
void list::reverse()
void list_base::reverse()
{
if (PyList_CheckExact(this->ptr()))
{
@@ -114,7 +114,7 @@ void list::reverse()
}
}
void list::sort()
void list_base::sort()
{
if (PyList_CheckExact(this->ptr()))
{
@@ -127,9 +127,9 @@ void list::sort()
}
}
void list::sort(object_cref cmpfunc)
void list_base::sort(object_cref cmpfunc)
{
this->attr("sort")(cmpfunc);
}
}} // namespace boost::python
}}} // namespace boost::python

View File

@@ -5,36 +5,36 @@
// to its suitability for any purpose.
#include <boost/python/long.hpp>
namespace boost { namespace python {
namespace boost { namespace python { namespace detail {
detail::new_non_null_reference long_::call(object const& arg_)
new_non_null_reference long_base::call(object const& arg_)
{
return (detail::new_non_null_reference)PyObject_CallFunction(
(PyObject*)&PyLong_Type, "(O)",
arg_.ptr());
}
detail::new_non_null_reference long_::call(object const& arg_, object const& base)
new_non_null_reference long_base::call(object const& arg_, object const& base)
{
return (detail::new_non_null_reference)PyObject_CallFunction(
(PyObject*)&PyLong_Type, "(OO)",
arg_.ptr(), base.ptr());
}
long_::long_()
long_base::long_base()
: object(
detail::new_reference(
PyObject_CallFunction((PyObject*)&PyLong_Type, "()"))
)
{}
long_::long_(object_cref arg)
: object(long_::call(arg))
long_base::long_base(object_cref arg)
: object(long_base::call(arg))
{}
long_::long_(object_cref arg, object_cref base)
: object(long_::call(arg, base))
long_base::long_base(object_cref arg, object_cref base)
: object(long_base::call(arg, base))
{}
}} // namespace boost::python
}}} // namespace boost::python

View File

@@ -1,99 +1,98 @@
#include <boost/python/str.hpp>
#include <boost/python/extract.hpp>
namespace boost { namespace python {
namespace boost { namespace python { namespace detail {
detail::new_reference str::call(object const& arg_)
detail::new_reference str_base::call(object const& arg_)
{
return (detail::new_reference)PyObject_CallFunction(
(PyObject*)&PyString_Type, "(O)",
arg_.ptr());
}
str::str()
str_base::str_base()
: object(detail::new_reference(PyString_FromString("")))
{}
str::str(const char* s)
str_base::str_base(const char* s)
: object(detail::new_reference(PyString_FromString(s)))
{}
str::str(object_cref other)
: object(str::call(other))
str_base::str_base(object_cref other)
: object(str_base::call(other))
{}
namespace
{
// When returning str objects from methods, it may turn out that the
// derived class is returning something else, perhaps something not
// even derived from str. Since it is generally harmless for a
// Boost.Python wrapper object to hold an object of a different
// type, and because calling str() with an object may in fact
// perform a conversion, the least-bad alternative is to assume that
// we have a Python str object and stuff it into the str result.
str assume_str(object const& o)
new_reference new_attr_reference(object const* obj, char const* name)
{
return str(detail::borrowed_reference(o.ptr()));
return new_reference(incref(object(obj->attr(name)).ptr()));
}
}
str str::capitalize() const
{
return assume_str(this->attr("capitalize")());
#define BOOST_PYTHON_FORMAT_OBJECT(z, n, data) "O"
#define BOOST_PYTHON_OBJECT_PTR(z, n, data) , x##n .ptr()
#define BOOST_PYTHON_DEFINE_STR_METHOD(name, arity) \
str str_base:: name ( BOOST_PP_ENUM_PARAMS(arity, object_cref x) ) const \
{ \
return str(new_reference( \
expect_non_null( \
PyObject_CallMethod( \
this->ptr(), #name, \
"(" BOOST_PP_REPEAT(arity, BOOST_PYTHON_FORMAT_OBJECT, _) ")" \
BOOST_PP_REPEAT_1(arity, BOOST_PYTHON_OBJECT_PTR, _))))); \
}
str str::center(object_cref width) const
{
return assume_str(
this->attr("center")(width)
);
}
BOOST_PYTHON_DEFINE_STR_METHOD(capitalize, 0)
BOOST_PYTHON_DEFINE_STR_METHOD(center, 1)
long str::count(object_cref sub) const
long str_base::count(object_cref sub) const
{
return extract<long>(this->attr("count")(sub));
}
long str::count(object_cref sub, object_cref start) const
long str_base::count(object_cref sub, object_cref start) const
{
return extract<long>(this->attr("count")(sub,start));
}
long str::count(object_cref sub, object_cref start, object_cref end) const
long str_base::count(object_cref sub, object_cref start, object_cref end) const
{
return extract<long>(this->attr("count")(sub,start,end));
}
object str::decode() const
object str_base::decode() const
{
return this->attr("decode")();
}
object str::decode(object_cref encoding) const
object str_base::decode(object_cref encoding) const
{
return this->attr("decode")(encoding);
}
object str::decode(object_cref encoding, object_cref errors) const
object str_base::decode(object_cref encoding, object_cref errors) const
{
return this->attr("decode")(encoding,errors);
}
object str::encode() const
object str_base::encode() const
{
return this->attr("encode")();
}
object str::encode(object_cref encoding) const
object str_base::encode(object_cref encoding) const
{
return this->attr("encode")(encoding);
}
object str::encode(object_cref encoding, object_cref errors) const
object str_base::encode(object_cref encoding, object_cref errors) const
{
return this->attr("encode")(encoding,errors);
}
bool str::endswith(object_cref suffix) const
bool str_base::endswith(object_cref suffix) const
{
bool result = PyInt_AsLong(this->attr("endswith")(suffix).ptr());
if (PyErr_Occurred())
@@ -101,17 +100,10 @@ bool str::endswith(object_cref suffix) const
return result;
}
str str::expandtabs() const
{
return assume_str(this->attr("expandtabs")());
}
BOOST_PYTHON_DEFINE_STR_METHOD(expandtabs, 0)
BOOST_PYTHON_DEFINE_STR_METHOD(expandtabs, 1)
str str::expandtabs(object_cref tabsize) const
{
return assume_str(this->attr("expandtabs")(tabsize));
}
long str::find(object_cref sub) const
long str_base::find(object_cref sub) const
{
long result = PyInt_AsLong(this->attr("find")(sub).ptr());
if (PyErr_Occurred())
@@ -119,7 +111,7 @@ long str::find(object_cref sub) const
return result;
}
long str::find(object_cref sub, object_cref start) const
long str_base::find(object_cref sub, object_cref start) const
{
long result = PyInt_AsLong(this->attr("find")(sub,start).ptr());
if (PyErr_Occurred())
@@ -127,7 +119,7 @@ long str::find(object_cref sub, object_cref start) const
return result;
}
long str::find(object_cref sub, object_cref start, object_cref end) const
long str_base::find(object_cref sub, object_cref start, object_cref end) const
{
long result = PyInt_AsLong(this->attr("find")(sub,start,end).ptr());
if (PyErr_Occurred())
@@ -135,7 +127,7 @@ long str::find(object_cref sub, object_cref start, object_cref end) const
return result;
}
long str::index(object_cref sub) const
long str_base::index(object_cref sub) const
{
long result = PyInt_AsLong(this->attr("index")(sub).ptr());
if (PyErr_Occurred())
@@ -143,7 +135,7 @@ long str::index(object_cref sub) const
return result;
}
long str::index(object_cref sub, object_cref start) const
long str_base::index(object_cref sub, object_cref start) const
{
long result = PyInt_AsLong(this->attr("index")(sub,start).ptr());
if (PyErr_Occurred())
@@ -151,7 +143,7 @@ long str::index(object_cref sub, object_cref start) const
return result;
}
long str::index(object_cref sub, object_cref start, object_cref end) const
long str_base::index(object_cref sub, object_cref start, object_cref end) const
{
long result = PyInt_AsLong(this->attr("index")(sub,start,end).ptr());
if (PyErr_Occurred())
@@ -159,7 +151,7 @@ long str::index(object_cref sub, object_cref start, object_cref end) const
return result;
}
bool str::isalnum() const
bool str_base::isalnum() const
{
bool result = PyInt_AsLong(this->attr("isalnum")().ptr());
if (PyErr_Occurred())
@@ -167,7 +159,7 @@ bool str::isalnum() const
return result;
}
bool str::isalpha() const
bool str_base::isalpha() const
{
bool result = PyInt_AsLong(this->attr("isalpha")().ptr());
if (PyErr_Occurred())
@@ -175,7 +167,7 @@ bool str::isalpha() const
return result;
}
bool str::isdigit() const
bool str_base::isdigit() const
{
bool result = PyInt_AsLong(this->attr("isdigit")().ptr());
if (PyErr_Occurred())
@@ -183,7 +175,7 @@ bool str::isdigit() const
return result;
}
bool str::islower() const
bool str_base::islower() const
{
bool result = PyInt_AsLong(this->attr("islower")().ptr());
if (PyErr_Occurred())
@@ -191,7 +183,7 @@ bool str::islower() const
return result;
}
bool str::isspace() const
bool str_base::isspace() const
{
bool result = PyInt_AsLong(this->attr("isspace")().ptr());
if (PyErr_Occurred())
@@ -199,7 +191,7 @@ bool str::isspace() const
return result;
}
bool str::istitle() const
bool str_base::istitle() const
{
bool result = PyInt_AsLong(this->attr("istitle")().ptr());
if (PyErr_Occurred())
@@ -207,7 +199,7 @@ bool str::istitle() const
return result;
}
bool str::isupper() const
bool str_base::isupper() const
{
bool result = PyInt_AsLong(this->attr("isupper")().ptr());
if (PyErr_Occurred())
@@ -215,36 +207,14 @@ bool str::isupper() const
return result;
}
str str::join(object_cref sequence) const
{
return assume_str(this->attr("join")(sequence));
}
BOOST_PYTHON_DEFINE_STR_METHOD(join, 1)
BOOST_PYTHON_DEFINE_STR_METHOD(ljust, 1)
BOOST_PYTHON_DEFINE_STR_METHOD(lower, 0)
BOOST_PYTHON_DEFINE_STR_METHOD(lstrip, 0)
BOOST_PYTHON_DEFINE_STR_METHOD(replace, 2)
BOOST_PYTHON_DEFINE_STR_METHOD(replace, 3)
str str::ljust(object_cref width) const
{
return assume_str(this->attr("ljust")(width));
}
str str::lower() const
{
return assume_str(this->attr("lower")());
}
str str::lstrip() const
{
return assume_str(this->attr("lstrip")());
}
str str::replace(object_cref old, object_cref new_) const
{
return assume_str(this->attr("replace")(old,new_));
}
str str::replace(object_cref old, object_cref new_, object_cref maxsplit) const {
return assume_str(this->attr("replace")(old,new_,maxsplit));
}
long str::rfind(object_cref sub) const
long str_base::rfind(object_cref sub) const
{
long result = PyInt_AsLong(this->attr("rfind")(sub).ptr());
if (PyErr_Occurred())
@@ -252,7 +222,7 @@ long str::rfind(object_cref sub) const
return result;
}
long str::rfind(object_cref sub, object_cref start) const
long str_base::rfind(object_cref sub, object_cref start) const
{
long result = PyInt_AsLong(this->attr("rfind")(sub,start).ptr());
if (PyErr_Occurred())
@@ -260,7 +230,7 @@ long str::rfind(object_cref sub, object_cref start) const
return result;
}
long str::rfind(object_cref sub, object_cref start, object_cref end) const
long str_base::rfind(object_cref sub, object_cref start, object_cref end) const
{
long result = PyInt_AsLong(this->attr("rfind")(sub,start,end).ptr());
if (PyErr_Occurred())
@@ -268,7 +238,7 @@ long str::rfind(object_cref sub, object_cref start, object_cref end) const
return result;
}
long str::rindex(object_cref sub) const
long str_base::rindex(object_cref sub) const
{
long result = PyInt_AsLong(this->attr("rindex")(sub).ptr());
if (PyErr_Occurred())
@@ -276,7 +246,7 @@ long str::rindex(object_cref sub) const
return result;
}
long str::rindex(object_cref sub, object_cref start) const
long str_base::rindex(object_cref sub, object_cref start) const
{
long result = PyInt_AsLong(this->attr("rindex")(sub,start).ptr());
if (PyErr_Occurred())
@@ -284,7 +254,7 @@ long str::rindex(object_cref sub, object_cref start) const
return result;
}
long str::rindex(object_cref sub, object_cref start, object_cref end) const
long str_base::rindex(object_cref sub, object_cref start, object_cref end) const
{
long result = PyInt_AsLong(this->attr("rindex")(sub,start,end).ptr());
if (PyErr_Occurred())
@@ -292,42 +262,35 @@ long str::rindex(object_cref sub, object_cref start, object_cref end) const
return result;
}
str str::rjust(object_cref width) const
{
return assume_str(this->attr("rjust")(width));
}
BOOST_PYTHON_DEFINE_STR_METHOD(rjust, 1)
BOOST_PYTHON_DEFINE_STR_METHOD(rstrip, 0)
str str::rstrip() const
{
return assume_str(this->attr("rstrip")());
}
list str::split() const
list str_base::split() const
{
return list(this->attr("split")());
}
list str::split(object_cref sep) const
list str_base::split(object_cref sep) const
{
return list(this->attr("split")(sep));
}
list str::split(object_cref sep, object_cref maxsplit) const
list str_base::split(object_cref sep, object_cref maxsplit) const
{
return list(this->attr("split")(sep,maxsplit));
}
list str::splitlines() const
list str_base::splitlines() const
{
return list(this->attr("splitlines")());
}
list str::splitlines(object_cref keepends) const
list str_base::splitlines(object_cref keepends) const
{
return list(this->attr("splitlines")(keepends));
}
bool str::startswith(object_cref prefix) const
bool str_base::startswith(object_cref prefix) const
{
bool result = PyInt_AsLong(this->attr("startswith")(prefix).ptr());
if (PyErr_Occurred())
@@ -335,7 +298,7 @@ bool str::startswith(object_cref prefix) const
return result;
}
bool str::startswith(object_cref prefix, object_cref start) const
bool str_base::startswith(object_cref prefix, object_cref start) const
{
bool result = PyInt_AsLong(this->attr("startswith")(prefix,start).ptr());
if (PyErr_Occurred())
@@ -343,7 +306,7 @@ bool str::startswith(object_cref prefix, object_cref start) const
return result;
}
bool str::startswith(object_cref prefix, object_cref start, object_cref end) const
bool str_base::startswith(object_cref prefix, object_cref start, object_cref end) const
{
bool result = PyInt_AsLong(this->attr("startswith")(prefix,start,end).ptr());
if (PyErr_Occurred())
@@ -351,34 +314,11 @@ bool str::startswith(object_cref prefix, object_cref start, object_cref end) con
return result;
}
str str::strip() const
{
return assume_str(this->attr("strip")());
}
BOOST_PYTHON_DEFINE_STR_METHOD(strip, 0)
BOOST_PYTHON_DEFINE_STR_METHOD(swapcase, 0)
BOOST_PYTHON_DEFINE_STR_METHOD(title, 0)
BOOST_PYTHON_DEFINE_STR_METHOD(translate, 1)
BOOST_PYTHON_DEFINE_STR_METHOD(translate, 2)
BOOST_PYTHON_DEFINE_STR_METHOD(upper, 0)
str str::swapcase() const
{
return assume_str(this->attr("swapcase")());
}
str str::title() const
{
return assume_str(this->attr("title")());
}
str str::translate(object_cref table) const
{
return assume_str(this->attr("translate")(table));
}
str str::translate(object_cref table, object_cref deletechars) const
{
return assume_str(this->attr("translate")(table,deletechars));
}
str str::upper() const
{
return assume_str(this->attr("upper")());
}
}} // namespace boost::python
}}} // namespace boost::python

View File

@@ -1,20 +1,20 @@
#include <boost/python/tuple.hpp>
namespace boost { namespace python {
namespace boost { namespace python { namespace detail {
detail::new_reference tuple::call(object const& arg_)
detail::new_reference tuple_base::call(object const& arg_)
{
return (detail::new_reference)PyObject_CallFunction(
(PyObject*)&PyTuple_Type, "(O)",
arg_.ptr());
}
tuple::tuple()
tuple_base::tuple_base()
: object(detail::new_reference(PyTuple_New(0)))
{}
tuple::tuple(object_cref sequence)
: object(tuple::call(sequence))
tuple_base::tuple_base(object_cref sequence)
: object(call(sequence))
{}
}} // namespace boost::python
}}} // namespace boost::python

File diff suppressed because it is too large Load Diff