Annotation of parser3/src/types/pa_method.h, revision 1.1.2.4
1.1.2.1 paf 1: /** @file
2: Parser: Method class decl.
3:
4: Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
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.1.2.4 ! paf 11: static const char* IDENT_METHOD_H="$Date: 2003/02/04 15:59:06 $";
1.1.2.1 paf 12:
13: #include "pa_pool.h"
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,
27: StringPtr method_name,
1.1.2.4 ! paf 28: MethodParams* params);
1.1.2.1 paf 29:
30:
31: /**
32: class method.
33:
34: methods can have
35: - named or
36: - numbered parameters
37:
38: methods can be
39: - parser or
40: - native onces
41:
42: holds
43: - parameter names or number limits
44: - local names
45: - code [parser or native]
46: */
47: class Method: public PA_Object {
48: public:
49:
50: /// allowed method call types
51: enum Call_type {
52: CT_ANY, ///< method can be called either statically or dynamically
53: CT_STATIC, ///< method can be called only statically
54: CT_DYNAMIC ///< method can be called only dynamically
55: };
56:
57: /// name for error reporting
58: StringPtr name;
59: ///
60: Call_type call_type;
61: //@{
62: /// @name either numbered params // for native-code methods = operators
63: int min_numbered_params_count, max_numbered_params_count;
64: //@}
65: //@{
66: /// @name or named params&locals // for parser-code methods
67: ArrayStringPtr params_names; ArrayStringPtr locals_names;
68: //@}
69: //@{
70: /// @name the Code
71: ArrayOperationPtr parser_code;/*OR*/NativeCodePtr native_code;
72: //@}
73:
74: Method::Method(
75: StringPtr aname,
76: Call_type call_type,
77: int amin_numbered_params_count, int amax_numbered_params_count,
78: ArrayStringPtr aparams_names, ArrayStringPtr alocals_names,
79: ArrayOperationPtr aparser_code, NativeCodePtr anative_code) :
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),
86: parser_code(aparser_code), native_code(anative_code) {
87: }
88:
89: /// call this before invoking to ensure proper actual numbered params count
90: void check_actual_numbered_params(
1.1.2.4 ! paf 91: Value& self, StringPtr actual_name, MethodParams* actual_numbered_params) const;
1.1.2.1 paf 92: };
93:
94: /// Auto-object used for temporarily substituting/removing elements
95: class Temp_value_element {
96: Value& fwhere;
97: StringPtr fname;
98: ValuePtr saved;
99: public:
100: Temp_value_element(Value& awhere, StringPtr aname, ValuePtr awhat) :
101: fwhere(awhere),
102: fname(aname),
103: saved(awhere.get_element(aname, awhere, false)) {
104: fwhere.put_element(aname, awhat, false);
105: }
106: ~Temp_value_element() {
107: fwhere.put_element(fname, saved, false);
108: }
109: };
110:
111:
112: #endif
E-mail: