1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cpp/overload.cpp
3 // Purpose: C++ implementation for a function to match a function's
4 // argument list against a prototype
5 // Author: Mattia Barbon
8 // RCS-ID: $Id: overload.cpp 2192 2007-08-21 21:27:40Z mbarbon $
9 // Copyright: (c) 2002-2004, 2006-2007 Mattia Barbon
10 // Licence: This program is free software; you can redistribute it and/or
11 // modify it under the same terms as Perl itself
12 /////////////////////////////////////////////////////////////////////////////
14 #include "cpp/overload.h"
20 virtual ~wxPliArgArray() {};
22 virtual SV* operator[]( size_t index ) = 0;
23 virtual size_t GetCount() const = 0;
37 bool wxPli_match_arguments_offset( pTHX_ const wxPliPrototype& prototype,
39 bool allow_more, size_t offset );
41 bool wxPli_match_arguments_skipfirst( pTHX_ const wxPliPrototype& prototype,
42 int required /* = -1 */,
43 bool allow_more /* = false */ )
45 return wxPli_match_arguments_offset( aTHX_ prototype, required,
49 bool wxPli_match_arguments( pTHX_ const wxPliPrototype& prototype,
50 int required /* = -1 */,
51 bool allow_more /* = false */ )
53 return wxPli_match_arguments_offset( aTHX_ prototype, required,
57 static inline bool IsGV( SV* sv ) { return SvTYPE( sv ) == SVt_PVGV; }
59 bool wxPli_match_arguments_offset( pTHX_ const wxPliPrototype& prototype,
61 bool allow_more, size_t offset )
63 dXSARGS; // restore the mark we implicitly popped in dMARK!
64 int argc = items - int(offset);
68 if( allow_more && argc < required )
69 { PUSHMARK(MARK); return false; }
70 if( !allow_more && argc != required )
71 { PUSHMARK(MARK); return false; }
73 else if( argc < int(prototype.count) )
74 { PUSHMARK(MARK); return false; }
76 size_t max = wxMin( prototype.count, size_t(argc) ) + offset;
77 for( size_t i = offset; i < max; ++i )
79 unsigned char p = prototype.args[i - offset];
80 // everything is a string or a boolean
81 if( p == wxPliOvlstr ||
88 if( p == wxPliOvlnum )
90 if( my_looks_like_number( aTHX_ t ) ) continue;
91 else { PUSHMARK(MARK); return false; }
93 // want an object/package name, accept undef, too
95 p > wxPliOvlzzz ? prototype.tnames[p - wxPliOvlzzz] :
96 p == wxPliOvlwpos ? "Wx::Position" :
97 p == wxPliOvlwpoi ? "Wx::Point" :
98 p == wxPliOvlwsiz ? "Wx::Size" :
104 && sv_derived_from( t, CHAR_P cstr )
109 // want an array reference
110 if( p == wxPliOvlarr && wxPli_avref_2_av( t ) ) continue;
111 // want a wxPoint/wxSize, accept an array reference, too
112 if( ( p == wxPliOvlwpoi || p == wxPliOvlwsiz || p == wxPliOvlwpos )
113 && wxPli_avref_2_av( t ) ) continue;
114 // want an input/output stream, accept any reference
115 if( ( p == wxPliOvlwist || p == wxPliOvlwost ) &&
116 ( SvROK( t ) || IsGV( t ) ) ) continue;
118 // type clash: return false
127 void wxPli_set_ovl_constant( const char* name, const wxPliPrototype* value )
131 strcpy( buffer, "Wx::_" );
132 strcat( buffer, name );
134 SV* sv = get_sv( buffer, 1 );
135 sv_setiv( sv, PTR2IV( value ) );