GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/variabledata.h Lines: 25 25 100.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2010  The Mana Developers
4
 *  Copyright (C) 2011-2017  The ManaPlus Developers
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#ifndef VARIABLEDATA_H
23
#define VARIABLEDATA_H
24
25
#include <string>
26
27
#include "localconsts.h"
28
29
class VariableData notfinal
30
{
31
    public:
32
        enum DataType
33
        {
34
            DATA_NONE = 0,
35
            DATA_INT,
36
            DATA_STRING,
37
            DATA_FLOAT,
38
            DATA_BOOL
39
        };
40
41
        VariableData()
42
411302
        { }
43
44
        A_DELETE_COPY(VariableData)
45
46
        virtual ~VariableData()
47
        {}
48
49
        virtual int getType() const A_WARN_UNUSED = 0;
50
};
51
52
106290
class IntData final : public VariableData
53
{
54
    public:
55
106290
        explicit IntData(const int value) :
56
            VariableData(),
57
212580
            mData(value)
58
        { }
59
60
        A_DELETE_COPY(IntData)
61
62
        int getData() const noexcept2 A_WARN_UNUSED
63
2387
        { return mData; }
64
65
2387
        int getType() const override final A_WARN_UNUSED
66
2387
        { return DATA_INT; }
67
68
    private:
69
        int mData;
70
};
71
72
202608
class StringData final : public VariableData
73
{
74
    public:
75
101304
        explicit StringData(const std::string &value) :
76
            VariableData(),
77
303912
            mData(value)
78
        { }
79
80
        A_DELETE_COPY(StringData)
81
82
        const std::string &getData() const noexcept2 A_WARN_UNUSED
83
6917
        { return mData; }
84
85
6921
        int getType() const override final A_WARN_UNUSED
86
6921
        { return DATA_STRING; }
87
88
    private:
89
        std::string mData;
90
};
91
92
2536
class FloatData final : public VariableData
93
{
94
    public:
95
2536
        explicit FloatData(const double value) :
96
            VariableData(),
97
5072
            mData(value)
98
        { }
99
100
        A_DELETE_COPY(FloatData)
101
102
        double getData() const noexcept2 A_WARN_UNUSED
103
118
        { return mData; }
104
105
118
        int getType() const override final A_WARN_UNUSED
106
118
        { return DATA_FLOAT; }
107
108
    private:
109
        double mData;
110
};
111
112
201172
class BoolData final : public VariableData
113
{
114
    public:
115
201172
        explicit BoolData(const bool value) :
116
            VariableData(),
117
402344
            mData(value)
118
        { }
119
120
        A_DELETE_COPY(BoolData)
121
122
        bool getData() const noexcept2 A_WARN_UNUSED
123
4753
        { return mData; }
124
125
4753
        int getType() const override final A_WARN_UNUSED
126
4753
        { return DATA_BOOL; }
127
128
    private:
129
        bool mData;
130
};
131
132
#endif  // VARIABLEDATA_H