Skip to main content

CPPValue Class

A class representing a C-preprocessor value. More...

Declaration​

class CPPValue { ... }

Included Headers​

#include <src/cppvalue.h>

Enumerations Index​

enumType { ... }

Public Constructors Index​

CPPValue (char c)
CPPValue (long val=0)
CPPValue (double val)

Public Operators Index​

operator double () const
operator long () const

Public Member Functions Index​

boolisInt () const
voidprint () const

Public Member Attributes Index​

doubled
longl

Private Member Attributes Index​

Typetype
union CPPValuev

Public Static Functions Index​

static CPPValueparseOctal (const std::string &token)
static CPPValueparseDecimal (const std::string &token)
static CPPValueparseHexadecimal (const std::string &token)
static CPPValueparseBinary (const std::string &token)
static CPPValueparseCharacter (const std::string &token)
static CPPValueparseFloat (const std::string &token)

Description​

A class representing a C-preprocessor value.

Definition at line 23 of file cppvalue.h.

Enumerations​

Type​

enum CPPValue::Type
Enumeration values
Int
Float

Definition at line 26 of file cppvalue.h.

26 enum Type { Int, Float };

Public Constructors​

CPPValue()​

CPPValue::CPPValue (char c)
inline explicit

Definition at line 28 of file cppvalue.h.

28 explicit CPPValue(char c) : type(Int) { v.l = c; }

References Int, type and v.

Referenced by parseBinary, parseCharacter, parseDecimal, parseFloat, parseHexadecimal and parseOctal.

CPPValue()​

CPPValue::CPPValue (long val=0)
inline explicit

Definition at line 29 of file cppvalue.h.

29 explicit CPPValue(long val=0) : type(Int) { v.l = val; }

References Int, type and v.

CPPValue()​

CPPValue::CPPValue (double val)
inline explicit

Definition at line 30 of file cppvalue.h.

30 explicit CPPValue(double val) : type(Float) { v.d = val; }

References Float, type and v.

Public Operators​

operator double()​

CPPValue::operator double ()
inline

Definition at line 32 of file cppvalue.h.

32 operator double () const { return type==Int ? static_cast<double>(v.l) : v.d; }

References Int, type and v.

operator long()​

CPPValue::operator long ()
inline

Definition at line 33 of file cppvalue.h.

33 operator long () const { return type==Int ? v.l : static_cast<long>(v.d); }

References Int, type and v.

Public Member Functions​

isInt()​

bool CPPValue::isInt ()
inline

Definition at line 35 of file cppvalue.h.

35 bool isInt() const { return type == Int; }

References Int and type.

print()​

void CPPValue::print ()
inline

Definition at line 37 of file cppvalue.h.

37 void print() const
38 {
39 if (type==Int)
40 printf("(%ld)\n",v.l);
41 else
42 printf("(%f)\n",v.d);
43 }

References Int, type and v.

Public Member Attributes​

d​

double CPPValue::d

Definition at line 54 of file cppvalue.h.

54 double d;

l​

long CPPValue::l

Definition at line 55 of file cppvalue.h.

55 long l;

Private Member Attributes​

type​

Type CPPValue::type

Definition at line 52 of file cppvalue.h.

Referenced by CPPValue, CPPValue, CPPValue, isInt, operator double, operator long and print.

v​

union CPPValue CPPValue::v

Definition at line 56 of file cppvalue.h.

Referenced by CPPValue, CPPValue, CPPValue, operator double, operator long and print.

Public Static Functions​

parseBinary()​

CPPValue CPPValue::parseBinary (const std::string & token)
static

Declaration at line 47 of file cppvalue.h, definition at line 54 of file cppvalue.cpp.

54CPPValue CPPValue::parseBinary(const std::string& token)
55{
56 long val = 0;
57 for (const char *p = token.c_str(); *p != 0; p++)
58 {
59 if (*p >= '0' && *p <= '1') val = val * 2 + *p - '0';
60 }
61 return CPPValue(val);
62}

Reference CPPValue.

parseCharacter()​

CPPValue CPPValue::parseCharacter (const std::string & token)
static

Declaration at line 48 of file cppvalue.h, definition at line 64 of file cppvalue.cpp.

64CPPValue CPPValue::parseCharacter(const std::string& token) // does not work for '\n' and the alike
65{
66 if (token[1]=='\\')
67 {
68 switch(token[2])
69 {
70 case 'n': return CPPValue('\n');
71 case 't': return CPPValue('\t');
72 case 'v': return CPPValue('\v');
73 case 'b': return CPPValue('\b');
74 case 'r': return CPPValue('\r');
75 case 'f': return CPPValue('\f');
76 case 'a': return CPPValue('\a');
77 case '\\': return CPPValue('\\');
78 case '?': return CPPValue('\?');
79 case '\'': return CPPValue('\'');
80 case '"': return CPPValue('"');
81 case '0': // fall through
82 case '1': // fall through
83 case '2': // fall through
84 case '3': // fall through
85 case '4': // fall through
86 case '5': // fall through
87 case '6': // fall through
88 case '7': // fall through
89 return parseOctal(token);
90 case 'x':
91 case 'X': return parseHexadecimal(token);
92 default: printf("Invalid escape sequence %s found!\n",token.c_str());
93 return CPPValue(0L);
94 }
95 }
96 return CPPValue(token[1]);
97}

References CPPValue, parseHexadecimal and parseOctal.

parseDecimal()​

CPPValue CPPValue::parseDecimal (const std::string & token)
static

Declaration at line 45 of file cppvalue.h, definition at line 31 of file cppvalue.cpp.

31CPPValue CPPValue::parseDecimal(const std::string& token)
32{
33 long val = 0;
34 for (const char *p = token.c_str(); *p != 0; p++)
35 {
36 if (*p >= '0' && *p <= '9') val = val * 10 + *p - '0';
37 }
38 return CPPValue(val);
39}

Reference CPPValue.

parseFloat()​

CPPValue CPPValue::parseFloat (const std::string & token)
static

Declaration at line 49 of file cppvalue.h, definition at line 99 of file cppvalue.cpp.

99CPPValue CPPValue::parseFloat(const std::string& token)
100{
101 return CPPValue(std::stod(token));
102}

Reference CPPValue.

parseHexadecimal()​

CPPValue CPPValue::parseHexadecimal (const std::string & token)
static

Declaration at line 46 of file cppvalue.h, definition at line 41 of file cppvalue.cpp.

41CPPValue CPPValue::parseHexadecimal(const std::string& token)
42{
43 long val = 0;
44 for (const char *p = token.c_str(); *p != 0; p++)
45 {
46 if (*p >= '0' && *p <= '9') val = val * 16 + *p - '0';
47 else if (*p >= 'a' && *p <= 'f') val = val * 16 + *p - 'a' + 10;
48 else if (*p >= 'A' && *p <= 'F') val = val * 16 + *p - 'A' + 10;
49 }
50 //printf("parseHexadecimal %s->%x\n",qPrint(token),val);
51 return CPPValue(val);
52}

Reference CPPValue.

Referenced by parseCharacter.

parseOctal()​

CPPValue CPPValue::parseOctal (const std::string & token)
static

Declaration at line 44 of file cppvalue.h, definition at line 21 of file cppvalue.cpp.

21CPPValue CPPValue::parseOctal(const std::string& token)
22{
23 long val = 0;
24 for (const char *p = token.c_str(); *p != 0; p++)
25 {
26 if (*p >= '0' && *p <= '7') val = val * 8 + *p - '0';
27 }
28 return CPPValue(val);
29}

Reference CPPValue.

Referenced by parseCharacter.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.14.0.