-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbaseVars.cpp
More file actions
55 lines (44 loc) · 1.08 KB
/
Copy pathbaseVars.cpp
File metadata and controls
55 lines (44 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// playing with class inheritance
// we want a system class to inherit variable things
// g++ -o baseVars baseVars.cpp -lcJSON
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>
#include <iostream>
#include <string>
#include <string.h>
#include <unordered_map>
#include <cJSON.h>
#include "mapVars.h"
using namespace std;
// Derived class
class SomeSystem: public mapVars {
public:
SomeSystem() {
model = NULL;
};
public:
const char *model;
float fval;
int ival;
};
int main() {
SomeSystem mySystem;
// This creates the mapVar object map
mySystem.addVar("model",&mySystem.model, "some model");
mySystem.addVar("fval",&mySystem.fval, 4.56);
mySystem.addVar("ival",&mySystem.ival, 2345);
mySystem.showVars();
cJSON * cj = mySystem.getCj();
char * foo = cJSON_Print(cj);
cout << " this is the cJson"<<endl;
cout << foo << endl;
mySystem.ival = 1234;
cout << " changed ival " << endl;
mySystem.showVars();
//next to parse a cJSON object
mySystem.parseCj(cj);
cout << " after parseCj " << endl;
mySystem.showVars();
return 0;
}