Annotation of parser3/src/classes/random.C, revision 1.5
1.1 paf 1: /** @file
2: Parser: random parser class.
3:
4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
5:
6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
7:
1.5 ! paf 8: $Id: random.C,v 1.4 2001/04/05 13:19:39 paf Exp $
1.1 paf 9: */
10:
11: #include <process.h>
12: #include <time.h>
13:
14: #include "pa_config_includes.h"
15: #include "pa_common.h"
16: #include "_random.h"
17: #include "pa_vint.h"
18: #include "pa_request.h"
19:
20: // global var
21:
22: VStateless_class *random_class;
23:
24: // methods
25:
1.5 ! paf 26: /// @test noticed series in isapi, check how initialize_random_class is called! [must be called only once]
1.1 paf 27: static void _generate(Request& r, const String& method_name, Array *params) {
28: Pool& pool=r.pool();
29:
1.4 paf 30: Value& range=*static_cast<Value *>(params->get(0));
31: // (this body type)
32: r.fail_if_junction_(false, range, method_name, "range must be expression");
33:
34: uint max=params->size()?(uint)r.process(range).as_double():0;
1.2 paf 35: if(max<=1)
1.3 paf 36: PTHROW(0, 0,
1.2 paf 37: &method_name,
38: "bad range [0..%u]", max);
1.1 paf 39:
40: r.write_no_lang(*new(pool) VInt(pool, rand()%max));
41: }
42:
43: // initialize
44:
45: void initialize_random_class(Pool& pool, VStateless_class& vclass) {
46: // setting seed
47: srand(getpid()+time(NULL)); rand();
48:
49: // ^random.generate[]
50: // ^random.generate(range)
1.4 paf 51: vclass.add_native_method("generate", Method::CT_STATIC, _generate, 1, 1);
1.1 paf 52: }
E-mail: