From: <md...@us...> - 2009-02-23 17:38:38
|
Revision: 6928 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6928&view=rev Author: mdboom Date: 2009-02-23 17:38:35 +0000 (Mon, 23 Feb 2009) Log Message: ----------- C++ standards compliance for use with Sun C++ compiler. These should be equivalent to what was there before on gcc. Modified Paths: -------------- branches/v0_98_5_maint/CXX/Extensions.hxx branches/v0_98_5_maint/agg24/include/agg_alpha_mask_u8.h Modified: branches/v0_98_5_maint/CXX/Extensions.hxx =================================================================== --- branches/v0_98_5_maint/CXX/Extensions.hxx 2009-02-23 17:30:07 UTC (rev 6927) +++ branches/v0_98_5_maint/CXX/Extensions.hxx 2009-02-23 17:38:35 UTC (rev 6928) @@ -61,7 +61,7 @@ namespace Py { class ExtensionModuleBase; - + // Make an Exception Type for use in raising custom exceptions class ExtensionExceptionType : public Object { @@ -74,44 +74,44 @@ void init( ExtensionModuleBase &module, const std::string& name ); }; - - class MethodTable + + class MethodTable { public: MethodTable(); virtual ~MethodTable(); - + void add(const char* method_name, PyCFunction f, const char* doc="", int flag=1); PyMethodDef* table(); - + protected: std::vector<PyMethodDef> t; // accumulator of PyMethodDef's PyMethodDef *mt; // Actual method table produced when full - + static PyMethodDef method (const char* method_name, PyCFunction f, int flags = 1, const char* doc=""); - + private: // // prevent the compiler generating these unwanted functions // MethodTable(const MethodTable& m); //unimplemented void operator=(const MethodTable& m); //unimplemented - + }; // end class MethodTable - + extern "C" { typedef PyObject *(*method_varargs_call_handler_t)( PyObject *_self, PyObject *_args ); typedef PyObject *(*method_keyword_call_handler_t)( PyObject *_self, PyObject *_args, PyObject *_dict ); - }; - + } + template<class T> class MethodDefExt : public PyMethodDef { public: typedef Object (T::*method_varargs_function_t)( const Tuple &args ); typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws ); - + MethodDefExt ( const char *_name, @@ -124,11 +124,11 @@ ext_meth_def.ml_meth = _handler; ext_meth_def.ml_flags = METH_VARARGS; ext_meth_def.ml_doc = const_cast<char *>(_doc); - + ext_varargs_function = _function; ext_keyword_function = NULL; } - + MethodDefExt ( const char *_name, @@ -141,57 +141,57 @@ ext_meth_def.ml_meth = method_varargs_call_handler_t( _handler ); ext_meth_def.ml_flags = METH_VARARGS|METH_KEYWORDS; ext_meth_def.ml_doc = const_cast<char *>(_doc); - + ext_varargs_function = NULL; ext_keyword_function = _function; } - + ~MethodDefExt() {} - + PyMethodDef ext_meth_def; - method_varargs_function_t ext_varargs_function; - method_keyword_function_t ext_keyword_function; + method_varargs_function_t ext_varargs_function; + method_keyword_function_t ext_keyword_function; }; - + class ExtensionModuleBase { public: ExtensionModuleBase( const char *name ); virtual ~ExtensionModuleBase(); - + Module module(void) const; // only valid after initialize() has been called Dict moduleDictionary(void) const; // only valid after initialize() has been called - + virtual Object invoke_method_keyword( const std::string &_name, const Tuple &_args, const Dict &_keywords ) = 0; virtual Object invoke_method_varargs( const std::string &_name, const Tuple &_args ) = 0; - + const std::string &name() const; const std::string &fullName() const; - + protected: // Initialize the module void initialize( const char *module_doc ); - + const std::string module_name; const std::string full_module_name; MethodTable method_table; - + private: - + // // prevent the compiler generating these unwanted functions // ExtensionModuleBase( const ExtensionModuleBase & ); //unimplemented void operator=( const ExtensionModuleBase & ); //unimplemented - + }; - + extern "C" PyObject *method_keyword_call_handler( PyObject *_self_and_name_tuple, PyObject *_args, PyObject *_keywords ); extern "C" PyObject *method_varargs_call_handler( PyObject *_self_and_name_tuple, PyObject *_args ); extern "C" void do_not_dealloc( void * ); - - + + template<TEMPLATE_TYPENAME T> class ExtensionModule : public ExtensionModuleBase { @@ -201,16 +201,16 @@ {} virtual ~ExtensionModule() {} - + protected: typedef Object (T::*method_varargs_function_t)( const Tuple &args ); typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws ); typedef std::map<std::string,MethodDefExt<T> *> method_map_t; - + static void add_varargs_method( const char *name, method_varargs_function_t function, const char *doc="" ) { method_map_t &mm = methods(); - + MethodDefExt<T> *method_definition = new MethodDefExt<T> ( name, @@ -218,14 +218,14 @@ method_varargs_call_handler, doc ); - + mm[std::string( name )] = method_definition; } - + static void add_keyword_method( const char *name, method_keyword_function_t function, const char *doc="" ) { method_map_t &mm = methods(); - + MethodDefExt<T> *method_definition = new MethodDefExt<T> ( name, @@ -233,7 +233,7 @@ method_keyword_call_handler, doc ); - + mm[std::string( name )] = method_definition; } @@ -241,46 +241,46 @@ { ExtensionModuleBase::initialize( module_doc ); Dict dict( moduleDictionary() ); - + // // put each of the methods into the modules dictionary // so that we get called back at the function in T. // method_map_t &mm = methods(); EXPLICIT_TYPENAME method_map_t::iterator i; - + for( i=mm.begin(); i != mm.end(); ++i ) { MethodDefExt<T> *method_definition = (*i).second; - + static PyObject *self = PyCObject_FromVoidPtr( this, do_not_dealloc ); - + Tuple args( 2 ); args[0] = Object( self ); args[1] = String( (*i).first ); - + PyObject *func = PyCFunction_New ( &method_definition->ext_meth_def, new_reference_to( args ) ); - + dict[ (*i).first ] = Object( func ); } } - + protected: // Tom Malcolmson reports that derived classes need access to these - + static method_map_t &methods(void) { static method_map_t *map_of_methods = NULL; if( map_of_methods == NULL ) map_of_methods = new method_map_t; - + return *map_of_methods; } - - + + // this invoke function must be called from within a try catch block virtual Object invoke_method_keyword( const std::string &name, const Tuple &args, const Dict &keywords ) { @@ -292,13 +292,13 @@ error_msg += name; throw RuntimeError( error_msg ); } - + // cast up to the derived class T *self = static_cast<T *>(this); - + return (self->*meth_def->ext_keyword_function)( args, keywords ); } - + // this invoke function must be called from within a try catch block virtual Object invoke_method_varargs( const std::string &name, const Tuple &args ) { @@ -310,13 +310,13 @@ error_msg += name; throw RuntimeError( error_msg ); } - + // cast up to the derived class T *self = static_cast<T *>(this); - + return (self->*meth_def->ext_varargs_function)( args ); } - + private: // // prevent the compiler generating these unwanted functions @@ -324,17 +324,17 @@ ExtensionModule( const ExtensionModule<T> & ); //unimplemented void operator=( const ExtensionModule<T> & ); //unimplemented }; - - + + class PythonType { public: - // if you define one sequence method you must define + // if you define one sequence method you must define // all of them except the assigns - + PythonType (size_t base_size, int itemsize, const char *default_name ); virtual ~PythonType (); - + const char *getName () const; const char *getDoc () const; @@ -342,7 +342,7 @@ PythonType & name (const char* nam); PythonType & doc (const char* d); PythonType & dealloc(void (*f)(PyObject*)); - + PythonType & supportPrint(void); PythonType & supportGetattr(void); PythonType & supportSetattr(void); @@ -354,61 +354,61 @@ PythonType & supportHash(void); PythonType & supportCall(void); PythonType & supportIter(void); - + PythonType & supportSequenceType(void); PythonType & supportMappingType(void); PythonType & supportNumberType(void); PythonType & supportBufferType(void); - + protected: PyTypeObject *table; PySequenceMethods *sequence_table; PyMappingMethods *mapping_table; PyNumberMethods *number_table; PyBufferProcs *buffer_table; - + void init_sequence(); void init_mapping(); void init_number(); void init_buffer(); - + private: // // prevent the compiler generating these unwanted functions // PythonType (const PythonType& tb); // unimplemented void operator=(const PythonType& t); // unimplemented - + }; // end of PythonType - - - + + + // Class PythonExtension is what you inherit from to create // a new Python extension type. You give your class itself // as the template paramter. - + // There are two ways that extension objects can get destroyed. // 1. Their reference count goes to zero // 2. Someone does an explicit delete on a pointer. - // In (1) the problem is to get the destructor called + // In (1) the problem is to get the destructor called // We register a special deallocator in the Python type object // (see behaviors()) to do this. // In (2) there is no problem, the dtor gets called. - - // PythonExtension does not use the usual Python heap allocator, + + // PythonExtension does not use the usual Python heap allocator, // instead using new/delete. We do the setting of the type object - // and reference count, usually done by PyObject_New, in the + // and reference count, usually done by PyObject_New, in the // base class ctor. - + // This special deallocator does a delete on the pointer. - - + + class PythonExtensionBase : public PyObject { public: PythonExtensionBase(); virtual ~PythonExtensionBase(); - + public: virtual int print( FILE *, int ); virtual Object getattr( const char * ) = 0; @@ -422,7 +422,7 @@ virtual Object call( const Object &, const Object & ); virtual Object iter(); virtual PyObject* iternext(); - + // Sequence methods virtual int sequence_length(); virtual Object sequence_concat( const Object & ); @@ -431,12 +431,12 @@ virtual Object sequence_slice( Py_ssize_t, Py_ssize_t ); virtual int sequence_ass_item( Py_ssize_t, const Object & ); virtual int sequence_ass_slice( Py_ssize_t, Py_ssize_t, const Object & ); - + // Mapping virtual int mapping_length(); virtual Object mapping_subscript( const Object & ); virtual int mapping_ass_subscript( const Object &, const Object & ); - + // Number virtual int number_nonzero(); virtual Object number_negative(); @@ -460,38 +460,38 @@ virtual Object number_xor( const Object & ); virtual Object number_or( const Object & ); virtual Object number_power( const Object &, const Object & ); - + // Buffer virtual Py_ssize_t buffer_getreadbuffer( Py_ssize_t, void** ); virtual Py_ssize_t buffer_getwritebuffer( Py_ssize_t, void** ); virtual Py_ssize_t buffer_getsegcount( Py_ssize_t* ); - + private: void missing_method( void ); static PyObject *method_call_handler( PyObject *self, PyObject *args ); }; - + template<TEMPLATE_TYPENAME T> - class PythonExtension: public PythonExtensionBase + class PythonExtension: public PythonExtensionBase { public: - static PyTypeObject* type_object() + static PyTypeObject* type_object() { return behaviors().type_object(); } - + static int check( PyObject *p ) { // is p like me? return p->ob_type == type_object(); } - + static int check( const Object& ob ) { return check( ob.ptr()); } - - + + // // every object needs getattr implemented // to support methods @@ -500,7 +500,7 @@ { return getattr_methods( name ); } - + protected: explicit PythonExtension() : PythonExtensionBase() @@ -511,18 +511,18 @@ ob_refcnt = 1; ob_type = type_object(); #endif - + // every object must support getattr behaviors().supportGetattr(); } - + virtual ~PythonExtension() - {} - + {} + static PythonType &behaviors() { static PythonType* p; - if( p == NULL ) + if( p == NULL ) { #if defined( _CPPRTTI ) || defined(__GNUG__) const char *default_name = (typeid ( T )).name(); @@ -532,15 +532,15 @@ p = new PythonType( sizeof( T ), 0, default_name ); p->dealloc( extension_object_deallocator ); } - + return *p; } - - + + typedef Object (T::*method_varargs_function_t)( const Tuple &args ); typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws ); typedef std::map<std::string,MethodDefExt<T> *> method_map_t; - + // support the default attributes, __name__, __doc__ and methods virtual Object getattr_default( const char *_name ) { @@ -576,39 +576,39 @@ virtual Object getattr_methods( const char *_name ) { std::string name( _name ); - + method_map_t &mm = methods(); - + if( name == "__methods__" ) { List methods; - + for( EXPLICIT_TYPENAME method_map_t::iterator i = mm.begin(); i != mm.end(); ++i ) methods.append( String( (*i).first ) ); - + return methods; } - + // see if name exists if( mm.find( name ) == mm.end() ) throw AttributeError( name ); - + Tuple self( 2 ); - + self[0] = Object( this ); self[1] = String( name ); - + MethodDefExt<T> *method_definition = mm[ name ]; - + PyObject *func = PyCFunction_New( &method_definition->ext_meth_def, self.ptr() ); - + return Object(func, true); } - + static void add_varargs_method( const char *name, method_varargs_function_t function, const char *doc="" ) { method_map_t &mm = methods(); - + MethodDefExt<T> *method_definition = new MethodDefExt<T> ( name, @@ -616,14 +616,14 @@ method_varargs_call_handler, doc ); - + mm[std::string( name )] = method_definition; } - + static void add_keyword_method( const char *name, method_keyword_function_t function, const char *doc="" ) { method_map_t &mm = methods(); - + MethodDefExt<T> *method_definition = new MethodDefExt<T> ( name, @@ -631,45 +631,45 @@ method_keyword_call_handler, doc ); - + mm[std::string( name )] = method_definition; } - + private: static method_map_t &methods(void) { static method_map_t *map_of_methods = NULL; if( map_of_methods == NULL ) map_of_methods = new method_map_t; - + return *map_of_methods; } - + static PyObject *method_keyword_call_handler( PyObject *_self_and_name_tuple, PyObject *_args, PyObject *_keywords ) { try { Tuple self_and_name_tuple( _self_and_name_tuple ); - + PyObject *self_in_cobject = self_and_name_tuple[0].ptr(); T *self = static_cast<T *>( self_in_cobject ); - + String name( self_and_name_tuple[1] ); - + method_map_t &mm = methods(); MethodDefExt<T> *meth_def = mm[ name ]; if( meth_def == NULL ) return 0; - + Tuple args( _args ); // _keywords may be NULL so be careful about the way the dict is created Dict keywords; if( _keywords != NULL ) keywords = Dict( _keywords ); - + Object result( (self->*meth_def->ext_keyword_function)( args, keywords ) ); - + return new_reference_to( result.ptr() ); } catch( Exception & ) @@ -677,27 +677,27 @@ return 0; } } - + static PyObject *method_varargs_call_handler( PyObject *_self_and_name_tuple, PyObject *_args ) { try { Tuple self_and_name_tuple( _self_and_name_tuple ); - + PyObject *self_in_cobject = self_and_name_tuple[0].ptr(); T *self = static_cast<T *>( self_in_cobject ); - + String name( self_and_name_tuple[1] ); - + method_map_t &mm = methods(); MethodDefExt<T> *meth_def = mm[ name ]; if( meth_def == NULL ) return 0; - + Tuple args( _args ); - + Object result; - + // TMM: 7Jun'01 - Adding try & catch in case of STL debug-mode exceptions. #ifdef _STLP_DEBUG try @@ -712,7 +712,7 @@ #else result = (self->*meth_def->ext_varargs_function)( args ); #endif // _STLP_DEBUG - + return new_reference_to( result.ptr() ); } catch( Exception & ) @@ -720,19 +720,19 @@ return 0; } } - + static void extension_object_deallocator ( PyObject* t ) { delete (T *)( t ); } - + // // prevent the compiler generating these unwanted functions // explicit PythonExtension( const PythonExtension<T>& other ); void operator=( const PythonExtension<T>& rhs ); }; - + // // ExtensionObject<T> is an Object that will accept only T's. // @@ -740,30 +740,30 @@ class ExtensionObject: public Object { public: - + explicit ExtensionObject ( PyObject *pyob ) : Object( pyob ) { validate(); } - + ExtensionObject( const ExtensionObject<T>& other ) : Object( *other ) { validate(); } - + ExtensionObject( const Object& other ) : Object( *other ) { validate(); } - + ExtensionObject& operator= ( const Object& rhs ) { return (*this = *rhs ); } - + ExtensionObject& operator= ( PyObject* rhsp ) { if( ptr() == rhsp ) @@ -771,12 +771,12 @@ set( rhsp ); return *this; } - + virtual bool accepts ( PyObject *pyob ) const { return ( pyob && T::check( pyob )); - } - + } + // // Obtain a pointer to the PythonExtension object // @@ -785,7 +785,7 @@ return static_cast<T *>( ptr() ); } }; - + } // Namespace Py // End of CXX_Extensions.h #endif Modified: branches/v0_98_5_maint/agg24/include/agg_alpha_mask_u8.h =================================================================== --- branches/v0_98_5_maint/agg24/include/agg_alpha_mask_u8.h 2009-02-23 17:30:07 UTC (rev 6927) +++ branches/v0_98_5_maint/agg24/include/agg_alpha_mask_u8.h 2009-02-23 17:38:35 UTC (rev 6928) @@ -2,8 +2,8 @@ // Anti-Grain Geometry - Version 2.4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) // -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // @@ -30,15 +30,15 @@ { static unsigned calculate(const int8u* p) { return *p; } }; - + //=====================================================rgb_to_gray_mask_u8 template<unsigned R, unsigned G, unsigned B> struct rgb_to_gray_mask_u8 { - static unsigned calculate(const int8u* p) - { - return (p[R]*77 + p[G]*150 + p[B]*29) >> 8; + static unsigned calculate(const int8u* p) + { + return (p[R]*77 + p[G]*150 + p[B]*29) >> 8; } }; @@ -50,7 +50,7 @@ typedef int8u cover_type; typedef alpha_mask_u8<Step, Offset, MaskF> self_type; enum cover_scale_e - { + { cover_shift = 8, cover_none = 0, cover_full = 255 @@ -64,12 +64,12 @@ MaskF& mask_function() { return m_mask_function; } const MaskF& mask_function() const { return m_mask_function; } - + //-------------------------------------------------------------------- cover_type pixel(int x, int y) const { - if(x >= 0 && y >= 0 && - x < (int)m_rbuf->width() && + if(x >= 0 && y >= 0 && + x < (int)m_rbuf->width() && y < (int)m_rbuf->height()) { return (cover_type)m_mask_function.calculate( @@ -81,13 +81,13 @@ //-------------------------------------------------------------------- cover_type combine_pixel(int x, int y, cover_type val) const { - if(x >= 0 && y >= 0 && - x < (int)m_rbuf->width() && + if(x >= 0 && y >= 0 && + x < (int)m_rbuf->width() && y < (int)m_rbuf->height()) { - return (cover_type)((cover_full + val * + return (cover_type)((cover_full + val * m_mask_function.calculate( - m_rbuf->row_ptr(y) + x * Step + Offset)) >> + m_rbuf->row_ptr(y) + x * Step + Offset)) >> cover_shift); } return 0; @@ -112,7 +112,7 @@ if(x < 0) { count += x; - if(count <= 0) + if(count <= 0) { memset(dst, 0, num_pix * sizeof(cover_type)); return; @@ -126,7 +126,7 @@ { int rest = x + count - xmax - 1; count -= rest; - if(count <= 0) + if(count <= 0) { memset(dst, 0, num_pix * sizeof(cover_type)); return; @@ -162,7 +162,7 @@ if(x < 0) { count += x; - if(count <= 0) + if(count <= 0) { memset(dst, 0, num_pix * sizeof(cover_type)); return; @@ -176,7 +176,7 @@ { int rest = x + count - xmax - 1; count -= rest; - if(count <= 0) + if(count <= 0) { memset(dst, 0, num_pix * sizeof(cover_type)); return; @@ -187,8 +187,8 @@ const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset; do { - *covers = (cover_type)((cover_full + (*covers) * - m_mask_function.calculate(mask)) >> + *covers = (cover_type)((cover_full + (*covers) * + m_mask_function.calculate(mask)) >> cover_shift); ++covers; mask += Step; @@ -214,7 +214,7 @@ if(y < 0) { count += y; - if(count <= 0) + if(count <= 0) { memset(dst, 0, num_pix * sizeof(cover_type)); return; @@ -228,7 +228,7 @@ { int rest = y + count - ymax - 1; count -= rest; - if(count <= 0) + if(count <= 0) { memset(dst, 0, num_pix * sizeof(cover_type)); return; @@ -263,7 +263,7 @@ if(y < 0) { count += y; - if(count <= 0) + if(count <= 0) { memset(dst, 0, num_pix * sizeof(cover_type)); return; @@ -277,7 +277,7 @@ { int rest = y + count - ymax - 1; count -= rest; - if(count <= 0) + if(count <= 0) { memset(dst, 0, num_pix * sizeof(cover_type)); return; @@ -288,8 +288,8 @@ const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset; do { - *covers = (cover_type)((cover_full + (*covers) * - m_mask_function.calculate(mask)) >> + *covers = (cover_type)((cover_full + (*covers) * + m_mask_function.calculate(mask)) >> cover_shift); ++covers; mask += m_rbuf->stride(); @@ -302,11 +302,11 @@ alpha_mask_u8(const self_type&); const self_type& operator = (const self_type&); - rendering_buffer* m_rbuf; + agg::rendering_buffer* m_rbuf; MaskF m_mask_function; }; - + typedef alpha_mask_u8<1, 0> alpha_mask_gray8; //----alpha_mask_gray8 typedef alpha_mask_u8<3, 0> alpha_mask_rgb24r; //----alpha_mask_rgb24r @@ -354,7 +354,7 @@ typedef int8u cover_type; typedef amask_no_clip_u8<Step, Offset, MaskF> self_type; enum cover_scale_e - { + { cover_shift = 8, cover_none = 0, cover_full = 255 @@ -376,13 +376,13 @@ m_rbuf->row_ptr(y) + x * Step + Offset); } - + //-------------------------------------------------------------------- cover_type combine_pixel(int x, int y, cover_type val) const { - return (cover_type)((cover_full + val * + return (cover_type)((cover_full + val * m_mask_function.calculate( - m_rbuf->row_ptr(y) + x * Step + Offset)) >> + m_rbuf->row_ptr(y) + x * Step + Offset)) >> cover_shift); } @@ -407,8 +407,8 @@ const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset; do { - *dst = (cover_type)((cover_full + (*dst) * - m_mask_function.calculate(mask)) >> + *dst = (cover_type)((cover_full + (*dst) * + m_mask_function.calculate(mask)) >> cover_shift); ++dst; mask += Step; @@ -436,8 +436,8 @@ const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset; do { - *dst = (cover_type)((cover_full + (*dst) * - m_mask_function.calculate(mask)) >> + *dst = (cover_type)((cover_full + (*dst) * + m_mask_function.calculate(mask)) >> cover_shift); ++dst; mask += m_rbuf->stride(); @@ -449,11 +449,11 @@ amask_no_clip_u8(const self_type&); const self_type& operator = (const self_type&); - rendering_buffer* m_rbuf; + agg::rendering_buffer* m_rbuf; MaskF m_mask_function; }; - + typedef amask_no_clip_u8<1, 0> amask_no_clip_gray8; //----amask_no_clip_gray8 typedef amask_no_clip_u8<3, 0> amask_no_clip_rgb24r; //----amask_no_clip_rgb24r This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |