Annotation of parser3/src/types/pa_vstring.h, revision 1.9

1.1       paf         1: /*
                      2:        Parser
                      3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.2       paf         4:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.1       paf         5: 
1.9     ! paf         6:        $Id: pa_vstring.h,v 1.8 2001/03/15 11:00:42 paf Exp $
1.1       paf         7: */
                      8: 
                      9: #ifndef PA_VSTRING_H
                     10: #define PA_VSTRING_H
                     11: 
                     12: #include <stdlib.h>
                     13: 
1.4       paf        14: #include "pa_vstateless_object.h"
1.1       paf        15: #include "pa_vdouble.h"
                     16: #include "_string.h"
                     17: 
1.4       paf        18: class VString : public VStateless_object {
1.1       paf        19: public: // Value
                     20: 
                     21:        // all: for error reporting after fail(), etc
                     22:        const char *type() const { return "string"; }
                     23:        // string: fvalue as VDouble
                     24:        Value *get_expr_result() { return NEW VDouble(pool(), get_double()); }
                     25:        // string: fvalue
                     26:        const String *get_string() { return &fvalue; };
                     27:        // string: fvalue
1.6       paf        28:        double get_double() { 
                     29:                double result;
                     30:                const char *cstr=fvalue.cstr();
                     31:                char *error_pos=0;
1.8       paf        32:                // 0xABC
                     33:                if(cstr[0]=='0' && (cstr[1]=='x' || cstr[1]=='X'))
1.6       paf        34:                        result=(double)strtoul(cstr, &error_pos, 0);
                     35:                else
                     36:                        result=strtod(cstr, &error_pos);
                     37: 
1.8       paf        38:                if(error_pos&&*error_pos)
                     39:                        THROW(0, 0,
                     40:                                &fvalue,
                     41:                                "invalid number");
                     42: 
                     43:                //return error_pos&&*error_pos?0:result;
                     44:                return result;
1.6       paf        45:        }
1.9     ! paf        46:        // string: double!=0
        !            47:        bool get_bool() { zreturn fvalue.size()!=0 && get_double()!=0; };
        !            48: 
        !            49:        // string: $CLASS,$BASE,$method
        !            50:        Value *get_element(const String& name) {
        !            51:                // $CLASS,$BASE,$method
        !            52:                if(Value *result=VStateless_object::get_element(name))
        !            53:                        return result;
        !            54: 
        !            55:                // bad $string.field
        !            56:                bark("(%s) does not have fields");  return 0;
        !            57:        }
1.1       paf        58: 
                     59: public: // usage
                     60: 
1.4       paf        61:        VString(Pool& apool) : VStateless_object(apool, *string_class), 
1.5       paf        62:                fvalue(*new(apool) String(apool)) {
1.1       paf        63:        }
                     64: 
1.4       paf        65:        VString(const String& avalue) : VStateless_object(avalue.pool(), *string_class),
1.1       paf        66:                fvalue(avalue) {
                     67:        }
                     68: 
                     69:        const String& value() { return fvalue; }
                     70: 
                     71: private:
                     72:        const String& fvalue;
                     73: 
                     74: };
                     75: 
                     76: #endif

E-mail: