Doxygen
Loading...
Searching...
No Matches
cppvalue.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2021 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16#ifndef CPPVALUE_H
17#define CPPVALUE_H
18
19#include <cstdio>
20#include <string>
21
22/** A class representing a C-preprocessor value. */
24{
25 public:
26 enum Type { Int, Float };
27
28 explicit CPPValue(char c) : type(Int) { v.l = c; }
29 explicit CPPValue(long val=0) : type(Int) { v.l = val; }
30 explicit CPPValue(double val) : type(Float) { v.d = val; }
31
32 operator double () const { return type==Int ? static_cast<double>(v.l) : v.d; }
33 operator long () const { return type==Int ? v.l : static_cast<long>(v.d); }
34
35 bool isInt() const { return type == Int; }
36
37 void print() const
38 {
39 if (type==Int)
40 printf("(%ld)\n",v.l);
41 else
42 printf("(%f)\n",v.d);
43 }
44 static CPPValue parseOctal(const std::string& token);
45 static CPPValue parseDecimal(const std::string& token);
46 static CPPValue parseHexadecimal(const std::string& token);
47 static CPPValue parseBinary(const std::string& token);
48 static CPPValue parseCharacter(const std::string& token);
49 static CPPValue parseFloat(const std::string& token);
50
51 private:
53 union {
54 double d;
55 long l;
56 } v;
57};
58
59
60#endif
static CPPValue parseOctal(const std::string &token)
Definition cppvalue.cpp:21
double d
Definition cppvalue.h:54
union CPPValue::@026105325157306004343225305026272177106174241033 v
void print() const
Definition cppvalue.h:37
bool isInt() const
Definition cppvalue.h:35
static CPPValue parseDecimal(const std::string &token)
Definition cppvalue.cpp:31
CPPValue(char c)
Definition cppvalue.h:28
CPPValue(double val)
Definition cppvalue.h:30
long l
Definition cppvalue.h:55
static CPPValue parseHexadecimal(const std::string &token)
Definition cppvalue.cpp:41
static CPPValue parseCharacter(const std::string &token)
Definition cppvalue.cpp:64
static CPPValue parseFloat(const std::string &token)
Definition cppvalue.cpp:99
static CPPValue parseBinary(const std::string &token)
Definition cppvalue.cpp:54
CPPValue(long val=0)
Definition cppvalue.h:29
Type type
Definition cppvalue.h:52