00001 /****************************************************************************** 00002 * 00003 * $Id: cppvalue.h,v 1.7 2001/03/19 19:27:40 root Exp $ 00004 * 00005 * 00006 * Copyright (C) 1997-2008 by Dimitri van Heesch. 00007 * 00008 * Permission to use, copy, modify, and distribute this software and its 00009 * documentation under the terms of the GNU General Public License is hereby 00010 * granted. No representations are made about the suitability of this software 00011 * for any purpose. It is provided "as is" without express or implied warranty. 00012 * See the GNU General Public License for more details. 00013 * 00014 * Documents produced by Doxygen are derivative works derived from the 00015 * input used in their production; they are not affected by this license. 00016 * 00017 */ 00018 00019 #ifndef _CPPVALUE_H 00020 #define _CPPVALUE_H 00021 00022 #include <stdio.h> 00023 #include <qglobal.h> 00024 00025 class CPPValue 00026 { 00027 public: 00028 00029 00030 enum Type { Int, Float }; 00031 00032 CPPValue(long val=0) : type(Int) { v.l = val; } 00033 CPPValue(double val) : type(Float) { v.d = val; } 00034 00035 operator double () const { return type==Int ? (double)v.l : v.d; } 00036 operator long () const { return type==Int ? v.l : (long)v.d; } 00037 00038 bool isInt() const { return type == Int; } 00039 00040 void print() const 00041 { 00042 if (type==Int) 00043 printf("(%ld)\n",v.l); 00044 else 00045 printf("(%f)\n",v.d); 00046 } 00047 00048 private: 00049 Type type; 00050 union { 00051 double d; 00052 long l; 00053 } v; 00054 }; 00055 00056 extern CPPValue parseOctal(); 00057 extern CPPValue parseDecimal(); 00058 extern CPPValue parseHexadecimal(); 00059 extern CPPValue parseCharacter(); 00060 extern CPPValue parseFloat(); 00061 00062 #endif