Annotation of parser3/src/doc/ClassExample1.dox, revision 1.4.34.1

1.4.34.1! paf         1: /**    @page ClassExample1  Example of creating simple class (with methods only)
1.1       paf         2: 
1.4.34.1! paf         3: To create the class of your own, consisting only of methods[like, for "random" class],
        !             4: one need to put to classes/ directory module in C++ language with .C file name extension,
        !             5: in which...
1.1       paf         6: 
1.4.34.1! paf         7: 1. Define a descendant of Methoded, declaring Methoded::used_directly as true.
1.1       paf         8: 
1.4.34.1! paf         9: 2. Code methods of objects like this[ Native_code_ptr ]:
1.1       paf        10: @code
                     11: static void _test(Request& r, const String& method_name, MethodParams *params) {
                     12:        Pool& pool=r.pool();
                     13: 
                     14:        ...
                     15: 
1.4.34.1! paf        16:        // generate exceptions like this:
1.1       paf        17:        if(error_code)
1.4.34.1! paf        18:                throw Exception("exception class",
        !            19:                        &method_name, // address of String, containing text/source of error
        !            20:                        "problem %d", error_code);
1.1       paf        21: 
1.4.34.1! paf        22:        // output text like this:
1.1       paf        23:        if(text_result)
1.3       paf        24:                r.write_assign_lang(*new(pool) String(pool, "тест"));
1.1       paf        25: 
1.4.34.1! paf        26:        // output objects like this:
1.1       paf        27:        if(object_result)
                     28:                r.write_no_lang(*new(pool) VInt(pool, 48));
                     29: }
                     30: @endcode
                     31: 
1.4.34.1! paf        32: 3. In constructor one must set class name and register it's methods:
1.1       paf        33: 
                     34: @code
1.4       paf        35: MExample1::MExample1(Pool& apool) : Methoded(apool, "example1") {
1.1       paf        36:        // ^example1:test[]
                     37:        add_native_method("test", Method::CT_STATIC, _test, 0, 0);
                     38: }
                     39: @endcode
                     40: 
1.4       paf        41: @see VStateless_class::add_native_method
1.1       paf        42: 
1.4.34.1! paf        43: 4. And, finally, define constricting function, with name M{name_of_file_with_first_letter_Capital}_create:
1.1       paf        44: @code
                     45: Methoded *MExample1_create(Pool& pool) {
                     46:        return new(pool) MExample1(pool);
                     47: }
                     48: @endcode
1.2       paf        49: 
1.4.34.1! paf        50: 5. If for class to work it need any options, they could be read from variables assigned in @conf,
        !            51: by overriding Methoded::configure_admin and/or Methoded::configure_user.
1.3       paf        52: 
1.4.34.1! paf        53: User then could call that method like:
1.3       paf        54: @verbatim
                     55: ^example1:test[]
                     56: @endverbatim
1.1       paf        57: 
                     58: */

E-mail: