|
#include "stdafx.h"
#include <Model/CppTagModel.h>
#include <Model/CTags/CTagsFileOutlineLoader.h>
#include <Model/CTags/CTagsCppTagFactory.h>
#include <Model/CTags/CTagsModelBuilder.h>
#include <Utilities/Properties.h>
#include <Utilities/smart_ptr.h>
#include <Utilities/stl_ext.h>
#include <Utilities/StringTokenizer.h>
#include <sstream>
#include <map>
#include <algorithm>
#include <iterator>
using namespace std;
using FileOutlineLoader::TagList;
using CTags::Database::TagTable;
namespace Browsers{
namespace Outline
{
extern const std::string SHOW_HEADER_AND_SOURCE;
}
}
using namespace Browsers::Outline;
namespace CTags {
FileOutlineLoader::FileOutlineLoader(const smart_ptr<Workspace> &wspace)
: mWorkspace(wspace)
{
}
struct SelectPossibleScopes : public std::unary_function<Tag, std::string>
{
std::string operator()(const argument_type &tag) const
{
switch(tag.getType()) {
case eNamespace : return "";//return GLOBAL_NAMESPACE;
case eClass :
case eStruct :
case eUnion:
case eEnum:
case eTypedef: return tag.getFQN();
case eFunction:
case eVariable:
case eMethod:
case eField:
case eEnumMember: return tag.getScope();
}
throw invalid_argument("SelectPossibleScopes");
}
};
struct ScopeMatches : public std::binary_function<Tag, FullQualifiedName, bool>
{
bool operator()(const first_argument_type &tag, const second_argument_type &fqn) const
{
switch(tag.getType()) {
case eNamespace : //return false;
//those ARE the scopes
case eClass :
case eStruct :
case eUnion:
case eEnum:
case eTypedef: return tag.getFQN() == fqn;
//this two need special treatments
case eFunction:
case eVariable: return false;
//those are typicaly in a scope !
case eMethod:
case eField:
case eEnumMember: return tag.getScope() == fqn.toString();
}
throw invalid_argument("ScopeMatches()");
}
};
bool same_name(string fullname, string target)
{
if(file_name_is::nameof(fullname) != file_name_is::nameof(target)) {
return false;
}
string suffix = file_suffix_is::suffixof(fullname);
string targetsuffix = file_suffix_is::suffixof(target);
if(targetsuffix == "h" || targetsuffix == "hpp") {
return suffix == "cpp";
} else if(targetsuffix == "cpp") {
return suffix == "h" || suffix == "hpp";
}
return false;
}
TagList FileOutlineLoader::load(const string &file)
{
list<string> files;
if(PropertiesManager::instance().getProperty(SHOW_HEADER_AND_SOURCE, "") == "1") {
files = mWorkspace->getFiles();
//files.remove_if(not1(bind2nd(file_name_is(), file_name_is::nameof(file))));
files.remove_if(not1(bind2nd(ptr_fun(same_name), file)));
}
files.push_back(file);
//remove duplicates
files.sort();
files.unique();
return load(files);
}
TagList FileOutlineLoader::load(const list<string> &files)
{
return loadFiles(files);
}
TagList FileOutlineLoader::loadFiles(const list<string> &files)
{
smart_ptr<CTags::Database> db = DatabaseManager::instance().getDatabase(mWorkspace);
//select tags from all requiered files....
TagTable fileTags;
for(list<string>::const_iterator file = files.begin(); file != files.end(); file++) {
fileTags.splice(fileTags.end(), db->selectTagsWhere(make_query(FileIs(), *file)));
}
//get the name of possible scopes....
//namespace are ignored because they can span multiple files and we would end up
//loading to much classes/structs etc...
set<string> scopes;
transform(fileTags.begin(), fileTags.end(), inserter(scopes, scopes.begin()), SelectPossibleScopes());
scopes.erase(GLOBAL_NAMESPACE);
scopes.erase("");
TagTable tagTable;
copy_if(fileTags.begin(), fileTags.end(), inserter(tagTable, tagTable.begin()), make_query(TypeIs(), eFunction | eVariable));
/*stringstream ss;
copy(scopes.begin(), scopes.end(), ostream_iterator<string>(ss, "\n"));
AfxMessageBox(ss.str().c_str());*/
for(set<string>::iterator scope = scopes.begin(); scope != scopes.end(); scope++) {
tagTable.splice(tagTable.end(), db->selectTagsWhere(make_query(ScopeMatches(), *scope)));
}
return createModelFromTagList(tagTable);
}
TagList FileOutlineLoader::createModelFromTagList(Database::TagTable &table)
{
return ModelBuilder().createModel(table);
}
} //namespace CTags
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.