#include "stdafx.h"
#include "CTagsCppTagFactory.h"
#include "CppTagModel.h"
#include <string>
#include <sstream>
using namespace std;
using CTags::Database::TagTable;
namespace CTags
{
smart_ptr<TypeInfoCreator::result_type> TypeInfoCreator::create(CppTagType type, const std::string name, AccessQualifier access, const TagLocation &file, const Tag* tag)
{
smart_ptr<CppType> result;
switch(type) {
case eNamespace: result = smart_ptr<CppType>(new Namespace(name)); break;
case eClass : result = smart_ptr<CppType>(new Class(name, access, file)); break;
case eStruct : result = smart_ptr<CppType>(new Struct(name, access, file)); break;
case eUnion : result = smart_ptr<CppType>(new Union(name, access, file)); break;
case eEnum : result = smart_ptr<CppType>(new Enum(name, access, file)); break;
case eTypedef : result = smart_ptr<CppType>(new Typedef(name, access, file)); break;
default:
{
std::stringstream text;
text << "TypeFactoryPolicy::create(): 0x" << std::hex << type << " not supported!";
throw std::runtime_error(text.str());
}
}
return result;
}
smart_ptr<MethodInfoCreator::result_type> MethodInfoCreator::create(CppTagType type, const std::string name, AccessQualifier access, const TagLocation &file, const Tag* tag)
{
smart_ptr<MethodInfoCreator::result_type> result;
switch(type) {
case eMethod : result = make_smart_ptr(new Method(tag->getReturnType(), name, access, file)); break;
case eFunction : result = make_smart_ptr(new Function(tag->getReturnType(), name, file)); break;
default :
{
std::stringstream text;
text << "MethodFactoryPolicy::create(): 0x" << std::hex << type << " not supported!";
throw std::runtime_error(text.str());
}
}
return result;
}
struct create_field
{
Field operator()(const string& type) const
{ return Field(type, "name"); }
};
CreatorPolicy<Method>::result_type MethodCreatorPolicy::create(Tag const* declaration, Tag const *definition) const
{
Tag const *tag = declaration ? declaration : definition;
list<Field> signature;
transform(tag->getSignature().begin(), tag->getSignature().end(), back_inserter(signature), create_field());
Method method(tag->getReturnType(), tag->getFQN(), signature);
setDeclAndDefn(method, declaration, definition);
method.setAccessQualifier(tag->getAccessQualifier());
if(tag->getReturnType().find("static ") != string::npos) {
method.isStatic(true);
}
size_t pos = tag->getCode().find(")");
if(pos != string::npos && tag->getCode().substr(pos, -1).find("const") != string::npos) {
method.isConst(true);
}
method.setImplementationQualifier(tag->getImplementationQualifier());
return method;
}
smart_ptr<Function> FunctionCreatorPolicy::create(Tag const* declaration, Tag const *definition) const
{
Tag const *tag = declaration ? declaration : definition;
smart_ptr<Function> function(new Function(tag->getReturnType(), tag->getName(), list<Field>()));
setDeclAndDefn(*function, declaration, definition);
return function;
}
} //namespace CTags