MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / getPrefixedDynamicDataField

Method getPrefixedDynamicDataField

Engine/source/console/simObject.cpp:1209–1255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1207//-----------------------------------------------------------------------------
1208
1209const char *SimObject::getPrefixedDynamicDataField(StringTableEntry fieldName, const char *_array, const S32 fieldType)
1210{
1211 // Sanity!
1212 AssertFatal(fieldName != NULL, "Cannot get field value with NULL field name.");
1213
1214 // Fetch field value.
1215 const char* pFieldValue = getDataField(fieldName, _array);
1216
1217 // Sanity.
1218 AssertFatal(pFieldValue != NULL, "Field value cannot be NULL.");
1219
1220 // Return the field if no field type is specified.
1221 if (fieldType == -1)
1222 return pFieldValue;
1223
1224 // Return without the prefix if there's no value.
1225 if (*pFieldValue == 0)
1226 return StringTable->EmptyString();
1227
1228 // Fetch the console base type.
1229 ConsoleBaseType* pConsoleBaseType = ConsoleBaseType::getType(fieldType);
1230
1231 // Did we find the console base type?
1232 if (pConsoleBaseType == NULL)
1233 {
1234 // No, so warn.
1235 Con::warnf("getPrefixedDynamicDataField() - Invalid field type '%d' specified for field '%s' with value '%s'.",
1236 fieldType, fieldName, pFieldValue);
1237 }
1238
1239 // Fetch the field prefix.
1240 StringTableEntry fieldPrefix = pConsoleBaseType->getTypePrefix();
1241
1242 // Sanity!
1243 AssertFatal(fieldPrefix != NULL, "Field prefix cannot be NULL.");
1244
1245 // Calculate a buffer size including prefix.
1246 const U32 valueBufferSize = dStrlen(fieldPrefix) + dStrlen(pFieldValue) + 1;
1247
1248 // Fetch a buffer.
1249 char* pValueBuffer = Con::getReturnBuffer(valueBufferSize);
1250
1251 // Format the value buffer.
1252 dSprintf(pValueBuffer, valueBufferSize, "%s%s", fieldPrefix, pFieldValue);
1253
1254 return pValueBuffer;
1255}
1256
1257//-----------------------------------------------------------------------------
1258

Callers

nothing calls this directly

Calls 7

getTypeFunction · 0.85
getReturnBufferFunction · 0.85
dSprintfFunction · 0.85
EmptyStringMethod · 0.80
getTypePrefixMethod · 0.80
warnfFunction · 0.70
dStrlenFunction · 0.50

Tested by

no test coverage detected