Python2/cxxsupport.cxx

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //
00003 // Copyright (c) 1998 - 2007, The Regents of the University of California
00004 // Produced at the Lawrence Livermore National Laboratory
00005 // All rights reserved.
00006 //
00007 // This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The
00008 // full copyright notice is contained in the file COPYRIGHT located at the root
00009 // of the PyCXX distribution.
00010 //
00011 // Redistribution  and  use  in  source  and  binary  forms,  with  or  without
00012 // modification, are permitted provided that the following conditions are met:
00013 //
00014 //  - Redistributions of  source code must  retain the above  copyright notice,
00015 //    this list of conditions and the disclaimer below.
00016 //  - Redistributions in binary form must reproduce the above copyright notice,
00017 //    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
00018 //    documentation and/or materials provided with the distribution.
00019 //  - Neither the name of the UC/LLNL nor  the names of its contributors may be
00020 //    used to  endorse or  promote products derived from  this software without
00021 //    specific prior written permission.
00022 //
00023 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
00024 // AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
00025 // IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
00026 // ARE  DISCLAIMED.  IN  NO  EVENT  SHALL  THE  REGENTS  OF  THE  UNIVERSITY OF
00027 // CALIFORNIA, THE U.S.  DEPARTMENT  OF  ENERGY OR CONTRIBUTORS BE  LIABLE  FOR
00028 // ANY  DIRECT,  INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR CONSEQUENTIAL
00029 // DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
00030 // SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
00031 // CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
00032 // LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
00033 // OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00034 // DAMAGE.
00035 //
00036 //-----------------------------------------------------------------------------
00037 
00038 #include "CXX/Objects.hxx"
00039 namespace Py {
00040 
00041 Py_UNICODE unicode_null_string[1] = { 0 };
00042 
00043 Type Object::type () const
00044 { 
00045     return Type (PyObject_Type (p), true);
00046 }
00047 
00048 String Object::str () const
00049 {
00050     return String (PyObject_Str (p), true);
00051 }
00052 
00053 String Object::repr () const
00054 { 
00055     return String (PyObject_Repr (p), true);
00056 }
00057 
00058 std::string Object::as_string() const
00059 {
00060     return static_cast<std::string>(str());
00061 }
00062 
00063 List Object::dir () const
00064         {
00065         return List (PyObject_Dir (p), true);
00066         }
00067 
00068 bool Object::isType (const Type& t) const
00069 { 
00070     return type ().ptr() == t.ptr();
00071 }
00072 
00073 Char::operator String() const
00074 {
00075     return String(ptr());
00076 }
00077 
00078 // TMM: non-member operaters for iterators - see above
00079 // I've also made a bug fix in respect to the cxx code
00080 // (dereffed the left.seq and right.seq comparison)
00081 bool operator==(const Sequence::iterator& left, const Sequence::iterator& right)
00082 {
00083     return left.eql( right );
00084 }
00085 
00086 bool operator!=(const Sequence::iterator& left, const Sequence::iterator& right)
00087 {
00088     return left.neq( right );
00089 }
00090 
00091 bool operator< (const Sequence::iterator& left, const Sequence::iterator& right)
00092 {
00093     return left.lss( right );
00094 }
00095 
00096 bool operator> (const Sequence::iterator& left, const Sequence::iterator& right)
00097 {
00098     return left.gtr( right );
00099 }
00100 
00101 bool operator<=(const Sequence::iterator& left, const Sequence::iterator& right)
00102 {
00103     return left.leq( right );
00104 }
00105 
00106 bool operator>=(const Sequence::iterator& left, const Sequence::iterator& right)
00107 {
00108     return left.geq( right );
00109 }
00110 
00111 // now for const_iterator
00112 bool operator==(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
00113 {
00114     return left.eql( right );
00115 }
00116 
00117 bool operator!=(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
00118 {
00119     return left.neq( right );
00120 }
00121 
00122 bool operator< (const Sequence::const_iterator& left, const Sequence::const_iterator& right)
00123 {
00124     return left.lss( right );
00125 }
00126 
00127 bool operator> (const Sequence::const_iterator& left, const Sequence::const_iterator& right)
00128 {
00129     return left.gtr( right );
00130 }
00131 
00132 bool operator<=(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
00133 {
00134     return left.leq( right );
00135 }
00136 
00137 bool operator>=(const Sequence::const_iterator& left, const Sequence::const_iterator& right)
00138 {
00139     return left.geq( right );
00140 }
00141 
00142 // For mappings:
00143 bool operator==(const Mapping::iterator& left, const Mapping::iterator& right)
00144 {
00145     return left.eql( right );
00146 }
00147 
00148 bool operator!=(const Mapping::iterator& left, const Mapping::iterator& right)
00149 {
00150     return left.neq( right );
00151 }
00152 
00153 // now for const_iterator
00154 bool operator==(const Mapping::const_iterator& left, const Mapping::const_iterator& right)
00155 {
00156     return left.eql( right );
00157 }
00158 
00159 bool operator!=(const Mapping::const_iterator& left, const Mapping::const_iterator& right)
00160 {
00161     return left.neq( right );
00162 }
00163 
00164 // TMM: 31May'01 - Added the #ifndef so I can exclude iostreams.
00165 #ifndef CXX_NO_IOSTREAMS
00166 // output
00167 
00168 std::ostream& operator<< (std::ostream& os, const Object& ob)
00169 {
00170     return (os << static_cast<std::string>(ob.str()));
00171 }  
00172 #endif
00173 
00174 } // Py

Generated on Wed Nov 23 19:00:05 2011 for FreeCAD by  doxygen 1.6.1