MCPcopy Create free account
hub / github.com/SmingHub/Sming / ArgRef

Class ArgRef

Sming/Core/Data/Stream/SectionTemplate.cpp:87–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85{
86public:
87 class ArgRef
88 {
89 public:
90 ArgRef(SectionTemplate& tmpl, Arg* arg) : tmpl(tmpl), arg(arg)
91 {
92 }
93
94 operator String() const
95 {
96 return toString();
97 }
98
99 String toString() const
100 {
101 if(arg == nullptr) {
102 return nullptr;
103 }
104
105 switch(arg->type) {
106 case Arg::Type::number:
107 case Arg::Type::string:
108 return static_cast<char*>(arg->ptr);
109 case Arg::Type::variable:
110 return tmpl.getValue(static_cast<const char*>(arg->ptr));
111 case Arg::Type::expression:
112 return *static_cast<String*>(arg->ptr);
113 default:
114 return nullptr;
115 }
116 }
117
118 char asChar() const
119 {
120 return (arg == nullptr) ? '\0' : *static_cast<char*>(arg->ptr);
121 }
122
123 int toInt() const
124 {
125 return toString().toInt();
126 }
127
128 float toFloat() const
129 {
130 return toString().toFloat();
131 }
132
133 int compare(const ArgRef& other) const
134 {
135 String s1 = toString();
136 String s2 = other.toString();
137 if(isNumber(s1.c_str())) {
138 return s1.toInt() - s2.toInt();
139 } else {
140 return s1.compareTo(s2);
141 }
142 }
143
144 String add(const ArgRef& other) const

Callers 1

operator[]Method · 0.85

Calls 1

toStringFunction · 0.70

Tested by

no test coverage detected