Skip to content

Commit

Permalink
Beautify the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Queequeg92 committed Nov 17, 2014
1 parent c7afdc7 commit 21f8cf2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
16 changes: 3 additions & 13 deletions ch17/ex17.3/textquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ TextQuery::query(const std::string &sought) const
/**
* @brief do a query opertion and return tuple.
*/
std::tuple<std::string,
std::shared_ptr<std::set<TextQuery::index_Tp>>,
std::shared_ptr<std::vector<std::string>>>
TextQuery::query_return_tuple(const std::string &sought)
result_tuple TextQuery::query_return_tuple(const std::string &sought)
{
//! dynamicaly allocated set used for the word does not appear.
static std::shared_ptr<std::set<index_Tp>> noData(new std::set<index_Tp>);
Expand All @@ -93,15 +90,8 @@ std::tuple<std::string,
//std::map<std::string, std::shared_ptr<std::set<index_Tp>>>::const_iterator
auto iter = wm.find(sought);
if(iter == wm.end())
return std::tuple <std::string,
std::shared_ptr<std::set<index_Tp>>,
std::shared_ptr<std::vector<std::string>>>
(sought, noData, file);
return result_tuple(sought, noData, file);
else
return std::tuple <std::string,
std::shared_ptr<std::set<index_Tp>>,
std::shared_ptr<std::vector<std::string>>>
(sought, iter->second, file);

return result_tuple(sought, iter->second, file);
}

8 changes: 4 additions & 4 deletions ch17/ex17.3/textquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class TextQuery

public:
typedef std::vector<std::string>::size_type index_Tp;
typedef std::tuple <std::string,
std::shared_ptr<std::set<index_Tp>>,
std::shared_ptr<std::vector<std::string>>> result_tuple;

//! constructor
TextQuery(std::ifstream&);
Expand All @@ -31,10 +34,7 @@ class TextQuery
query(const std::string&) const;

//! query operation returns tuple
std::tuple <std::string,
std::shared_ptr<std::set<index_Tp>>,
std::shared_ptr<std::vector<std::string>>>
query_return_tuple(const std::string& sought);
result_tuple query_return_tuple(const std::string& sought);
private:
std::shared_ptr<std::vector<std::string>> file;
std::map<std::string,
Expand Down

0 comments on commit 21f8cf2

Please sign in to comment.