use map instead of unordered_map
authorKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 15 Aug 2012 20:55:03 +0000 (13:55 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 15 Aug 2012 20:55:03 +0000 (13:55 -0700)
ambd/core.cpp
ambd/core.h
lib/vehicleproperty.cpp
lib/vehicleproperty.h

index 223aaf8..ada481d 100644 (file)
@@ -20,6 +20,7 @@
 #include "core.h"
 #include <functional>
 #include "listplusplus.h"
+#include "debugout.h"
 
 using namespace std::placeholders;
 
@@ -28,6 +29,12 @@ Core::Core()
        
 }
 
+Core::~Core()
+{
+
+}
+
+
 void Core::setSupported(PropertyList supported, AbstractSource* source)
 {
        mSources.push_back(source);
@@ -63,7 +70,7 @@ void Core::updateSupported(PropertyList added, PropertyList removed)
        
        /// iterate through subscribed properties and resubscribe.  This catches newly supported properties in the process.
        
-       for(unordered_map<VehicleProperty::Property, SinkList>::iterator itr = propertySinkMap.begin(); itr != propertySinkMap.end(); itr++)
+       for(map<VehicleProperty::Property, SinkList>::iterator itr = propertySinkMap.begin(); itr != propertySinkMap.end(); itr++)
        {
                VehicleProperty::Property  property = (*itr).first;
                
@@ -91,12 +98,20 @@ void Core::setProperty(VehicleProperty::Property , boost::any )
 
 void Core::subscribeToProperty(VehicleProperty::Property property, AbstractSink* self)
 {
+       if(propertySinkMap.find(property) == propertySinkMap.end())
+       {
+               DebugOut()<<__FUNCTION__<<"property not supported: "<<VehicleProperty::name(property);
+               return; 
+       }
+       
        SinkList list = propertySinkMap[property];
        
        if(!ListPlusPlus<AbstractSink*>(&list).contains(self))
        {
                list.push_back(self);
        }
+       
+       
 }
 
 void Core::unsubscribeToProperty(VehicleProperty::Property , AbstractSink* self)
index 0ee4cea..282fd19 100644 (file)
 #include "abstractsource.h"
 #include "abstractroutingengine.h"
 
-#include <unordered_map>
+#include <map>
 
 class Core: public AbstractRoutingEngine
 {
-
+       
 public:
        Core();
         
@@ -44,13 +44,16 @@ public:
        void subscribeToProperty(VehicleProperty::Property, AbstractSink* self);
        void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self);
     
+protected: 
+       ~Core();
+       
 private:
        PropertyList mMasterPropertyList;
        
        SourceList mSources;
        SinkList mSinks;
        
-       unordered_map<VehicleProperty::Property, SinkList> propertySinkMap;
+       std::map<VehicleProperty::Property, SinkList> propertySinkMap;
     
 };
 
index e995aa9..5c19451 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "vehicleproperty.h"
 
+using namespace std;
+
 VehicleProperty::VehicleProperty()
 {
 
index 8eed19e..258fcfa 100644 (file)
 #include <string>
 #include <list>
 
-using namespace std;
+
 
 class VehicleProperty
 {
 
 public:
+       
 
        VehicleProperty();
 
@@ -39,11 +40,11 @@ public:
                EngineSpeed
        };
 
-       static string name(Property prop);
-       static Property value(string name);
+       static std::string name(Property prop);
+       static Property value(std::string name);
     
 };
 
-typedef list<VehicleProperty::Property> PropertyList;
+typedef std::list<VehicleProperty::Property> PropertyList;
 
 #endif // VEHICLEPROPERTY_H