From: Pino Toscano Date: Sat, 3 Mar 2007 22:28:11 +0000 (+0000) Subject: API cleanup: don't use byref return values when not necessary, pass by constref when... X-Git-Tag: v3.90.1~44 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=c49e6f04f5f907f18644caf165c3f532eaeaad4a;p=libqmvoc.git API cleanup: don't use byref return values when not necessary, pass by constref when necessary, add const overloads for some methods, etc svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=638975 --- diff --git a/kdeeducore/leitnerbox.cpp b/kdeeducore/leitnerbox.cpp index eef1e5d..83453ef 100644 --- a/kdeeducore/leitnerbox.cpp +++ b/kdeeducore/leitnerbox.cpp @@ -40,11 +40,21 @@ LeitnerBox* LeitnerBox::correctWordBox() return m_correctWordBox; } +const LeitnerBox* LeitnerBox::correctWordBox() const +{ + return m_correctWordBox; +} + LeitnerBox* LeitnerBox::wrongWordBox() { return m_wrongWordBox; } +const LeitnerBox* LeitnerBox::wrongWordBox() const +{ + return m_wrongWordBox; +} + void LeitnerBox::setBoxName( const QString& name ) { m_name = name; diff --git a/kdeeducore/leitnerbox.h b/kdeeducore/leitnerbox.h index 7e74413..03733a3 100644 --- a/kdeeducore/leitnerbox.h +++ b/kdeeducore/leitnerbox.h @@ -89,12 +89,16 @@ public: */ LeitnerBox* correctWordBox(); + const LeitnerBox* correctWordBox() const; + /** * Returns a pointer to the LeitnerBox wrong cards of this LeitnerBox here are assigned to * @return a pointer to a LeitnerBox */ LeitnerBox* wrongWordBox(); + const LeitnerBox* wrongWordBox() const; + bool operator == ( const LeitnerBox& a ) const; private: diff --git a/kdeeducore/leitnersystem.cpp b/kdeeducore/leitnersystem.cpp index 0533d60..4ad884a 100644 --- a/kdeeducore/leitnersystem.cpp +++ b/kdeeducore/leitnersystem.cpp @@ -50,6 +50,11 @@ LeitnerBox* LeitnerSystem::boxWithNumber( int number ) return &m_boxes[ number ]; } +const LeitnerBox* LeitnerSystem::boxWithNumber( int number ) const +{ + return &m_boxes.at( number ); +} + LeitnerBox* LeitnerSystem::boxWithName( const QString& name ) { QList::iterator it, it2; @@ -64,12 +69,26 @@ LeitnerBox* LeitnerSystem::boxWithName( const QString& name ) return 0; } -QString& LeitnerSystem::systemName() +const LeitnerBox* LeitnerSystem::boxWithName( const QString& name ) const +{ + QList::const_iterator it, it2; + it = m_boxes.begin(); + it2 = m_boxes.end(); + for ( ; it != it2; ++it) + { + if ( (*it).boxName() == name ) + return &(*it); + } + + return 0; +} + +QString LeitnerSystem::systemName() const { return m_systemName; } -QString LeitnerSystem::nextBox( QString& previousBox ) +QString LeitnerSystem::nextBox( const QString& previousBox ) { for( int i = 0; i < m_boxes.count(); i++ ) { @@ -80,32 +99,32 @@ QString LeitnerSystem::nextBox( QString& previousBox ) return QString(); } -const QString& LeitnerSystem::correctBox( int box ) +QString LeitnerSystem::correctBox( int box ) const { return m_boxes[ box ].correctWordBox()->boxName(); } -const QString& LeitnerSystem::wrongBox( int box ) +QString LeitnerSystem::wrongBox( int box ) const { return m_boxes[ box ].wrongWordBox()->boxName(); } -const QString& LeitnerSystem::correctBox( QString& box ) +QString LeitnerSystem::correctBox( const QString& box ) const { return boxWithName( box )->correctWordBox()->boxName(); } -const QString& LeitnerSystem::wrongBox( QString& box ) +QString LeitnerSystem::wrongBox( const QString& box ) const { return boxWithName( box )->wrongWordBox()->boxName(); } -int LeitnerSystem::wrongBoxNumber( int box ) +int LeitnerSystem::wrongBoxNumber( int box ) const { return number( m_boxes[ box ].wrongWordBox() ); } -int LeitnerSystem::correctBoxNumber( int box ) +int LeitnerSystem::correctBoxNumber( int box ) const { return number( m_boxes[ box ].correctWordBox() ); } @@ -148,7 +167,7 @@ void LeitnerSystem::setSystemName( const QString& name ) m_systemName = name; } -int LeitnerSystem::number( LeitnerBox* box ) const +int LeitnerSystem::number( const LeitnerBox* box ) const { if( box == 0 ) return -1; @@ -202,9 +221,9 @@ void LeitnerSystem::setWrongBox( const QString& box, const QString& wrongWordBox boxWithName( box )->setWrongWordBox( boxWithName( wrongWordBox ) ); } -const QString& LeitnerSystem::box( int i ) const +QString LeitnerSystem::box( int i ) const { - return m_boxes[ i ].boxName(); + return m_boxes.at( i ).boxName(); } void LeitnerSystem::setBoxVocabCount( QString& box, int vocabCount ) @@ -217,13 +236,13 @@ int LeitnerSystem::boxVocabCount( QString& box ) return boxWithName( box )->vocabCount(); } -void LeitnerSystem::incrementBoxVocabCount( QString& box ) +void LeitnerSystem::incrementBoxVocabCount( const QString& box ) { int tmp = boxWithName( box )->vocabCount(); boxWithName( box )->setVocabCount( tmp++ ); } -void LeitnerSystem::decrementBoxVocabCount( QString& box ) +void LeitnerSystem::decrementBoxVocabCount( const QString& box ) { int tmp = boxWithName( box )->vocabCount(); boxWithName( box )->setVocabCount( tmp-- ); diff --git a/kdeeducore/leitnersystem.h b/kdeeducore/leitnersystem.h index 4bd7f7a..18a4776 100644 --- a/kdeeducore/leitnersystem.h +++ b/kdeeducore/leitnersystem.h @@ -28,7 +28,7 @@ class KDEEDUCORE_EXPORT LeitnerSystem { public: /**Constructor without arguments*/ - LeitnerSystem(); + explicit LeitnerSystem(); /**Constructor with arguments * @param boxes reference to a QList of LeitnerBox @@ -52,7 +52,7 @@ public: /**Returns the LeitnerSystem's name * @return the LeitnerSystem's name as reference to QString */ - QString& systemName(); + QString systemName() const; /**Sets the LeitnerSystem's name * @@ -66,6 +66,8 @@ public: */ LeitnerBox* boxWithNumber( int number ); + const LeitnerBox* boxWithNumber( int number ) const; + /**Returns a LeitnerBox by name * @param name the name of the LeitnerBox to be returned * @return a pointer to the LeitnerBox with the name, @@ -73,31 +75,37 @@ public: */ LeitnerBox* boxWithName( const QString& name ); + const LeitnerBox* boxWithName( const QString& name ) const; + /**Returns the number of the given LeitnerBox * @param box a pointer to the LeitnerBox * @return the number of the given LeitnerBox */ - int number( LeitnerBox* box ) const; + int number( const LeitnerBox* box ) const; /**Returns the name of the LeitnerBox with number @p i * @param i the LeitnerBox's number * @return the name of the LeitnerBox with number @p i */ - const QString& box( int i ) const; + QString box( int i ) const; /**Returns the LeitnerBox following @p previousBox * @param previousBox the name of the LeitnerBox * @return the name of the LeitnerBox following previousBox */ - QString nextBox( QString& previousBox ); + QString nextBox( const QString& previousBox ); - const QString& correctBox( int box ); //returns the correct word box of "int box" - const QString& wrongBox( int box ); //returns the wrong word box of "int box" - const QString& correctBox( QString& box ); - const QString& wrongBox( QString& box ); + /**Returns the correct word box of "int box" + */ + QString correctBox( int box ) const; + /**Returns the wrong word box of "int box" + */ + QString wrongBox( int box ) const; + QString correctBox( const QString& box ) const; + QString wrongBox( const QString& box ) const; - int wrongBoxNumber( int box ); - int correctBoxNumber( int box ); + int wrongBoxNumber( int box ) const; + int correctBoxNumber( int box ) const; void setCorrectBox( const QString& box, const QString& correctWordBox ); void setWrongBox( const QString& box, const QString& wrongWordBox ); @@ -108,8 +116,8 @@ public: void setBoxVocabCount( QString& box, int vocabCount ); int boxVocabCount( QString& box ); - void incrementBoxVocabCount( QString& box ); - void decrementBoxVocabCount( QString& box ); + void incrementBoxVocabCount( const QString& box ); + void decrementBoxVocabCount( const QString& box ); //inserts a box with number, name, correct and wrong word box bool insertBox( const QString& name, int correctWordBox, int wrongWordBox );