File:  [parser3project] / parser3 / src / doc / ClassExample1.dox
Revision 1.5: download - view: text, annotated - select for diffs - revision graph
Tue Mar 30 08:32:17 2004 UTC (22 years, 2 months ago) by paf
Branches: MAIN
CVS tags: release_3_5_1, release_3_5_0, release_3_4_6, release_3_4_5, release_3_4_4, release_3_4_3, release_3_4_2, release_3_4_1, release_3_4_0, release_3_3_0, release_3_2_3, release_3_2_2, release_3_2_1, release_3_2_0, release_3_1_6, release_3_1_5, release_3_1_4, release_3_1_3, paf_left, HEAD
merged bugfixes from 3.1.2, changed version to 3.1.3beta

/**	@page ClassExample1  Example of creating simple class (with methods only)

To create the class of your own, consisting only of methods[like, for "random" class],
one need to put to classes/ directory module in C++ language with .C file name extension,
in which...

1. Define a descendant of Methoded, declaring Methoded::used_directly as true.

2. Code methods of objects like this[ Native_code_ptr ]:
@code
static void _test(Request& r, const String& method_name, MethodParams *params) {
	Pool& pool=r.pool();

	...

	// generate exceptions like this:
	if(error_code)
		throw Exception("exception class",
			&method_name, // address of String, containing text/source of error
			"problem %d", error_code);

	// output text like this:
	if(text_result)
		r.write_assign_lang(*new(pool) String(pool, "тест"));

	// output objects like this:
	if(object_result)
		r.write_no_lang(*new(pool) VInt(pool, 48));
}
@endcode

3. In constructor one must set class name and register it's methods:

@code
MExample1::MExample1(Pool& apool) : Methoded(apool, "example1") {
	// ^example1:test[]
	add_native_method("test", Method::CT_STATIC, _test, 0, 0);
}
@endcode

@see VStateless_class::add_native_method

4. And, finally, define constricting function, with name M{name_of_file_with_first_letter_Capital}_create:
@code
Methoded *MExample1_create(Pool& pool) {
	return new(pool) MExample1(pool);
}
@endcode

5. If for class to work it need any options, they could be read from variables assigned in @conf,
by overriding Methoded::configure_admin and/or Methoded::configure_user.

User then could call that method like:
@verbatim
^example1:test[]
@endverbatim

*/

E-mail: