Renamed some of Get() methods to Find(), read more
From now on, ideally any function with "get" in the name should always return a valid value. A function with "find" in the name, however, does the same thing, but may also return an invalid result such as an error code.
This commit is contained in:
@@ -59,7 +59,7 @@ void TriggerManager::UnloadIf(std::function<bool(std::pair<const int, TriggerDat
|
||||
}
|
||||
}
|
||||
|
||||
TriggerData* TriggerManager::Get(int uid) {
|
||||
TriggerData* TriggerManager::Find(int uid) {
|
||||
std::map<int, TriggerData>::iterator it = elementMap.find(uid);
|
||||
|
||||
if (it == elementMap.end()) {
|
||||
@@ -69,7 +69,7 @@ TriggerData* TriggerManager::Get(int uid) {
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
TriggerData* TriggerManager::Get(std::string handle) {
|
||||
TriggerData* TriggerManager::Find(std::string handle) {
|
||||
for (std::map<int, TriggerData>::iterator it = elementMap.begin(); it != elementMap.end(); ++it) {
|
||||
if (it->second.GetHandle() == handle) {
|
||||
return &it->second;
|
||||
|
||||
@@ -44,8 +44,8 @@ public:
|
||||
void UnloadIf(std::function<bool(std::pair<const int, TriggerData const&>)> fn);
|
||||
|
||||
//accessors & mutators
|
||||
TriggerData* Get(int uid);
|
||||
TriggerData* Get(std::string handle);
|
||||
TriggerData* Find(int uid);
|
||||
TriggerData* Find(std::string handle);
|
||||
int GetLoadedCount();
|
||||
std::map<int, TriggerData>* GetContainer();
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ static int create(lua_State* L) {
|
||||
|
||||
//create the trigger
|
||||
int index = mgr->Create(lua_tostring(L, 2));
|
||||
TriggerData* triggerData = mgr->Get(index);
|
||||
TriggerData* triggerData = mgr->Find(index);
|
||||
|
||||
//origin
|
||||
if (lua_gettop(L) >= 4) {
|
||||
@@ -101,16 +101,16 @@ static int unload(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getTrigger(lua_State* L) {
|
||||
static int findTrigger(lua_State* L) {
|
||||
TriggerManager* mgr = static_cast<TriggerManager*>(lua_touserdata(L, 1));
|
||||
TriggerData* triggerData = nullptr;
|
||||
|
||||
switch(lua_type(L, 2)) {
|
||||
case LUA_TNUMBER:
|
||||
triggerData = mgr->Get(lua_tointeger(L, 2));
|
||||
triggerData = mgr->Find(lua_tointeger(L, 2));
|
||||
break;
|
||||
case LUA_TSTRING:
|
||||
triggerData = mgr->Get(lua_tostring(L, 2));
|
||||
triggerData = mgr->Find(lua_tostring(L, 2));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ static int getLoadedCount(lua_State* L) {
|
||||
static const luaL_Reg triggerManagerLib[] = {
|
||||
{"Create",create},
|
||||
{"Unload",unload},
|
||||
{"GetTrigger",getTrigger},
|
||||
{"FindTrigger",findTrigger},
|
||||
{"GetCount",getLoadedCount},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user