MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / get_var_value

Method get_var_value

erpcgen/src/cpptemplate/cpptempl.cpp:1114–1235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1112// args ::= "(" [ expr ( "," expr )* ")"
1113
1114data_ptr ExprParser::get_var_value(const std::string &path, data_list &params)
1115{
1116 // Check if this is a pseudo function.
1117 bool is_fn = false;
1118 if (path == "count" || path == "empty" || path == "defined" || path == "addIndent" || path == "int" ||
1119 path == "str" || path == "upper" || path == "lower" || path == "capitalize" || path == "dump")
1120 {
1121 is_fn = true;
1122 }
1123
1124 try
1125 {
1126 data_ptr result;
1127 if (is_fn)
1128 {
1129 if (params.size() != 1 && path != "addIndent")
1130 {
1131 throw TemplateException("function " + path + " requires 1 parameter");
1132 }
1133 else if (params.size() != 2 && path == "addIndent")
1134 {
1135 throw TemplateException("function " + path + " requires 2 parameters");
1136 }
1137
1138 if (path == "count")
1139 {
1140 result = params[0]->getlist().size();
1141 }
1142 else if (path == "empty")
1143 {
1144 result = params[0]->empty();
1145 }
1146 else if (path == "defined")
1147 {
1148 // TODO: handle undefined case for defined fn
1149 result = true;
1150 }
1151 else if (path == "addIndent")
1152 {
1153 std::stringstream ss(params[1]->getvalue());
1154 if (!ss.eof())
1155 {
1156 std::string line;
1157 std::string resultValue;
1158 int c = 0;
1159 while (std::getline(ss, line))
1160 {
1161 ++c;
1162 if (c > 1)
1163 {
1164 resultValue += '\n';
1165 }
1166 if (line.size() > 0 && line[0] != '\r' && line[0] != '\n')
1167 {
1168 resultValue += params[0]->getvalue() + line;
1169 }
1170 }
1171 result = resultValue;

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.80

Calls 11

TemplateExceptionClass · 0.85
dump_dataFunction · 0.85
getvalueMethod · 0.80
getintMethod · 0.80
is_templateMethod · 0.80
evalMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.64