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

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

E-mail: