Annotation of parser3/src/types/pa_method.h, revision 1.11
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.11 ! misha 11: static const char * const IDENT_METHOD_H="$Date: 2009-04-17 12:00:42 $";
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.9 misha 71: bool all_vars_local; // in local vars list 'locals' was specified: all vars are local
1.11 ! misha 72: bool allways_use_result; // write to $result detected. will not collect all writes to output scope.
1.2 paf 73:
1.7 misha 74: Method(
1.2 paf 75: //const String& aname,
76: Call_type call_type,
77: int amin_numbered_params_count, int amax_numbered_params_count,
78: ArrayString* aparams_names, ArrayString* alocals_names,
1.8 misha 79: ArrayOperation* aparser_code, NativeCodePtr anative_code,
1.10 misha 80: bool aall_vars_local=false, bool aallways_use_result=false) :
1.2 paf 81:
82: //name(aname),
83: call_type(call_type),
84: min_numbered_params_count(amin_numbered_params_count),
85: max_numbered_params_count(amax_numbered_params_count),
86: params_names(aparams_names), locals_names(alocals_names),
1.8 misha 87: parser_code(aparser_code), native_code(anative_code),
1.10 misha 88: all_vars_local(aall_vars_local), allways_use_result(aallways_use_result) {
1.2 paf 89: }
90:
91: /// call this before invoking to ensure proper actual numbered params count
92: void check_actual_numbered_params(
93: Value& self, /*const String& actual_name, */MethodParams* actual_numbered_params) const;
94: };
95:
96: /// Auto-object used for temporarily substituting/removing elements
97: class Temp_value_element {
98: Value& fwhere;
99: const String& fname;
100: Value* saved;
101: public:
102: Temp_value_element(Value& awhere, const String& aname, Value* awhat) :
103: fwhere(awhere),
104: fname(aname),
105: saved(awhere.get_element(aname, awhere, false)) {
1.5 paf 106: fwhere.put_element(fwhere, aname, awhat, false);
1.2 paf 107: }
108: ~Temp_value_element() {
1.5 paf 109: fwhere.put_element(fwhere, fname, saved, false);
1.2 paf 110: }
111: };
112:
113:
114: #endif
E-mail: