Annotation of parser3/src/types/pa_method.h, revision 1.8

1.2       paf         1: /** @file
                      2:        Parser: Method class decl.
                      3: 
1.6       paf         4:        Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
1.2       paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
                      6: */
                      7: 
                      8: #ifndef PA_METHOD_H
                      9: #define PA_METHOD_H
                     10: 
1.8     ! misha      11: static const char * const IDENT_METHOD_H="$Date: 2006/12/20 09:39:39 $";
1.2       paf        12: 
                     13: 
                     14: /*#include "pa_string.h"
                     15: #include "pa_array.h"
                     16: #include "pa_exception.h"
                     17: */
                     18: #include "pa_operation.h"
                     19: 
                     20: /**
                     21:        native code method
                     22:        params can be NULL when 
                     23:        method min&max params (see VStateless_class::add_native_method)
                     24:        counts are zero.        
                     25: */
                     26: typedef void (*NativeCodePtr)(Request& request, MethodParams& params);
                     27: 
                     28: 
                     29: /** 
                     30:        class method.
                     31: 
                     32:        methods can have 
                     33:        - named or
                     34:        - numbered parameters
                     35: 
                     36:        methods can be
                     37:        - parser or 
                     38:        - native onces
                     39: 
                     40:        holds
                     41:        - parameter names or number limits
                     42:        - local names
                     43:        - code [parser or native]
                     44: */
                     45: class Method: public PA_Object {
                     46: public:
                     47: 
                     48:        /// allowed method call types
                     49:        enum Call_type {
                     50:                CT_ANY, ///< method can be called either statically or dynamically
                     51:                CT_STATIC, ///< method can be called only statically
                     52:                CT_DYNAMIC ///< method can be called only dynamically
                     53:        };
                     54:        
                     55:        /// name for error reporting
                     56:        //const String& name;
                     57:        ///
                     58:        Call_type call_type;
                     59:        //@{
                     60:        /// @name either numbered params // for native-code methods = operators
                     61:        int min_numbered_params_count, max_numbered_params_count;
                     62:        //@}
                     63:        //@{
                     64:        /// @name or named params&locals // for parser-code methods
                     65:        ArrayString* params_names;  ArrayString* locals_names;
                     66:        //@}
                     67:        //@{
                     68:        /// @name the Code
                     69:        ArrayOperation* parser_code;/*OR*/NativeCodePtr native_code;
                     70:        //@}
1.8     ! misha      71:        bool all_vars_local;
1.2       paf        72: 
1.7       misha      73:        Method(
1.2       paf        74:                //const String& aname,
                     75:                Call_type call_type,
                     76:                int amin_numbered_params_count, int amax_numbered_params_count,
                     77:                ArrayString* aparams_names, ArrayString* alocals_names,
1.8     ! misha      78:                ArrayOperation* aparser_code, NativeCodePtr anative_code,
        !            79:                bool aall_vars_local=false) : 
1.2       paf        80: 
                     81:                //name(aname),
                     82:                call_type(call_type),
                     83:                min_numbered_params_count(amin_numbered_params_count),
                     84:                max_numbered_params_count(amax_numbered_params_count),
                     85:                params_names(aparams_names), locals_names(alocals_names),
1.8     ! misha      86:                parser_code(aparser_code), native_code(anative_code),
        !            87:                all_vars_local(aall_vars_local) {
1.2       paf        88:        }
                     89: 
                     90:        /// call this before invoking to ensure proper actual numbered params count
                     91:        void check_actual_numbered_params(
                     92:                Value& self, /*const String& actual_name, */MethodParams* actual_numbered_params) const;
                     93: };
                     94: 
                     95: ///    Auto-object used for temporarily substituting/removing elements
                     96: class Temp_value_element {
                     97:        Value& fwhere;
                     98:        const String& fname;
                     99:        Value* saved;
                    100: public:
                    101:        Temp_value_element(Value& awhere, const String& aname, Value* awhat) : 
                    102:                fwhere(awhere),
                    103:                fname(aname),
                    104:                saved(awhere.get_element(aname, awhere, false)) {
1.5       paf       105:                fwhere.put_element(fwhere, aname, awhat, false);
1.2       paf       106:        }
                    107:        ~Temp_value_element() { 
1.5       paf       108:                fwhere.put_element(fwhere, fname, saved, false);
1.2       paf       109:        }
                    110: };
                    111: 
                    112: 
                    113: #endif

E-mail: