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