PythonType.hxx

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 #ifndef __CXX_PythonType__h
00039 #define __CXX_PythonType__h
00040 
00041 namespace Py
00042 {
00043     class PYCXX_EXPORT PythonType
00044     {
00045     public:
00046         // if you define one sequence method you must define 
00047         // all of them except the assigns
00048 
00049         PythonType( size_t base_size, int itemsize, const char *default_name );
00050         virtual ~PythonType();
00051 
00052         const char *getName() const;
00053         const char *getDoc() const;
00054 
00055         PyTypeObject *type_object() const;
00056         PythonType &name( const char *nam );
00057         PythonType &doc( const char *d );
00058 
00059         PythonType &supportClass( void );
00060 #if !defined( PY3 )
00061         PythonType &dealloc( void (*f)( PyObject* ) );
00062 #endif
00063 #if defined( PYCXX_PYTHON_2TO3 ) || !defined( PY3 )
00064         PythonType &supportPrint( void );
00065 #endif
00066         PythonType &supportGetattr( void );
00067         PythonType &supportSetattr( void );
00068         PythonType &supportGetattro( void );
00069         PythonType &supportSetattro( void );
00070 #if defined( PYCXX_PYTHON_2TO3 ) || !defined( PY3 )
00071         PythonType &supportCompare( void );
00072 #endif
00073         PythonType &supportRichCompare( void );
00074         PythonType &supportRepr( void );
00075         PythonType &supportStr( void );
00076         PythonType &supportHash( void );
00077         PythonType &supportCall( void );
00078         PythonType &supportIter( void );
00079 
00080         PythonType &supportSequenceType( void );
00081         PythonType &supportMappingType( void );
00082         PythonType &supportNumberType( void );
00083         PythonType &supportBufferType( void );
00084 
00085         PythonType &set_tp_dealloc( void (*tp_dealloc)( PyObject * ) );
00086         PythonType &set_tp_init( int (*tp_init)( PyObject *self, PyObject *args, PyObject *kwds ) );
00087         PythonType &set_tp_new( PyObject *(*tp_new)( PyTypeObject *subtype, PyObject *args, PyObject *kwds ) );
00088         PythonType &set_methods( PyMethodDef *methods );
00089 
00090         // call once all support functions have been called to ready the type
00091         bool readyType();
00092 
00093     protected:
00094         void init_sequence();
00095         void init_mapping();
00096         void init_number();
00097         void init_buffer();
00098 
00099         PyTypeObject            *table;
00100         PySequenceMethods       *sequence_table;
00101         PyMappingMethods        *mapping_table;
00102         PyNumberMethods         *number_table;
00103         PyBufferProcs           *buffer_table;
00104 
00105     private:
00106         //
00107         // prevent the compiler generating these unwanted functions
00108         //
00109         PythonType( const PythonType &tb );     // unimplemented
00110         void operator=( const PythonType &t );  // unimplemented
00111 
00112     };
00113 
00114 } // Namespace Py
00115 
00116 // End of __CXX_PythonType__h
00117 #endif

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