--- parser3/src/classes/Attic/random.C 2001/04/17 19:00:27 1.7 +++ parser3/src/classes/Attic/random.C 2001/04/27 16:48:21 1.9.2.2 @@ -1,26 +1,35 @@ /** @file - Parser: random parser class. + Parser: @b random parser class. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: random.C,v 1.7 2001/04/17 19:00:27 paf Exp $ + $Id: random.C,v 1.9.2.2 2001/04/27 16:48:21 paf Exp $ */ #include "pa_config_includes.h" #include "pa_common.h" -#include "_random.h" #include "pa_vint.h" #include "pa_request.h" -// global var +// defines -VStateless_class *random_class; +#define RANDOM_CLASS_NAME "random" + +// class + +class MRandom : public Methoded { +public: + MRandom(Pool& pool); + bool used_directly() { return true; } +}; // methods -/// @test noticed series in isapi, check how initialize_random_class is called! [must be called only once] +/** ^random.generate[] + ^random.generate(range) +*/ static void _generate(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -34,13 +43,21 @@ static void _generate(Request& r, const r.write_no_lang(*new(pool) VInt(pool, rand()%max)); } -// initialize +// constructor + +MRandom::MRandom(Pool& pool) : Methoded(pool) { + set_name(NEW String(pool, RANDOM_CLASS_NAME)); -void initialize_random_class(Pool& pool, VStateless_class& vclass) { // setting seed srand(getpid()+time(NULL)); rand(); // ^random.generate[] // ^random.generate(range) - vclass.add_native_method("generate", Method::CT_STATIC, _generate, 1, 1); + add_native_method("generate", Method::CT_STATIC, _generate, 1, 1); +} + +// creator + +Methoded *MRandom_create(Pool& pool) { + return new(pool) MRandom(pool); }