Annotation of parser3/src/classes/random.C, revision 1.6

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.6     ! paf         8:        $Id: random.C,v 1.5 2001/04/06 08:55:18 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.6     ! paf        27: static void _generate(Request& r, const String& method_name, MethodParams *params) {
1.1       paf        28:        Pool& pool=r.pool();
                     29: 
1.6     ! paf        30:        Value& range=params->get_junction(0, "range must be expression");
1.4       paf        31:     uint max=params->size()?(uint)r.process(range).as_double():0;
1.2       paf        32:     if(max<=1)
1.3       paf        33:                PTHROW(0, 0,
1.2       paf        34:                        &method_name,
                     35:                        "bad range [0..%u]", max);
1.1       paf        36:        
                     37:        r.write_no_lang(*new(pool) VInt(pool, rand()%max));
                     38: }
                     39: 
                     40: // initialize
                     41: 
                     42: void initialize_random_class(Pool& pool, VStateless_class& vclass) {
                     43:        // setting seed
                     44:        srand(getpid()+time(NULL));  rand();
                     45:        
                     46:        // ^random.generate[]
                     47:        // ^random.generate(range)
1.4       paf        48:        vclass.add_native_method("generate", Method::CT_STATIC, _generate, 1, 1);
1.1       paf        49: }

E-mail: