Annotation of parser3/src/types/pa_vint.h, revision 1.38.2.3
1.12 paf 1: /** @file
1.17 paf 2: Parser: @b int parser class decl.
1.12 paf 3:
1.38 paf 4: Copyright (c) 2001, 2003 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.38.2.3! paf 11: static const char* IDENT_VINT_H="$Date: 2003/01/27 15:07:48 $";
1.1 paf 12:
1.20 paf 13: #include "classes.h"
1.10 paf 14: #include "pa_common.h"
1.5 paf 15: #include "pa_vstateless_object.h"
1.18 paf 16:
17: extern Methoded *int_class;
1.1 paf 18:
1.12 paf 19: /// value of type 'int'. implemented with @c int
1.4 paf 20: class VInt : public VStateless_object {
1.1 paf 21: public: // Value
22:
1.38.2.1 paf 23: override const char *type() const { return "int"; }
24: override VStateless_class *get_class() { return int_class; }
1.34 paf 25:
1.25 parser 26: /// VInt: clone
1.38.2.1 paf 27: override ValuePtr as_expr_result(bool ) { return ValuePtr(new VInt(finteger)); }
1.1 paf 28:
1.12 paf 29: /// VInt: finteger
1.38.2.1 paf 30: override ConstStringPtr get_string(Pool& pool) {
1.32 paf 31: char local_buf[MAX_NUMBER];
32: size_t size=snprintf(local_buf, MAX_NUMBER, "%d", finteger);
1.38.2.3! paf 33: char *pool_buf=pool.copy(local_buf, size);
1.32 paf 34:
1.38.2.2 paf 35: return ConstStringPtr(new String(pool_buf, size));
1.1 paf 36: }
1.12 paf 37: /// VInt: finteger
1.38.2.1 paf 38: override double as_double() const { return as_int(); }
1.22 parser 39: /// VInt: finteger
1.38.2.1 paf 40: override int as_int() const { return finteger; }
1.12 paf 41: /// VInt: 0 or !0
1.38.2.1 paf 42: override bool as_bool() const { return finteger!=0; }
1.1 paf 43:
44: public: // usage
45:
1.38.2.2 paf 46: VInt(int ainteger): finteger(ainteger) {}
1.1 paf 47:
48: int get_int() { return finteger; }
1.8 paf 49: void set_int(int ainteger) { finteger=ainteger; }
1.1 paf 50:
1.8 paf 51: void inc(int increment) { finteger+=increment; }
52: void mul(double k) { finteger=(int)(finteger*k); }
53: void div(double d) { finteger=(int)(finteger/d); }
54: void mod(int d) { finteger%=d; }
1.1 paf 55:
56: private:
57:
58: int finteger;
59:
60: };
61:
62: #endif
E-mail: