Skip to content

Commit 3803a08

Browse files
committed
Add operators for long
1 parent b204db8 commit 3803a08

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/JSONVar.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ JSONVar::JSONVar(int i) :
3939
*this = i;
4040
}
4141

42+
JSONVar::JSONVar(long l) :
43+
JSONVar()
44+
{
45+
*this = l;
46+
}
47+
4248
JSONVar::JSONVar(double d) :
4349
JSONVar()
4450
{
@@ -125,6 +131,11 @@ JSONVar::operator int() const
125131
return cJSON_IsNumber(_json) ? _json->valueint : 0;
126132
}
127133

134+
JSONVar::operator long() const
135+
{
136+
return cJSON_IsNumber(_json) ? _json->valueint : 0;
137+
}
138+
128139
JSONVar::operator double() const
129140
{
130141
return cJSON_IsNumber(_json) ? _json->valuedouble : NAN;
@@ -184,6 +195,11 @@ void JSONVar::operator=(int i)
184195
replaceJson(cJSON_CreateNumber(i));
185196
}
186197

198+
void JSONVar::operator=(long l)
199+
{
200+
replaceJson(cJSON_CreateNumber(l));
201+
}
202+
187203
void JSONVar::operator=(double d)
188204
{
189205
replaceJson(cJSON_CreateNumber(d));

src/JSONVar.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class JSONVar : public Printable {
3232
JSONVar();
3333
JSONVar(bool b);
3434
JSONVar(int i);
35+
JSONVar(long l);
3536
JSONVar(double d);
3637
JSONVar(const char* s);
3738
JSONVar(const String& s);
@@ -46,6 +47,7 @@ class JSONVar : public Printable {
4647

4748
operator bool() const;
4849
operator int() const;
50+
operator long() const;
4951
operator double() const;
5052
operator const char*() const;
5153

@@ -55,6 +57,7 @@ class JSONVar : public Printable {
5557
#endif
5658
void operator=(bool b);
5759
void operator=(int i);
60+
void operator=(long l);
5861
void operator=(double d);
5962
void operator=(const char* s);
6063
void operator=(const String& s);

0 commit comments

Comments
 (0)