本文整理汇总了C++中type_info::name方法的典型用法代码示例。如果您正苦于以下问题:C++ type_info::name方法的具体用法?C++ type_info::name怎么用?C++ type_info::name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类type_info
的用法示例。
在下文中一共展示了type_info::name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetTypeName
string StringConverter::GetTypeName (const type_info &typeInfo)
{
try
{
#ifdef _MSC_VER
// type_info::name() leaks memory as of MS VC++ 8.0
string rawName (typeInfo.raw_name());
size_t cut1 = (rawName.find (".?A") != string::npos) ? 4 : string::npos;
size_t cut2 = rawName.find ("@");
size_t cut3 = rawName.find ("@@");
if (cut1 == string::npos || cut2 == string::npos || cut3 == string::npos)
return typeInfo.name();
return rawName.substr (cut2 + 1, cut3 - cut2 - 1) + "::" + rawName.substr (cut1, cut2 - cut1);
#elif defined (__GNUC__)
int status;
char *name = abi::__cxa_demangle (typeInfo.name(), nullptr, nullptr, &status);
if (name)
{
string s (name);
free (name);
return s;
}
#endif
}
catch (...) { }
return typeInfo.name();
}
示例2: getVartypeFromTypeInfo
vartype getVartypeFromTypeInfo(const type_info &ti) {
if (ti.name() == "int" || ti.name() == "bool") {
return vartype::NUMBER;
}
else if (ti.name() == "std::string") {
return vartype::STRING;
}
}
示例3:
bad_downcast::bad_downcast(
const type_info& fromType,
const type_info& toType
)
{
what_ = "cannot downcast ";
what_ += fromType.name();
what_ += " to ";
what_ += toType.name();
}
示例4: demangleName
string demangleName( const type_info& typeinfo ){
int status;
char * niceName = abi::__cxa_demangle(typeinfo.name(), 0, 0, &status);
if ( ! niceName )
return typeinfo.name();
string s = niceName;
free(niceName);
return s;
}
示例5: ReleaseWaiter
void CSynchInvoker::ReleaseWaiter(const type_info& info, const string& id)
{
Key key(id, info.name());
CLock lock(m_synchronizer);
assert(m_key2Waiter.end() != m_key2Waiter.find(key));
m_key2Waiter.erase(key);
}
示例6: getCacheFolder
// Generate a cache path. This must be different for different settings in order
// to prevent cache hits on different settings.
string CacheHelper::getCacheFolder(string filename,
const type_info& dataType) const {
string dataTypeName = dataType.name();
dataTypeName.erase(
boost::remove_if(dataTypeName, ::isdigit), dataTypeName.end());
string basePath = "cache/" + m_datasetPath +
"/" + dataTypeName;
if(dataType == typeid(DatasetManager)) {
return basePath + "/";
}
stringstream cacheNameStream;
cacheNameStream <<
"_" << m_settings->get<string>("image.type") <<
"_" << m_settings->get<float>("image.smoothingSigma") <<
"_" << m_settings->get<string>("features.type") <<
"_" << m_settings->get<vector<int> >("features.gridSpacing")[0] <<
"_" << m_settings->get<vector<int> >("features.patchSize")[0];
if(dataType == typeid(ImageFeatures)) {
return basePath + cacheNameStream.str() + "/";
}
cacheNameStream <<
"_" << m_settings->get<int>("codebook.textonImages") <<
"_" << m_settings->get<int>("codebook.codewords") <<
"_" << m_settings->get<string>("histogram.type") <<
"_" << m_settings->get<int>("histogram.pyramidLevels");
return basePath + cacheNameStream.str() + "/";
}
示例7: GetClassName
static string GetClassName(const type_info& info)
{
const char* name = info.name();
// __cxa_demangle requires an output buffer
// allocated with malloc(). Provide it.
size_t len = 1024;
char *buf = (char*)malloc(len);
assert(buf != 0);
int status = 0;
char *res = 0;
#ifdef HAVE_GCC_ABI_DEMANGLE
res = abi::__cxa_demangle(name, buf, &len, &status);
#endif
if (res && status == 0)
{
string ret = res;
free(res);
return ret;
}
else
{
if (res) free(res);
else free(buf);
return name;
}
}
示例8: RegisterWaiter
void CSynchInvoker::RegisterWaiter(const type_info& info, const string& id, IWaiter* pWaiter)
{
Key key(id, info.name());
CLock lock(m_synchronizer);
assert(m_key2Waiter.end() == m_key2Waiter.find(key));
m_key2Waiter[key] = pWaiter;
}
示例9: x_ThrowSanityCheck
void CException::x_ThrowSanityCheck(const type_info& expected_type,
const char* human_name) const
{
const type_info& actual_type = typeid(*this);
if (actual_type != expected_type) {
ERR_POST_X(14, Warning << "CException::Throw(): throwing object of type "
<< actual_type.name() << " as " << expected_type.name()
<< " [" << human_name << ']');
}
}
示例10: Response
void CSynchInvoker::Response(const type_info& info, const CFxEventInfo& eventInfo, void* pData)
{
Key key(eventInfo.ID, info.name());
CLock lock(m_synchronizer);
auto it = m_key2Waiter.find(key);
if (m_key2Waiter.end() != it)
{
IWaiter* pWaiter = it->second;
pWaiter->VResponse(eventInfo, pData);
}
}
示例11: demangle
const string demangle(const type_info &ti)
{
const size_t __mangle_buff_size = 1024;
int status;
size_t __mangle_buff_len = __mangle_buff_size;
char __mangle_buff[__mangle_buff_size];
/*
Назначение третьего (__length) и четвертого (__status) аргументов неясно: в случае очевидной ошибки нехватки памяти происходит крушение процесса (Segmentation fault или Bus error). Ситуация, при которой хотя бы один из аргументов был изменен не наблюдалась
*/
const char *mangled_name = abi::__cxa_demangle(ti.name(), __mangle_buff, &__mangle_buff_len, &status);
return (mangled_name ? mangled_name : "<not_demangled>");
}
示例12: name
string
TypeInfoHelper::getClassName( const type_info &info )
{
static const string classPrefix( "class " );
string name( info.name() );
bool has_class_prefix = 0 ==
#if CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST
name.compare( classPrefix, 0, classPrefix.length() );
#else
name.compare( 0, classPrefix.length(), classPrefix );
#endif
return has_class_prefix ? name.substr( classPrefix.length() ) : name;
}
示例13: GetTypeName
/**
* Returns a human-readable type name of a type_info object.
*
* @param ti A type_info object.
* @returns The type name of the object.
*/
String Utility::GetTypeName(const type_info& ti)
{
String klass = ti.name();
#ifdef HAVE_GCC_ABI_DEMANGLE
int status;
char *realname = abi::__cxa_demangle(klass.CStr(), 0, 0, &status);
if (realname != NULL) {
klass = String(realname);
free(realname);
}
#endif /* HAVE_GCC_ABI_DEMANGLE */
return klass;
}
示例14: get_type_name
std::string get_type_name(const type_info& info)
{
std::string type_name = info.name();
typedef std::string::size_type size_type;
//TODO: handle case of other than MSVC compilers
static const std::string msvc_typeid_prefix = "class ";
size_type pos = type_name.find(msvc_typeid_prefix);
if (std::string::npos != pos )
{
size_type start_pos = pos + msvc_typeid_prefix.size();
type_name = std::string(type_name, start_pos, type_name.size() - start_pos);
}
return type_name;
}
示例15: while
string
ClassName( const type_info& inTypeid )
{
string result = inTypeid.name();
#ifdef __GNUC__
int err = 0;
char* name = abi::__cxa_demangle( result.c_str(), 0, 0, &err );
if( name )
{
result = name;
::free( name );
}
#endif // __GNUC__
// To obtain a useful representation of the class name, we need to do some
// processing that removes white space and compiler specific additions.
// First, remove white space between template arguments and <> brackets.
static struct
{
const char* original,
* replacement;
} replacementTable[] =
{
{ ", ", "," },
{ "< ", "<" },
{ " >", ">" },
{ "class ", "" },
{ "struct ", "" },
{ "enum ", "" },
};
size_t pos;
for( size_t r = 0; r < sizeof( replacementTable ) / sizeof( *replacementTable ); ++r )
{
string original = replacementTable[r].original;
while( string::npos != ( pos = result.find( original ) ) )
result = result.replace( pos, original.length(), replacementTable[r].replacement );
}
return result;
}