MCPcopy Create free account
hub / github.com/carbonengine/trinity / RegisterVariableType

Method RegisterVariableType

trinity/Tr2VariableStore.cpp:401–438  ·  view source on GitHub ↗

------------------------------------------------------------- Description: Registers a new variable. If the variable with that name is already registered in this store then if its type is the same the variable is reused otherwise the error is logged and the function returns NULL. Arguments: name - Name of the new variable type - Type of the new variable Return Value: New variable (or old with the

Source from the content-addressed store, hash-verified

399// fails).
400// -------------------------------------------------------------
401TriVariable* Tr2VariableStore::RegisterVariableType( const char* name, TriVariableContentType type )
402{
403 TriVariable* var = FindLocalVariable( name );
404
405 if( var )
406 {
407 // Variable already exists, ensure type matches
408 TriVariableContentType existingType = var->GetType();
409 if( existingType == TRIVARIABLE_INVALID )
410 {
411 // Variable was just reserved, switch it to this type,
412 // it has enough allocated space
413 var->m_type = type;
414 }
415 else if( type == TRIVARIABLE_INVALID )
416 {
417 return var;
418 }
419 else if( type != existingType )
420 {
421 // Variable exists under a different type
422 CCP_LOGERR( "Attempting to register variable '%s' as '%s', already registered as '%s'", name, TriVariable::GetTypeName( type ), TriVariable::GetTypeName( existingType ) );
423 CCP_ASSERT( false );
424 var = NULL;
425 }
426 }
427 else
428 {
429 TriVariablePtr variable;
430 variable.CreateInstance();
431 var = variable;
432 var->m_type = type;
433 var->m_name = name;
434 m_variableMap[name] = var;
435 }
436
437 return var;
438}
439
440std::vector<std::string> Tr2VariableStore::GetLocalNames() const
441{

Callers

nothing calls this directly

Calls 3

GetTypeNameFunction · 0.85
CreateInstanceMethod · 0.80
GetTypeMethod · 0.45

Tested by

no test coverage detected