Permalink
Browse files

Merge branch 'master' of github.com:PongUIO/AndroidWars

  • Loading branch information...
TZer0 committed May 20, 2012
2 parents 846c969 + b94ed3d commit 7c73604b7e423daed1567296599cedbf146f83c0
Showing with 21 additions and 22 deletions.
  1. +8 −2 extsim/ExtBaseData.h
  2. +6 −13 extsim/ExtData.cpp
  3. +7 −7 extsim/ExtData.h
View
@@ -12,11 +12,16 @@
namespace ExtS {
class ExtSim;
+ struct NodeListener {
+ virtual void loadNode(DaScript::Node &node)=0;
+ virtual void postProcess()=0;
+ };
+
/**
* Base virtual class for processing and storing data.
*
*/
- class ExtBaseData {
+ class ExtBaseData : public NodeListener {
public:
ExtBaseData(ExtSim &sim) : mExtSim(&sim) {}
virtual ~ExtBaseData() {}
@@ -25,7 +30,6 @@ namespace ExtS {
virtual void shutdown()=0;
virtual void loadNode(DaScript::Node &node)=0;
-
virtual void postProcess()=0;
protected:
@@ -104,6 +108,8 @@ namespace ExtS {
Sim::DefaultDatabase<T>::getType(i)->postProcess(*mExtSim);
}
}
+
+ private:
};
/**
View
@@ -49,13 +49,13 @@ namespace ExtS {
if(daScr.getError().size()>0)
return;
- size_t nodeCount = daScr.getRoot().getNodeCount();
- for(size_t i=0; i<nodeCount; i++) {
+ for(size_t i=0, nc=daScr.getRoot().getNodeCount(); i<nc; i++) {
DaScript::Node &node = daScr.getRoot().getNode(i);
- ExtBaseData *listener = getListener(node.getId());
- if(listener)
- listener->loadNode(node);
+ ListenerMapPair lmp = mListeners.equal_range(node.getId());
+ for(ListenerMap::iterator i=lmp.first; i!=lmp.second; ++i) {
+ i->second.mData->loadNode(node);
+ }
}
}
@@ -73,14 +73,7 @@ namespace ExtS {
void ExtData::registerListener(const std::string& blockTag,
const Listener &listener)
- { mListeners[blockTag] = listener; }
-
- ExtBaseData* ExtData::getListener(const std::string& tag)
- {
- ListenerMap::iterator i=mListeners.find(tag);
- return (i==mListeners.end() || !(i->second.mContext&mCurrentContext)) ?
- 0 : i->second.mData;
- }
+ { mListeners.insert( std::make_pair(blockTag,listener) ); }
}
// Template implementations for DaScript
View
@@ -43,10 +43,10 @@ namespace ExtS {
};
struct Listener {
- Listener(ExtBaseData *data=0, ListenerContext context=LcNone) :
+ Listener(NodeListener *data=0, ListenerContext context=LcNone) :
mData(data), mContext(context) {}
- ExtBaseData *mData;
+ NodeListener *mData;
ListenerContext mContext;
};
@@ -66,6 +66,9 @@ namespace ExtS {
void postProcess();
void switchContext(ListenerContext ctx)
{ mCurrentContext = ctx; }
+
+ void registerListener(const std::string &blockTag,
+ const Listener &listener);
//@}
/// @name Database retrieval
@@ -79,10 +82,6 @@ namespace ExtS {
//@}
private:
- void registerListener(const std::string &blockTag,
- const Listener &listener);
- ExtBaseData *getListener(const std::string &tag);
-
/// @name Databases
//@{
#define _EXTS_X(type, name) type m##name;
@@ -92,7 +91,8 @@ namespace ExtS {
/// @name Internal
//@{
- typedef boost::unordered_map<std::string, Listener> ListenerMap;
+ typedef boost::unordered_multimap<std::string, Listener> ListenerMap;
+ typedef std::pair<ListenerMap::iterator,ListenerMap::iterator> ListenerMapPair;
ListenerMap mListeners;
ListenerContext mCurrentContext;

0 comments on commit 7c73604

Please sign in to comment.