Diff for /parser3/src/doc/ClassExample1.dox between versions 1.2 and 1.5

version 1.2, 2001/05/07 13:29:54 version 1.5, 2004/03/30 08:32:17
Line 1 Line 1
 /**     @page ClassExample1  Пример создания простого класса (только методы)  /**     @page ClassExample1  Example of creating simple class (with methods only)
   
 Чтобы создать свой класс, состоящий только из методов[таков, например, класс random],   To create the class of your own, consisting only of methods[like, for "random" class],
 нужно положить в каталог classes/ модуль на C++ с расширением .С,  one need to put to classes/ directory module in C++ language with .C file name extension,
 в котором...  in which...
   
 1. Определить потомка Methoded, определяющего Methoded::used_directly в true.  1. Define a descendant of Methoded, declaring Methoded::used_directly as true.
   
 2. Оформить методы объекта так[ Native_code_ptr ]:  2. Code methods of objects like this[ Native_code_ptr ]:
 @code  @code
 static void _test(Request& r, const String& method_name, MethodParams *params) {  static void _test(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
   
         ...          ...
   
         // ошибки генерировать так:          // generate exceptions like this:
         if(error_code)          if(error_code)
                 PTHROW(0, 0,                  throw Exception("exception class",
                         &method_name, // адрес String, содержащей текст/место ошибки                          &method_name, // address of String, containing text/source of error
                         "проблема %d", error_code);                          "problem %d", error_code);
   
         // выдавать текст так:          // output text like this:
         if(text_result)          if(text_result)
                 r.write_assign_lang(*new(pool) VString(pool, "тест"));                  r.write_assign_lang(*new(pool) String(pool, "тест"));
   
         // выдавать объекты так:          // output objects like this:
         if(object_result)          if(object_result)
                 r.write_no_lang(*new(pool) VInt(pool, 48));                  r.write_no_lang(*new(pool) VInt(pool, 48));
 }  }
 @endcode  @endcode
   
 3. В конструкторе задать имя класса и зарегистрировать методы:  3. In constructor one must set class name and register it's methods:
   
 @code  @code
 MExample1::MExample1(Pool& apool) : Methoded(apool) {  MExample1::MExample1(Pool& apool) : Methoded(apool, "example1") {
         set_name(*NEW String(pool(), "example1"));  
   
   
         // ^example1:test[]          // ^example1:test[]
         add_native_method("test", Method::CT_STATIC, _test, 0, 0);          add_native_method("test", Method::CT_STATIC, _test, 0, 0);
 }  }
 @endcode  @endcode
   
 @see Value::set_name, VStateless_class::add_native_method  @see VStateless_class::add_native_method
   
 4. И, наконец, определить производящую функцию, с именем M{имя_файла_с_заглавной_буквы}_create:  4. And, finally, define constricting function, with name M{name_of_file_with_first_letter_Capital}_create:
 @code  @code
 Methoded *MExample1_create(Pool& pool) {  Methoded *MExample1_create(Pool& pool) {
         return new(pool) MExample1(pool);          return new(pool) MExample1(pool);
 }  }
 @endcode  @endcode
   
 5. Если для работы классу необходимы какие-то настройки, то их можно принять из системного auto.p,  5. If for class to work it need any options, they could be read from variables assigned in @conf,
 или из пользовательского MAIN класса, переопределив Methoded::configure_admin и/или Methoded::configure_user.  by overriding Methoded::configure_admin and/or Methoded::configure_user.
   
   User then could call that method like:
   @verbatim
   ^example1:test[]
   @endverbatim
   
 */  */

Removed from v.1.2  
changed lines
  Added in v.1.5


E-mail: