Annotation of parser3/src/types/pa_vbool.h, revision 1.41
1.7 paf 1: /** @file
1.8 paf 2: Parser: @b bool class decls.
1.7 paf 3:
1.41 ! moko 4: Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com)
1.39 moko 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1 paf 6: */
7:
8: #ifndef PA_VBOOL_H
9: #define PA_VBOOL_H
1.19 paf 10:
1.41 ! moko 11: #define IDENT_PA_VBOOL_H "$Id: pa_vbool.h,v 1.40 2023/10/05 01:28:08 moko Exp $"
1.22 paf 12:
13: // include
1.1 paf 14:
1.29 misha 15: #include "classes.h"
1.3 paf 16: #include "pa_common.h"
1.29 misha 17: #include "pa_vstateless_object.h"
1.1 paf 18:
1.28 misha 19: // defines
20:
1.29 misha 21: #define VBOOL_TYPE "bool"
1.1 paf 22: #define MAX_BOOL_AS_STRING 20
23:
1.29 misha 24: extern Methoded* bool_class;
25:
26: // VBool
1.40 moko 27: class VBool: public VSimple_stateless_object {
1.1 paf 28: public: // Value
29:
1.28 misha 30: override const char* type() const { return VBOOL_TYPE; }
1.18 paf 31: /// VBool: 0
1.29 misha 32: override VStateless_class *get_class() { return bool_class; }
33:
1.27 paf 34: /// VBool: true
35: override bool is_evaluated_expr() const { return true; }
1.11 parser 36: /// VBool: clone
1.34 moko 37: override Value& as_expr_result() { return *this; }
1.29 misha 38:
1.32 misha 39: /// VBool: true
1.30 misha 40: virtual bool is_defined() const { return true; }
1.29 misha 41:
42: /// VBool: fbool
1.34 moko 43: override double as_double() const { return fbool ? 1 : 0; }
1.25 paf 44: /// VBool: fbool
1.29 misha 45: override int as_int() const { return fbool ? 1 : 0; }
1.7 paf 46: /// VBool: fbool
1.22 paf 47: override bool as_bool() const { return fbool; }
1.29 misha 48:
1.30 misha 49: override bool is_bool() const { return true; }
1.1 paf 50:
1.32 misha 51: /// VBool: json-string ("true"|"false")
1.35 moko 52: override const String* get_json_string(Json_options&) {
1.32 misha 53: static const String singleton_json_true(String("true")), singleton_json_false(String("false"));
54: return fbool ? &singleton_json_true : &singleton_json_false;
55: }
56:
1.31 misha 57: inline static VBool &get(bool abool){
58: static VBool singleton_true(true), singleton_false(false);
59: return abool?singleton_true:singleton_false;
60: }
61:
1.1 paf 62: public: // usage
63:
1.22 paf 64: VBool(bool abool): fbool(abool) {}
1.29 misha 65: bool get_bool() { return fbool; }
1.1 paf 66:
67: private:
68:
69: bool fbool;
70:
71: };
72:
73: #endif
E-mail: