Annotation of parser3/src/types/pa_vint.h, revision 1.17
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.17 ! paf 8: $Id: pa_vint.h,v 1.16 2001/04/02 16:00:17 paf Exp $
1.1 paf 9: */
10:
11: #ifndef PA_VINT_H
12: #define PA_VINT_H
13:
1.10 paf 14: #include "pa_common.h"
1.5 paf 15: #include "pa_vstateless_object.h"
1.1 paf 16: #include "_int.h"
17:
1.12 paf 18: /// value of type 'int'. implemented with @c int
1.4 paf 19: class VInt : public VStateless_object {
1.1 paf 20: public: // Value
21:
1.12 paf 22: /// all: for error reporting after fail(), etc
1.1 paf 23: const char *type() const { return "int"; }
1.12 paf 24: /// VInt: this
1.15 paf 25: Value *as_expr_result(bool return_string_as_is=false) { return this; }
1.1 paf 26:
1.12 paf 27: /// VInt: finteger
1.1 paf 28: const String *get_string() {
1.7 paf 29: char *buf=(char *)pool().malloc(MAX_NUMBER);
30: snprintf(buf, MAX_NUMBER, "%d", finteger);
1.9 paf 31: return NEW String(pool(), buf);
1.1 paf 32: }
1.12 paf 33: /// VInt: finteger
1.15 paf 34: double as_double() { return finteger; }
1.12 paf 35: /// VInt: 0 or !0
1.15 paf 36: bool as_bool() { return finteger!=0; }
1.11 paf 37:
38: protected: // VAliased
39:
1.14 paf 40: /// disable .CLASS element. @see VAliased::get_element
1.16 paf 41: bool hide_class() { return true; }
1.1 paf 42:
43: public: // usage
44:
1.4 paf 45: VInt(Pool& apool, int ainteger) : VStateless_object(apool, *int_class),
1.1 paf 46: finteger(ainteger) {
47: }
48:
49: int get_int() { return finteger; }
1.8 paf 50: void set_int(int ainteger) { finteger=ainteger; }
1.1 paf 51:
1.8 paf 52: void inc(int increment) { finteger+=increment; }
53: void mul(double k) { finteger=(int)(finteger*k); }
54: void div(double d) { finteger=(int)(finteger/d); }
55: void mod(int d) { finteger%=d; }
1.1 paf 56:
57: private:
58:
59: int finteger;
60:
61: };
62:
63: #endif
E-mail: