1 module hunt.sql.ast.expr.SQLRealExpr;
2 import hunt.sql.ast.expr.SQLValuableExpr;
3 import hunt.sql.ast.expr.SQLNumericLiteralExpr;
4 import hunt.collection;
5 import hunt.sql.visitor.SQLASTVisitor;
6 import hunt.Number;
7 import hunt.Float;
8 import hunt.sql.ast.SQLObject;
9 
10 public class SQLRealExpr : SQLNumericLiteralExpr , SQLValuableExpr {
11 
12     private float value;
13 
14     public this(){
15 
16     }
17 
18     public this(float value){
19         super();
20         this.value = value;
21     }
22 
23     override public SQLRealExpr clone() {
24         return new SQLRealExpr(value);
25     }
26 
27     public override List!SQLObject getChildren() {
28         return Collections.emptyList!(SQLObject)();
29     }
30 
31     public override Number getNumber() {
32         return cast(Number)(new Float(value));
33     }
34 
35     override public Object getValue() {
36         return new Float(value);
37     }
38 
39     public void setValue(float value) {
40         this.value = value;
41     }
42 
43     override  protected void accept0(SQLASTVisitor visitor) {
44         visitor.visit(this);
45 
46         visitor.endVisit(this);
47     }
48 
49     public override size_t toHash() @trusted nothrow {
50          int prime = 31;
51         size_t result = 1;
52         result = prime * result + hashOf(value);
53         return result;
54     }
55 
56     public override bool opEquals(Object obj) {
57         if (this is obj) {
58             return true;
59         }
60         if (obj is null) {
61             return false;
62         }
63         if (typeid("SQLRealExpr") != typeid(obj)) {
64             return false;
65         }
66         SQLRealExpr other = cast(SQLRealExpr) obj;
67         if (value == float.init) {
68             if (other.value !is float.init) {
69                 return false;
70             }
71         } else if (!(value == other.value)) {
72             return false;
73         }
74         return true;
75     }
76 
77     public override void setNumber(Number number) {
78         if (number is null) {
79             this.setValue(float.init);
80             return;
81         }
82 
83         this.setValue(number.floatValue());
84     }
85 
86 }