Annotation of parser3/src/types/pa_vdouble.h, revision 1.33

1.11      paf         1: /** @file
1.16      paf         2:        Parser: @b double parser class decl.
1.11      paf         3: 
1.31      paf         4:        Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.32      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: 
1.33    ! paf         7:        $Id: pa_vdouble.h,v 1.32 2002/02/08 08:30:19 paf Exp $
1.1       paf         8: */
                      9: 
                     10: #ifndef PA_VDOUBLE_H
                     11: #define PA_VDOUBLE_H
                     12: 
1.19      paf        13: #include "classes.h"
1.9       paf        14: #include "pa_common.h"
1.5       paf        15: #include "pa_vstateless_object.h"
1.17      paf        16: 
                     17: extern Methoded *double_class;
1.1       paf        18: 
1.11      paf        19: /// value of type 'double'. implemented with @c double
1.4       paf        20: class VDouble : public VStateless_object {
1.1       paf        21: public: // Value
                     22: 
                     23:        const char *type() const { return "double"; }
1.24      parser     24:        /// VDouble: clone
1.27      parser     25:        Value *as_expr_result(bool ) { return NEW VDouble(pool(), fdouble); }
1.1       paf        26: 
1.30      paf        27:        /** VDouble: fdouble 
                     28:                @test
                     29:                        now $a(2*2) 2*2 becomes double, then string, then double again!! get rid of that
                     30:        */
1.1       paf        31:        const String *get_string() {
1.6       paf        32:                char *buf=(char *)pool().malloc(MAX_NUMBER);
1.22      parser     33:                String *result=NEW String(pool());
1.23      parser     34:                result->APPEND_CLEAN(
1.33    ! paf        35:                        buf, snprintf(buf, MAX_NUMBER, "%g", fdouble), 
1.23      parser     36:                        name().origin().file, name().origin().line);
1.22      parser     37:                return result;
1.1       paf        38:        }
1.11      paf        39:        /// VDouble: fdouble
1.25      parser     40:        double as_double() const { return fdouble; }
1.21      parser     41:        /// VDouble: fdouble
1.25      parser     42:        int as_int() const { return (int)fdouble; }
1.11      paf        43:        /// VDouble: 0 or !0
1.25      parser     44:        bool as_bool() const { return fdouble!=0; }
1.10      paf        45: 
                     46: protected: // VAliased
                     47: 
1.13      paf        48:        /// disable .CLASS element. @see VAliased::get_element
1.15      paf        49:        bool hide_class() { return true; }
1.1       paf        50: 
                     51: public: // usage
                     52: 
1.4       paf        53:        VDouble(Pool& apool, double adouble) : VStateless_object(apool, *double_class), 
1.1       paf        54:                fdouble(adouble) {
                     55:        }
                     56: 
                     57:        void inc(double increment) { fdouble+=increment; }
1.7       paf        58:        void mul(double k) { fdouble*=k; }
                     59:        void div(double d) { fdouble/=d; }
                     60:        void mod(int d) { fdouble=((int)fdouble)%d; }
1.1       paf        61: 
                     62: private:
                     63: 
                     64:        double fdouble;
                     65: 
                     66: };
                     67: 
                     68: #endif

E-mail: