1 // 2 // aegis - project change supervisor 3 // Copyright (C) 1994, 1996, 1997, 2003-2008 Peter Miller 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program. If not, see 17 // <http://www.gnu.org/licenses/>. 18 // 19 20 #include <common/ac/limits.h> 21 22 #include <common/error.h> 23 #include <libaegis/aer/value/boolean.h> 24 #include <libaegis/aer/value/integer.h> 25 #include <libaegis/aer/value/real.h> 26 #include <libaegis/aer/value/string.h> 27 28 ~rpt_value_real()29rpt_value_real::~rpt_value_real() 30 { 31 } 32 33 rpt_value_real(double arg)34rpt_value_real::rpt_value_real(double arg) : 35 value(arg) 36 { 37 } 38 39 40 rpt_value::pointer create(double arg)41rpt_value_real::create(double arg) 42 { 43 return pointer(new rpt_value_real(arg)); 44 } 45 46 47 rpt_value::pointer stringize_or_null() const48rpt_value_real::stringize_or_null() 49 const 50 { 51 if (value == 0) 52 { 53 // avoid IEEE "negative zero" lunacy 54 return rpt_value_string::create("0"); 55 } 56 return rpt_value_string::create(nstring::format("%g", value)); 57 } 58 59 60 rpt_value::pointer booleanize_or_null() const61rpt_value_real::booleanize_or_null() 62 const 63 { 64 return rpt_value_boolean::create(value != 0); 65 } 66 67 68 rpt_value::pointer integerize_or_null() const69rpt_value_real::integerize_or_null() 70 const 71 { 72 if (value < LONG_MIN || value > LONG_MAX) 73 return pointer(); 74 return rpt_value_integer::create(long(value)); 75 } 76 77 78 const char * name() const79rpt_value_real::name() 80 const 81 { 82 return "real"; 83 } 84 85 86 double query() const87rpt_value_real::query() 88 const 89 { 90 return value; 91 } 92