BWAPI
SPAR/AIModule/SparAIModule/DecisionMaking/Layer3Tactical/Interface/TechSet.h
Go to the documentation of this file.
00001 #pragma once
00002 #include "../../../PerceptualState/Techs/Tech.h"
00003 
00004 class TechSet
00005 {
00006 private:
00007   struct TechWrapper
00008   {
00009     TechWrapper(Tech* tech, unsigned int priority)
00010       : m_tech(tech)
00011       , m_priority(priority)
00012     {}
00013     Tech* m_tech;
00014     unsigned int m_priority;
00015     //stdext::hash_map<Tech*, TechWrapper>::iterator m_posInTechs;
00016     //std::multimap<unsigned int, TechWrapper*>::iterator m_posInTechsByPriority;
00017   };
00018   struct extract_tech : std::unary_function<const TechWrapper*, Tech*>
00019   {
00020     Tech* operator()(const TechWrapper* wrapper) const
00021     {
00022       return wrapper->m_tech;
00023     }
00024   };
00025 
00026 public:
00027   TechSet() {}
00028   TechSet(const TechSet& other)
00029   {
00030     for (stdext::hash_map<Tech*, TechWrapper>::const_iterator it = other.m_techs.begin(); it != other.m_techs.end(); ++it)
00031     {
00032       add(it->first, it->second.m_priority);
00033     }
00034   }
00035 
00036   bool add(Tech* tech, unsigned int priority)
00037   {
00038     std::pair<stdext::hash_map<Tech*, TechWrapper>::iterator, bool> resultInTechs = 
00039       m_techs.insert(std::make_pair(tech, TechWrapper(tech, priority)));
00040     if (resultInTechs.second)
00041     {
00042       TechWrapper& wrapper = resultInTechs.first->second;
00043 
00044       std::multimap<unsigned int, TechWrapper*>::iterator posInTechsByPriority = 
00045         m_techsByPriority.insert(std::make_pair(priority, &wrapper));
00046 
00047       //wrapper.m_posInTechs = resultInTechs.first;
00048       //wrapper.m_posInTechsByPriority = posInTechsByPriority;
00049     }
00050 
00051     return resultInTechs.second;
00052   }
00053 
00054   typedef boost::transform_iterator<composite_functor<extract_tech, extract_pair_second<std::multimap<unsigned int, TechWrapper*>::const_iterator::value_type>>,
00055                                     std::multimap<unsigned int, TechWrapper*>::const_iterator>
00056           const_iterator;
00057   const_iterator begin() const { return const_iterator(m_techsByPriority.begin()); }
00058   const_iterator end() const { return const_iterator(m_techsByPriority.end()); }
00059 
00060   TechSet& operator=(const TechSet& other)
00061   {
00062     m_techs.clear();
00063     m_techsByPriority.clear();
00064     for (stdext::hash_map<Tech*, TechWrapper>::const_iterator it = other.m_techs.begin(); it != other.m_techs.end(); ++it)
00065     {
00066       add(it->first, it->second.m_priority);
00067     }
00068     return *this;
00069   }
00070 
00071   bool operator==(const TechSet& other) const
00072   {
00073     return m_techsByPriority == other.m_techsByPriority;
00074   }
00075   bool operator!=(const TechSet& other) const
00076   {
00077     return m_techsByPriority != other.m_techsByPriority;
00078   }
00079 
00080 private:
00081   stdext::hash_map<Tech*, TechWrapper> m_techs;
00082   std::multimap<unsigned int, TechWrapper*> m_techsByPriority;
00083 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines