Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/system/ComponentManager.cpp
Show All 26 Lines | |||||
#include "scriptinterface/FunctionWrapper.h" | #include "scriptinterface/FunctionWrapper.h" | ||||
#include "simulation2/components/ICmpTemplateManager.h" | #include "simulation2/components/ICmpTemplateManager.h" | ||||
#include "simulation2/MessageTypes.h" | #include "simulation2/MessageTypes.h" | ||||
#include "simulation2/system/DynamicSubscription.h" | #include "simulation2/system/DynamicSubscription.h" | ||||
#include "simulation2/system/IComponent.h" | #include "simulation2/system/IComponent.h" | ||||
#include "simulation2/system/ParamNode.h" | #include "simulation2/system/ParamNode.h" | ||||
#include "simulation2/system/SimContext.h" | #include "simulation2/system/SimContext.h" | ||||
#include <string_view> | |||||
/** | /** | ||||
* Used for script-only message types. | * Used for script-only message types. | ||||
*/ | */ | ||||
class CMessageScripted final : public CMessage | class CMessageScripted final : public CMessage | ||||
{ | { | ||||
public: | public: | ||||
virtual int GetType() const { return mtid; } | virtual int GetType() const { return mtid; } | ||||
virtual const char* GetScriptHandlerName() const { return handlerName.c_str(); } | virtual const char* GetScriptHandlerName() const { return handlerName.c_str(); } | ||||
▲ Show 20 Lines • Show All 225 Lines • ▼ Show 20 Lines | void CComponentManager::Script_RegisterComponentType_Common(int iid, const std::string& cname, JS::HandleValue ctor, bool reRegister, bool systemComponent) | ||||
std::vector<std::string> methods; | std::vector<std::string> methods; | ||||
if (!Script::EnumeratePropertyNames(rq, protoVal, false, methods)) | if (!Script::EnumeratePropertyNames(rq, protoVal, false, methods)) | ||||
{ | { | ||||
ScriptException::Raise(rq, "Failed to enumerate component properties."); | ScriptException::Raise(rq, "Failed to enumerate component properties."); | ||||
return; | return; | ||||
} | } | ||||
for (std::vector<std::string>::const_iterator it = methods.begin(); it != methods.end(); ++it) | for (const std::string& method : methods) | ||||
{ | { | ||||
// TODO C++17: string_view | if (std::string_view{method}.substr(0, 2) != "On") | ||||
Stan: Is the compiler smart enough to inline all those string_view creations? | |||||
if (strncmp((it->c_str()), "On", 2) != 0) | |||||
continue; | continue; | ||||
std::string name = (*it).substr(2); // strip the "On" prefix | std::string_view name{std::string_view{method}.substr(2)}; // strip the "On" prefix | ||||
// Handle "OnGlobalFoo" functions specially | // Handle "OnGlobalFoo" functions specially | ||||
bool isGlobal = false; | bool isGlobal = false; | ||||
if (strncmp(name.c_str(), "Global", 6) == 0) | if (std::string_view{name}.substr(0, 6) == "Global") | ||||
{ | { | ||||
isGlobal = true; | isGlobal = true; | ||||
name = name.substr(6); | name.remove_prefix(6); | ||||
} | } | ||||
std::map<std::string, MessageTypeId>::const_iterator mit = m_MessageTypeIdsByName.find(name); | auto mit = m_MessageTypeIdsByName.find(std::string{name}); | ||||
Not Done Inline ActionsIt's possible to search by std::string_view with some modifications. But might be done in separate patch. vladislavbelov: It's possible to search by `std::string_view` with some modifications. But might be done in… | |||||
if (mit == m_MessageTypeIdsByName.end()) | if (mit == m_MessageTypeIdsByName.end()) | ||||
{ | { | ||||
ScriptException::Raise(rq, "Registered component has unrecognized '%s' message handler method", it->c_str()); | ScriptException::Raise(rq, "Registered component has unrecognized '%s' message " | ||||
"handler method", method.c_str()); | |||||
return; | return; | ||||
Done Inline ActionsMoving the whole text on the new line should be enough. vladislavbelov: Moving the whole text on the new line should be enough. | |||||
} | } | ||||
if (isGlobal) | if (isGlobal) | ||||
SubscribeGloballyToMessageType(mit->second); | SubscribeGloballyToMessageType(mit->second); | ||||
else | else | ||||
SubscribeToMessageType(mit->second); | SubscribeToMessageType(mit->second); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 491 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Is the compiler smart enough to inline all those string_view creations?