From 56b09bf912d2965744e2e78a30fc68d73ebe401c Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Tue, 12 Mar 2002 01:43:44 +0000 Subject: [PATCH] fixed some const/stl problems.. --- bs/bsdoc.cpp | 2 +- bs/bsdoc.h | 2 +- bs/bsview.cpp | 12 ++++++------ bs/fleet.cpp | 36 ++++++++++++++++++++++++++---------- bs/fleet.h | 11 +++++++---- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/bs/bsdoc.cpp b/bs/bsdoc.cpp index a782c08..e5504f9 100644 --- a/bs/bsdoc.cpp +++ b/bs/bsdoc.cpp @@ -68,7 +68,7 @@ int BSDoc::newBattle(QString name) ///////////////////////////////////////////////////////////////////////// // -std::map > >& BSDoc::Battles() +const std::map > >& BSDoc::Battles() const { return m_Battles; } diff --git a/bs/bsdoc.h b/bs/bsdoc.h index 5cf0001..d113f5b 100644 --- a/bs/bsdoc.h +++ b/bs/bsdoc.h @@ -58,7 +58,7 @@ class BSDoc : public QObject * change it. * \todo remove this, and replace it with a better more closed interface. */ - std::map > >& Battles(); + const std::map > >& Battles() const; signals: void documentChanged(); diff --git a/bs/bsview.cpp b/bs/bsview.cpp index ac969a3..78f8340 100644 --- a/bs/bsview.cpp +++ b/bs/bsview.cpp @@ -94,24 +94,24 @@ void BSView::slotDocumentChanged() { m_NumberView->clear(); - map > >& battles = m_doc->Battles(); + const map > >& battles = m_doc->Battles(); - for (map > >::iterator i = battles.begin(); i != battles.end(); i++) + for (map > >::const_iterator i = battles.begin(); i != battles.end(); ++i) { QString b = (*i).first; QListViewItem* battle = new QListViewItem(m_NumberView, b); - for (map >::iterator j = battles[b].begin(); j != battles[b].end(); j++) + for (map >::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::iterator k = battles[b][g].begin(); k != battles[b][g].end(); k++) + for (map::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)); } diff --git a/bs/fleet.cpp b/bs/fleet.cpp index a7ebe5c..a46a50a 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -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 >::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 >::iterator i = m_Fleet.begin(); i != m_Fleet.end(); i++) + for (map >::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 >& races) +void Fleet::setRaces(map >& races) { s_Races = races; } ////////////////////////////////////////////////////////////////////////// // -void Fleet::setUnits(map& units) +void Fleet::setUnits(map& units) { s_Units = units; for (map::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& units) } } +////////////////////////////////////////////////////////////////////////// +// +const map >& Fleet::Races() +{ + return s_Races; +} + +////////////////////////////////////////////////////////////////////////// +// +const map& Fleet::Units() +{ + return s_Units; +} + + + diff --git a/bs/fleet.h b/bs/fleet.h index b6aaecd..95c0c88 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -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 >& races); static void setUnits(std::map& units); + static const std::map >& Races(); + static const std::map& Units(); + protected: std::string m_sName; std::string m_sRace; -- 2.39.2