MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / setValueFromString

Function setValueFromString

Source/UserPrefs.cpp:44–85  ·  view source on GitHub ↗

Helper function to convert string to appropriate type and set the JSON value

Source from the content-addressed store, hash-verified

42
43// Helper function to convert string to appropriate type and set the JSON value
44void setValueFromString(Json::Value& element, const std::string& value)
45{
46 switch (element.type())
47 {
48 case Json::nullValue:
49 ofLog() << "Cannot update null value.";
50 break;
51 case Json::intValue:
52 element = std::stoi(value);
53 break;
54 case Json::uintValue:
55 element = static_cast<unsigned int>(std::stoul(value));
56 break;
57 case Json::realValue:
58 element = std::stod(value);
59 break;
60 case Json::stringValue:
61 element = value;
62 break;
63 case Json::booleanValue:
64 if (value == "true" || value == "1")
65 {
66 element = true;
67 }
68 else if (value == "false" || value == "0")
69 {
70 element = false;
71 }
72 else
73 {
74 ofLog() << "Invalid boolean value.";
75 }
76 break;
77 case Json::arrayValue:
78 case Json::objectValue:
79 ofLog() << "Cannot update array or object value with a single command-line parameter.";
80 break;
81 default:
82 ofLog() << "Unsupported JSON value type.";
83 break;
84 }
85}
86
87void UserPrefsHolder::Init()
88{

Callers 1

InitMethod · 0.85

Calls 1

ofLogClass · 0.85

Tested by

no test coverage detected