Annotation of parser3/src/types/pa_vint.h, revision 1.45

1.12      paf         1: /** @file
1.17      paf         2:        Parser: @b int parser class decl.
1.12      paf         3: 
1.43      paf         4:        Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
1.31      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_VINT_H
                      9: #define PA_VINT_H
1.35      paf        10: 
1.45    ! misha      11: static const char * const IDENT_VINT_H="$Date: 2005/11/21 10:13:43 $";
        !            12: 
        !            13: // include
1.1       paf        14: 
1.20      paf        15: #include "classes.h"
1.10      paf        16: #include "pa_common.h"
1.5       paf        17: #include "pa_vstateless_object.h"
1.18      paf        18: 
1.45    ! misha      19: // defines
        !            20: 
        !            21: #define VINT_TYPE "int"
        !            22: 
1.39      paf        23: extern Methoded* int_class;
1.1       paf        24: 
1.12      paf        25: /// value of type 'int'. implemented with @c int
1.39      paf        26: class VInt: public VStateless_object {
1.1       paf        27: public: // Value
                     28: 
1.45    ! misha      29:        override const char* type() const { return VINT_TYPE; }
1.39      paf        30:        override VStateless_class *get_class() { return int_class; }
1.34      paf        31: 
1.42      paf        32:        /// VInt: true
1.44      paf        33:        override bool is_evaluated_expr() const { return true; }
1.25      parser     34:        /// VInt: clone
1.39      paf        35:        override Value& as_expr_result(bool) { return *new VInt(finteger); }
1.1       paf        36: 
1.12      paf        37:        /// VInt: finteger
1.39      paf        38:        override const String* get_string() {
1.32      paf        39:                char local_buf[MAX_NUMBER];
1.39      paf        40:                size_t length=snprintf(local_buf, MAX_NUMBER, "%d", finteger);
                     41:                return new String(strdup(local_buf, length), length);
1.1       paf        42:        }
1.12      paf        43:        /// VInt: finteger
1.39      paf        44:        override double as_double() const { return as_int(); }
1.22      parser     45:        /// VInt: finteger
1.39      paf        46:        override int as_int() const { return finteger; }
1.12      paf        47:        /// VInt: 0 or !0
1.39      paf        48:        override bool as_bool() const { return finteger!=0; }
1.1       paf        49: 
                     50: public: // usage
                     51: 
1.39      paf        52:        VInt(int ainteger): finteger(ainteger) {}
1.1       paf        53: 
                     54:        int get_int() { return finteger; }
1.8       paf        55:        void set_int(int ainteger) { finteger=ainteger; }
1.1       paf        56: 
1.8       paf        57:        void inc(int increment) { finteger+=increment; }
                     58:        void mul(double k) { finteger=(int)(finteger*k); }
                     59:        void div(double d) { finteger=(int)(finteger/d); }
                     60:        void mod(int d) { finteger%=d; }
1.1       paf        61: 
                     62: private:
                     63: 
                     64:        int finteger;
                     65: 
                     66: };
                     67: 
                     68: #endif

E-mail: