]> ruin.nu Git - hbs.git/commitdiff
fixed some const/stl problems..
authorMichael Andreen <harv@ruin.nu>
Tue, 12 Mar 2002 01:43:44 +0000 (01:43 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 12 Mar 2002 01:43:44 +0000 (01:43 +0000)
bs/bsdoc.cpp
bs/bsdoc.h
bs/bsview.cpp
bs/fleet.cpp
bs/fleet.h

index a782c08412f9f8dcf1c70a9480cb84489feded9b..e5504f93d16d9e5c70cf8151b3effb44e91b3910 100644 (file)
@@ -68,7 +68,7 @@ int BSDoc::newBattle(QString name)
 /////////////////////////////////////////////////////////////////////////
 //
 
-std::map<QString, std::map<QString, std::map<QString, Fleet> > >& BSDoc::Battles()
+const std::map<QString, std::map<QString, std::map<QString, Fleet> > >& BSDoc::Battles() const
 {
        return m_Battles;
 }
index 5cf0001e33716fd8b5f7012bd88f6028ccbcdb2d..d113f5bc3df0effd22428ce91108654478778244 100644 (file)
@@ -58,7 +58,7 @@ class BSDoc : public QObject
         * change it.
         * \todo remove this, and replace it with a better more closed interface.
         */
-       std::map<QString, std::map<QString, std::map<QString, Fleet> > >& Battles();
+       const std::map<QString, std::map<QString, std::map<QString, Fleet> > >& Battles() const;
 
   signals:
     void documentChanged();
index ac969a3506c38bac22a96ac137fc45ed5bd4dc69..78f8340fe185bcc7568415518b190a0784e5cc7c 100644 (file)
@@ -94,24 +94,24 @@ void BSView::slotDocumentChanged()
 {
        m_NumberView->clear();
        
-       map<QString, map<QString, map<QString, Fleet> > >& battles = m_doc->Battles();  
+       const map<QString, map<QString, map<QString, Fleet> > >& battles = m_doc->Battles();    
 
-       for (map<QString, map<QString, map<QString, Fleet> > >::iterator i = battles.begin(); i != battles.end(); i++)
+       for (map<QString, map<QString, map<QString, Fleet> > >::const_iterator i = battles.begin(); i != battles.end(); ++i)
        {
                QString b = (*i).first;
                QListViewItem* battle = new QListViewItem(m_NumberView, b);
 
-               for (map<QString, map<QString, Fleet> >::iterator j = battles[b].begin(); j != battles[b].end(); j++)
+               for (map<QString, map<QString, Fleet> >::const_iterator j = i->second.begin(); j != i->second.end(); ++j)
                {
                        QString g = (*j).first;
                        QListViewItem* group = new QListViewItem(battle, g);
                        int groupShips = 0;
 
-                       for (map<QString, Fleet>::iterator k = battles[b][g].begin(); k != battles[b][g].end(); k++)
+                       for (map<QString, Fleet>::const_iterator k = j->second.begin(); k != j->second.end(); ++k)
                        {       
-                               int ships = battles[b][g][(*k).first].NumberOfShips();
+                               int ships = k->second.NumberOfShips();
                                groupShips += ships;
-                               (void) new QListViewItem(group, (*k).first, QString("%1").arg(ships), QString("%1").arg(battles[b][g][(*k).first].ETA()));
+                               (void) new QListViewItem(group, (*k).first, QString("%1").arg(ships), QString("%1").arg(k->second.ETA()));
                        }
                        group->setText(1, QString("%1").arg(groupShips));
                }
index a7ebe5cf0f7b610550b6c759ab1a0ea66aabe350..a46a50a2ad51944c28a979e45992f99748deecfa 100644 (file)
@@ -41,7 +41,7 @@ void Fleet::setName(string sName)
 
 //////////////////////////////////////////////////////////////////////////
 //
-string Fleet::Name()
+string Fleet::Name() const
 {
        return m_sName;
 }
@@ -52,7 +52,7 @@ string Fleet::Name()
  * s_Races and checks if it finds the race it returns true, if it reaches
  * the end without finding it it returns false.
  */
-bool Fleet::setRace(std::string sRace)
+bool Fleet::setRace(string sRace)
 {
        m_sRace = sRace;
        for (map<string, vector<int> >::iterator i = s_Races.begin(); i != s_Races.end(); i++)
@@ -65,7 +65,7 @@ bool Fleet::setRace(std::string sRace)
 
 //////////////////////////////////////////////////////////////////////////
 //
-string Fleet::Race()
+string Fleet::Race() const
 {
        return m_sRace;
 }
@@ -75,13 +75,13 @@ string Fleet::Race()
 /** This function iterates through m_Fleet and adds all numbers together to
  * produce a total.
  */
-int Fleet::NumberOfShips()
+int Fleet::NumberOfShips() const
 {
        int total = 0;
 
-       for (map<string, vector<int> >::iterator i = m_Fleet.begin(); i != m_Fleet.end(); i++)
+       for (map<string, vector<int> >::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
        {
-               total += m_Fleet[(*i).first][0];
+               total += i->second[0];
        }
 
        return total;
@@ -96,27 +96,27 @@ void Fleet::setETA(int eta)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int  Fleet::ETA()
+int  Fleet::ETA() const
 {
        return m_iETA;
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
-void Fleet::setRaces(std::map<std::string, std::vector<int> >& races)
+void Fleet::setRaces(map<string, vector<int> >& races)
 {
        s_Races = races;
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
-void Fleet::setUnits(map<std::string, UnitType>& units)
+void Fleet::setUnits(map<string, UnitType>& units)
 {
        s_Units = units;
 
        for (map<string, UnitType >::iterator i = s_Units.begin(); i != s_Units.end(); i++)
        {
-               cerr << s_Units[(*i).first].Name() << "\t"
+               cerr << s_Units[(*i).first].Name() << "\t\t"
                        << s_Units[(*i).first].Race() <<"\t"
                        << s_Units[(*i).first].Class() << "\t"
                        << s_Units[(*i).first].Target(0) << "\t"
@@ -136,3 +136,19 @@ void Fleet::setUnits(map<std::string, UnitType>& units)
        }
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
+const map<string, vector<int> >& Fleet::Races()
+{
+       return s_Races;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+const map<string, UnitType>& Fleet::Units()
+{
+       return s_Units;
+}
+
+
+
index b6aaecd429ab85d31775f5777fba78feb9545a39..95c0c88dffbe53a779afd3557951cc24df045b3e 100644 (file)
@@ -45,7 +45,7 @@ public:
        /**Returns the name of this fleet.
         * \see setName
         */
-       std::string Name();
+       std::string Name() const;
 
        /**The race string decides what type of ships this fleet can have.
         * The values must be feeded into this class.
@@ -58,11 +58,11 @@ public:
         * \return The race, represented as a string.
         * \see setRace
         */
-       std::string Race();
+       std::string Race() const;
 
        /**Returns the total number of ships in this fleet
         */
-       int NumberOfShips();
+       int NumberOfShips() const;
 
        /**Sets the estimated time of arrival. The time as a single integer,
         * in relation to the current time. For example if the current time is
@@ -71,11 +71,14 @@ public:
        void setETA(int eta);
        /**Return the estimated time of arrival. It's counted from the current time (tick).
         */
-       int  ETA();
+       int  ETA() const;
 
        static void setRaces(std::map<std::string, std::vector<int> >& races);
        static void setUnits(std::map<std::string, UnitType>& units);
 
+       static const std::map<std::string, std::vector<int> >& Races();
+       static const std::map<std::string, UnitType>& Units();
+
 protected:
        std::string     m_sName;
        std::string     m_sRace;