// If a variable is set onto a script, it sets an internal pointer to that script. // Later, when the variable destructs, if that pointer is set, it removes itself // from the script by calling this function. (Yes, this would be better with smart // pointers. C++11 here we come!) // void OTScript::RemoveVariable (OTVariable & theVar) { const std::string str_var_name = theVar.GetName().Get(); mapOfVariables::iterator it_var = m_mapVariables.find(str_var_name); if (it_var != m_mapVariables.end()) { m_mapVariables.erase(it_var); // no need to delete the variable pointer since the script doesn't own it anyway. } }
// Done bool OTVariable::Compare(OTVariable & rhs) { if (!(GetName().Compare(rhs.GetName()))) { OTLog::vOutput(0, "OTVariable::Compare: Names don't match: %s / %s \n", GetName().Get(), rhs.GetName().Get()); return false; } if ( ! (GetType() == rhs.GetType()) ) { OTLog::vOutput(0, "OTVariable::Compare: Type doesn't match: %s \n", GetName().Get()); return false; } if ( ! (GetAccess() == rhs.GetAccess()) ) { OTLog::vOutput(0, "OTVariable::Compare: Access types don't match: %s \n", GetName().Get()); return false; } // ------------------------------- bool bMatch = false; switch (GetType()) { case OTVariable::Var_Integer: bMatch = (GetValueInteger() == rhs.GetValueInteger()); break; case OTVariable::Var_Bool: bMatch = (GetValueBool() == rhs.GetValueBool()); break; case OTVariable::Var_String: bMatch = (GetValueString().compare(rhs.GetValueString()) == 0); break; default: OTLog::vError("OTVariable::Compare: Unknown type in variable %s.\n", m_strName.Get()); break; } return bMatch; }