Annotation of parser3/src/types/pa_vint.h, revision 1.34
1.12 paf 1: /** @file
1.17 paf 2: Parser: @b int parser class decl.
1.12 paf 3:
1.30 paf 4: Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.31 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6:
1.34 ! paf 7: $Id: pa_vint.h,v 1.33 2002/04/18 10:51:02 paf Exp $
1.1 paf 8: */
9:
10: #ifndef PA_VINT_H
11: #define PA_VINT_H
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:
23: const char *type() const { return "int"; }
1.34 ! paf 24: VStateless_class *get_class() { return int_class; }
! 25:
1.25 parser 26: /// VInt: clone
1.28 parser 27: Value *as_expr_result(bool ) { return NEW VInt(pool(), finteger); }
1.1 paf 28:
1.12 paf 29: /// VInt: finteger
1.1 paf 30: const String *get_string() {
1.32 paf 31: char local_buf[MAX_NUMBER];
32: size_t size=snprintf(local_buf, MAX_NUMBER, "%d", finteger);
33:
34: char *pool_buf=(char *)pool().malloc(size);
35: memcpy(pool_buf, local_buf, size);
36:
1.23 parser 37: String *result=NEW String(pool());
1.24 parser 38: result->APPEND_CLEAN(
1.33 paf 39: pool_buf, size/*,
40: name().origin().file, name().origin().line*/,0,0);
1.23 parser 41: return result;
1.1 paf 42: }
1.12 paf 43: /// VInt: finteger
1.26 parser 44: double as_double() const { return as_int(); }
1.22 parser 45: /// VInt: finteger
1.26 parser 46: int as_int() const { return finteger; }
1.12 paf 47: /// VInt: 0 or !0
1.26 parser 48: bool as_bool() const { return finteger!=0; }
1.11 paf 49:
50: protected: // VAliased
51:
1.14 paf 52: /// disable .CLASS element. @see VAliased::get_element
1.16 paf 53: bool hide_class() { return true; }
1.1 paf 54:
55: public: // usage
56:
1.34 ! paf 57: VInt(Pool& apool, int ainteger) : VStateless_object(apool),
1.1 paf 58: finteger(ainteger) {
59: }
60:
61: int get_int() { return finteger; }
1.8 paf 62: void set_int(int ainteger) { finteger=ainteger; }
1.1 paf 63:
1.8 paf 64: void inc(int increment) { finteger+=increment; }
65: void mul(double k) { finteger=(int)(finteger*k); }
66: void div(double d) { finteger=(int)(finteger/d); }
67: void mod(int d) { finteger%=d; }
1.1 paf 68:
69: private:
70:
71: int finteger;
72:
73: };
74:
75: #endif
E-mail: