Doxygen
Toggle main menu visibility
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. */
23
class
CPPValue
24
{
25
public
:
26
enum class
Type
{
Int
,
Float
};
27
28
explicit
constexpr
CPPValue
(
char
c) noexcept :
m_type
(
Type::Int
),
m_d
(0.0),
m_l
(c) {}
29
explicit
constexpr
CPPValue
(
long
val=0) noexcept :
m_type
(
Type
::
Int
),
m_d
(0.0),
m_l
(val) {}
30
explicit
constexpr
CPPValue
(
double
val) noexcept :
m_type
(
Type::Float
),
m_d
(val),
m_l
(0) {}
31
32
constexpr
operator
double () const noexcept {
return
m_type
==
Type::Int
?
static_cast<
double
>
(
m_l
) :
m_d
; }
33
constexpr
operator
long () const noexcept {
return
m_type
==
Type::Int
?
m_l
:
static_cast<
long
>
(
m_d
); }
34
35
constexpr
Type
type
() const noexcept {
return
m_type
; }
36
37
void
print
()
const
38
{
39
if
(
m_type
==
Type::Int
)
40
printf(
"(%ld)\n"
,
m_l
);
41
else
42
printf(
"(%f)\n"
,
m_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
:
52
Type
m_type
;
53
double
m_d
;
54
long
m_l
;
55
};
56
57
58
#endif
CPPValue
A class representing a C-preprocessor value.
Definition
cppvalue.h:24
CPPValue::CPPValue
constexpr CPPValue(double val) noexcept
Definition
cppvalue.h:30
CPPValue::Type
Type
Definition
cppvalue.h:26
CPPValue::Type::Int
@ Int
Definition
cppvalue.h:26
CPPValue::Type::Float
@ Float
Definition
cppvalue.h:26
CPPValue::CPPValue
constexpr CPPValue(char c) noexcept
Definition
cppvalue.h:28
CPPValue::parseOctal
static CPPValue parseOctal(const std::string &token)
Definition
cppvalue.cpp:22
CPPValue::print
void print() const
Definition
cppvalue.h:37
CPPValue::type
constexpr Type type() const noexcept
Definition
cppvalue.h:35
CPPValue::m_type
Type m_type
Definition
cppvalue.h:52
CPPValue::m_l
long m_l
Definition
cppvalue.h:54
CPPValue::parseDecimal
static CPPValue parseDecimal(const std::string &token)
Definition
cppvalue.cpp:32
CPPValue::CPPValue
constexpr CPPValue(long val=0) noexcept
Definition
cppvalue.h:29
CPPValue::m_d
double m_d
Definition
cppvalue.h:53
CPPValue::parseHexadecimal
static CPPValue parseHexadecimal(const std::string &token)
Definition
cppvalue.cpp:42
CPPValue::parseCharacter
static CPPValue parseCharacter(const std::string &token)
Definition
cppvalue.cpp:65
CPPValue::parseFloat
static CPPValue parseFloat(const std::string &token)
Definition
cppvalue.cpp:102
CPPValue::parseBinary
static CPPValue parseBinary(const std::string &token)
Definition
cppvalue.cpp:55
src
cppvalue.h
Generated by
1.17.0