Skip to content

Commit 3f6879b

Browse files
committed
more fixes to ObjectFactory
* implement removeAll() * exit early * remove typedef that's only used in one place and in private scope
1 parent 9b9318e commit 3f6879b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

cocos/base/ObjectFactory.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Ref* ObjectFactory::createObject(const std::string &name)
6565
if (t._fun != nullptr) {
6666
return t._fun();
6767
}
68-
else if (t._func != nullptr) {
68+
if (t._func != nullptr) {
6969
return t._func();
7070
}
7171
return nullptr;
@@ -76,4 +76,9 @@ void ObjectFactory::registerType(const TInfo &t)
7676
_typeMap.emplace(t._class, t);
7777
}
7878

79+
void ObjectFactory::removeAll()
80+
{
81+
_typeMap.clear();
82+
}
83+
7984
NS_CC_END

cocos/base/ObjectFactory.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ class CC_DLL ObjectFactory
4848
Instance _fun = nullptr;
4949
InstanceFunc _func;
5050
};
51-
typedef std::unordered_map<std::string, TInfo> FactoryMap;
5251

5352
static ObjectFactory* getInstance();
5453
static void destroyInstance();
55-
cocos2d::Ref* createObject(const std::string &name);
5654

55+
cocos2d::Ref* createObject(const std::string &name);
5756
void registerType(const TInfo &t);
5857
void removeAll();
5958

@@ -62,7 +61,7 @@ class CC_DLL ObjectFactory
6261
virtual ~ObjectFactory() = default;
6362
private:
6463
static ObjectFactory *_sharedFactory;
65-
FactoryMap _typeMap;
64+
std::unordered_map<std::string, TInfo> _typeMap;
6665
};
6766

6867
NS_CC_END

0 commit comments

Comments
 (0)