cxxsupport.cpp
1//---------------------------------------------------------------------------//
2// Copyright 1998 The Regents of the University of California.
3// All rights reserved. See Legal.htm for full text and disclaimer.
4//---------------------------------------------------------------------------//
5
6#include "Objects.h"
7namespace Py {
8
9Py_UNICODE unicode_null_string[1] = { 0 };
10
11Type Object::type () const
12 {
13 return Type (PyObject_Type (p), true);
14 }
15
16String Object::str () const
17 {
18 return String (PyObject_Str (p), true);
19 }
20
21String Object::repr () const
22 {
23 return String (PyObject_Repr (p), true);
24 }
25
26std::string Object::as_string() const
27 {
28 return static_cast<std::string>(str());
29 }
30
31List Object::dir () const
32 {
33 return List (PyObject_Dir (p), true);
34 }
35
36bool Object::isType (const Type& t) const
37 {
38 return type ().ptr() == t.ptr();
39 }
40
41Char::operator String() const
42 {
43 return String(ptr());
44 }
45
46// TMM: non-member operaters for iterators - see above
47// I've also made a bug fix in respect to the cxx code
48// (dereffed the left.seq and right.seq comparison)
49bool operator==(const Sequence::iterator& left, const Sequence::iterator& right)
50 {
51 return left.eql( right );
52 }
53
54bool operator!=(const Sequence::iterator& left, const Sequence::iterator& right)
55 {
56 return left.neq( right );
57 }
58
59bool operator< (const Sequence::iterator& left, const Sequence::iterator& right)
60 {
61 return left.lss( right );
62 }
63
64bool operator> (const Sequence::iterator& left, const Sequence::iterator& right)
65 {
66 return left.gtr( right );
67 }
68
69bool operator<=(const Sequence::iterator& left, const Sequence::iterator& right)
70 {
71 return left.leq( right );
72 }
73
74bool operator>=(const Sequence::iterator& left, const Sequence::iterator& right)
75 {
76 return left.geq( right );
77 }
78
79// now for const_iterator
80bool operator==(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
81 {
82 return left.eql( right );
83 }
84
85bool operator!=(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
86 {
87 return left.neq( right );
88 }
89
90bool operator< (const Sequence::const_iterator& left, const Sequence::const_iterator& right)
91 {
92 return left.lss( right );
93 }
94
95bool operator> (const Sequence::const_iterator& left, const Sequence::const_iterator& right)
96 {
97 return left.gtr( right );
98 }
99
100bool operator<=(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
101 {
102 return left.leq( right );
103 }
104
105bool operator>=(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
106 {
107 return left.geq( right );
108 }
109
110// For mappings:
111bool operator==(const Mapping::iterator& left, const Mapping::iterator& right)
112 {
113 return left.eql( right );
114 }
115
116bool operator!=(const Mapping::iterator& left, const Mapping::iterator& right)
117 {
118 return left.neq( right );
119 }
120
121// now for const_iterator
122bool operator==(const Mapping::const_iterator& left, const Mapping::const_iterator& right)
123 {
124 return left.eql( right );
125 }
126
127bool operator!=(const Mapping::const_iterator& left, const Mapping::const_iterator& right)
128 {
129 return left.neq( right );
130 }
131
132// TMM: 31May'01 - Added the #ifndef so I can exclude iostreams.
133#ifndef CXX_NO_IOSTREAMS
134// output
135
136std::ostream& operator<< (std::ostream& os, const Object& ob)
137 {
138 return (os << static_cast<std::string>(ob.str()));
139 }
140#endif
141
142} // Py
@ String
string
Definition property.h:71
@ List
TQValueList<TQVariant>
Definition property.h:70