Skip to content

Commit

Permalink
ViewHistory: Fix ArticleBase::get_current_url() to const member (#278)
Browse files Browse the repository at this point in the history
メンバ関数empty()がassertマクロの中で呼ばれていますがcppcheckが
constメンバ関数でなく副作用がある可能性を警告していたため修正します。

さらにViewHistoryのメンバ関数のうちconstやnoexcept指定可能なものを
修正します。

```
src/history/viewhistory.cpp:325:13: warning: Assert statement calls a function which may have desired side effects: 'get_current_url'. [assertWithSideEffect]
    assert( get_current_url() == url );
            ^
```
  • Loading branch information
ma8ma committed May 16, 2020
1 parent 53c1b84 commit 88bfbc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/history/viewhistory.cpp
Expand Up @@ -79,7 +79,7 @@ void ViewHistory::set_end( const int end )
}


const std::string& ViewHistory::get_current_url()
const std::string& ViewHistory::get_current_url() const
{
#ifdef _DEBUG
std::cout << "ViewHistory::get_current_url" << std::endl
Expand All @@ -94,7 +94,7 @@ const std::string& ViewHistory::get_current_url()
}


const std::string& ViewHistory::get_current_title()
const std::string& ViewHistory::get_current_title() const
{
return m_items[ m_history_current ]->title;
}
Expand Down Expand Up @@ -162,7 +162,7 @@ void ViewHistory::replace_current_title( const std::string& title )


// item の取得
std::vector< ViewHistoryItem* >& ViewHistory::get_items_back( const int count )
std::vector< ViewHistoryItem* >& ViewHistory::get_items_back( const int count ) const
{
static std::vector< ViewHistoryItem* > items;
items.clear();
Expand All @@ -181,7 +181,7 @@ std::vector< ViewHistoryItem* >& ViewHistory::get_items_back( const int count )
}


std::vector< ViewHistoryItem* >& ViewHistory::get_items_forward( const int count )
std::vector< ViewHistoryItem* >& ViewHistory::get_items_forward( const int count ) const
{
static std::vector< ViewHistoryItem* > items;
items.clear();
Expand All @@ -203,7 +203,7 @@ std::vector< ViewHistoryItem* >& ViewHistory::get_items_forward( const int count
//
// 「戻る」可能
//
bool ViewHistory::can_back( const int count )
bool ViewHistory::can_back( const int count ) const noexcept
{
if( count <= 0 ) return false;

Expand All @@ -221,7 +221,7 @@ bool ViewHistory::can_back( const int count )
//
// 「進む」可能
//
bool ViewHistory::can_forward( const int count )
bool ViewHistory::can_forward( const int count ) const noexcept
{
if( count <= 0 ) return false;

Expand Down
22 changes: 11 additions & 11 deletions src/history/viewhistory.h
Expand Up @@ -26,19 +26,19 @@ namespace HISTORY
ViewHistory();
virtual ~ViewHistory();

int get_size() const { return m_items.size(); }
const ViewHistoryItem* get_item( const int pos ){ return m_items[ pos ]; }
int get_size() const noexcept { return m_items.size(); }
const ViewHistoryItem* get_item( const int pos ) const { return m_items[ pos ]; }

int get_top() const { return m_history_top; }
int get_cur() const { return m_history_current; }
int get_end() const { return m_history_end; }
int get_top() const noexcept { return m_history_top; }
int get_cur() const noexcept { return m_history_current; }
int get_end() const noexcept { return m_history_end; }

void set_top( const int top );
void set_cur( const int cur );
void set_end( const int end );

const std::string& get_current_url();
const std::string& get_current_title();
const std::string& get_current_url() const;
const std::string& get_current_title() const;

// URL更新
void replace_current_url( const std::string& url ); // 現在のアドレス
Expand All @@ -48,12 +48,12 @@ namespace HISTORY
void replace_current_title( const std::string& title );

// item の取得
std::vector< ViewHistoryItem* >& get_items_back( const int count );
std::vector< ViewHistoryItem* >& get_items_forward( const int count );
std::vector< ViewHistoryItem* >& get_items_back( const int count ) const;
std::vector< ViewHistoryItem* >& get_items_forward( const int count ) const;

// 戻る / 進む 可能かの判定
bool can_back( const int count );
bool can_forward( const int count );
bool can_back( const int count ) const noexcept;
bool can_forward( const int count ) const noexcept;

// 追加
void append( const std::string& url );
Expand Down

0 comments on commit 88bfbc8

Please sign in to comment.