10Duke Enterprise C++ Client
Loading...
Searching...
No Matches
SimpleJSONNumber.h
1#ifndef TENDUKE_JSON_SIMPLEJSONNUMBER_H
2#define TENDUKE_JSON_SIMPLEJSONNUMBER_H
3
4#include "./SimpleJSONElement.h"
5#include "json/JSONNumber.h"
6
7#include <cmath>
8
9namespace tenduke { namespace json {
10
11class SimpleJSONNumber : public virtual ::tenduke::json::JSONNumber, public ::tenduke::json::SimpleJSONElement
12{
13public:
14 explicit SimpleJSONNumber(double value)
15 : SimpleJSONElement(::tenduke::json::JSONElement::NUMBER),
16 value(value)
17 {
18 }
19
20 double getValue() const override
21 {
22 return this->value;
23 }
24
25 std::string asJSON() const override
26 {
27 if (std::trunc(this->value) == this->value) {
28 return std::to_string(static_cast<std::int64_t>(this->value));
29 }
30 return std::to_string(this->value);
31 }
32
33private:
34 double value;
35};
36
37}} // tenduke
38
39#endif //TENDUKE_JSON_SIMPLEJSONNUMBER_H
Represents JSON number.
Definition JSONNumber.h:12
Definition SimpleJSONElement.h:11
std::string asJSON() const override
Serializes the element as JSON.
Definition SimpleJSONNumber.h:25
double getValue() const override
Returns the value.
Definition SimpleJSONNumber.h:20
JSON support.
Definition JSONArray.h:10
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4