本文整理汇总了C++中std::type_info类的典型用法代码示例。如果您正苦于以下问题:C++ type_info类的具体用法?C++ type_info怎么用?C++ type_info使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了type_info类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: demangle
inline std::string demangle(const std::type_info & type)
{
#ifdef __GNUG__
int status;
char * realname = abi::__cxa_demangle(type.name(), 0, 0, &status);
std::string result(realname);
free(realname);
return result;
#else
return std::string("<") + type.name() + std::string(">");
#endif
}
示例2: query
bool ContextRead::query(void *ptr, const std::type_info &objType, void *&pObj)
{
if (type_ptr_obj_ptr_.get() &&
(*type_ptr_obj_ptr_)[ objType.name() ].find(ptr) != (*type_ptr_obj_ptr_)[ objType.name() ].end() )
{
pObj = (*type_ptr_obj_ptr_)[ objType.name() ][ ptr ];
return true;
}
else
{
return false;
}
}
示例3: GetTypeName
std::string DefTagMetaData::GetTypeName(const std::type_info& typeInfo)
{
// demangle typename
#ifndef _MSC_VER
int status;
char* ctname = abi::__cxa_demangle(typeInfo.name(), 0, 0, &status);
const std::string tname = ctname;
free(ctname);
#else
const std::string tname(typeInfo.name()); // FIXME?
#endif
return tname;
}
示例4: convert_to
void Variant::convert_to(const std::type_info& info, void* p) const
{
try
{
TRY_CONVERT_TO(std::string);
TRY_CONVERT_TO(long);
TRY_CONVERT_TO(bool);
TRY_CONVERT_TO(float);
TRY_CONVERT_TO(double);
TRY_CONVERT_TO(unsigned long);
TRY_CONVERT_TO(int);
TRY_CONVERT_TO(unsigned int);
TRY_CONVERT_TO(char);
TRY_CONVERT_TO(unsigned char);
TRY_CONVERT_TO(int32_t);
TRY_CONVERT_TO(uint32_t);
}
catch(Poco::SyntaxException& ex)
{
string msg = "Could not convert variant with typeid ";
msg += self->var.type().name();
msg += " to type";
msg += info.name();
msg += "error: ";
msg += ex.what();
msg += ", string value: " + self->var.toString();
throw std::logic_error(msg);
}
string msg = "Could not convert variant with typeid ";
msg += self->var.type().name();
msg += " to type";
msg += info.name();
throw invalid_argument(msg);
}
示例5: query
bool ContextRead::query(void *ptr, const std::type_info &objType, void *&pObj)
{
RCF_ASSERT(mEnabled);
if (mTypeToObjMap.get() &&
(*mTypeToObjMap)[ objType.name() ].find(ptr) != (*mTypeToObjMap)[ objType.name() ].end() )
{
pObj = (*mTypeToObjMap)[ objType.name() ][ ptr ];
return true;
}
else
{
return false;
}
}
示例6: RegisterSingleton
void Adaptor::RegisterSingleton(const std::type_info& info, BaseHandle singleton)
{
if(singleton)
{
mSingletonContainer.insert(SingletonPair(info.name(), singleton));
}
}
示例7: Register
bool TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_info& baseTypeInfo,
Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit )
{
bool ret = false;
std::string baseTypeName = DemangleClassName(baseTypeInfo.name());
RegistryMap::iterator iter = mRegistryLut.find(uniqueTypeName);
if( iter == mRegistryLut.end() )
{
mRegistryLut[uniqueTypeName] = Dali::TypeInfo(new Internal::TypeInfo(uniqueTypeName, baseTypeName, createInstance));
ret = true;
DALI_LOG_INFO( gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str());
}
else
{
DALI_LOG_WARNING("Duplicate name for TypeRegistry for '%s'\n", + uniqueTypeName.c_str());
DALI_ASSERT_ALWAYS(!"Duplicate type name for Type Registation");
}
if( callCreateOnInit )
{
mInitFunctions.push_back(createInstance);
}
return ret;
}
示例8: tmp
void connection::connection_specific_reset(std::type_info const &type, connection_specific_data *ptr)
{
std::auto_ptr<connection_specific_data> tmp(ptr);
if(ptr && typeid(*ptr)!=type) {
throw cppdb_error(
std::string("cppdb::connection_specific::Inconsistent pointer type")
+ typeid(*ptr).name()
+ " and std::type_info reference:"
+ type.name()
);
}
for(data::conn_specific_type::iterator p=d->conn_specific.begin();p!=d->conn_specific.end();++p) {
if(typeid(**p) == type) {
delete *p;
if(ptr)
*p = tmp.release();
else
d->conn_specific.erase(p);
return;
}
}
if(ptr) {
d->conn_specific.push_back(0);
d->conn_specific.back() = tmp.release();
}
}
示例9: name_of
std::string
name_of(const std::type_info &ti)
{
const static std::string typename_notavailable = "N/A";
const char* mangled = ti.name();
if (!mangled)
{
return typename_notavailable;
}
int status;
char* demangled = abi::__cxa_demangle(mangled, 0, 0, &status);
std::string rv;
if (status != 0)
rv = mangled;
else
rv = demangled ? demangled : typename_notavailable;
std::free(demangled);
return rv;
}
示例10: demangle
std::string demangle(const std::type_info& id) {
int status;
char* unmangled = abi::__cxa_demangle(id.name(), 0, 0, &status);
std::string realname = unmangled;
free(unmangled);
return realname;
}
示例11: isTypeRegistered
bool Registry::isTypeRegistered(const std::type_info &ti)
{
ReadLock lock(mReadWriteMutex);
RCF_UNUSED_VARIABLE(lock);
Rtti typeRtti = ti.name();
return mRttiToTypename.find(typeRtti) != mRttiToTypename.end();
}
示例12: TProtocolException
[[noreturn]] void JSONProtocolReaderCommon::throwUnrecognizableAsIntegral(
folly::StringPiece s,
std::type_info const& type) {
throw TProtocolException(
TProtocolException::INVALID_DATA,
folly::to<std::string>(s, " is not a valid ", type.name()));
}
示例13: Register
void SingletonService::Register( const std::type_info& info, BaseHandle singleton )
{
if( singleton )
{
mSingletonContainer.insert( SingletonPair( info.name(), singleton ) );
}
}
示例14: register_interface
unsigned register_interface(const std::type_info& info)
{
std::string key = info.name();
unsigned data = ++m_max_key;
m_interfaces[key] = data;
return data;
}
示例15: register_callback
unsigned register_callback(const std::type_info& info, dump_context::dump_callback callback)
{
std::string key = info.name();
unsigned data = ++m_max_key;
m_callbacks[key] = std::make_pair(data,callback);
return data;
}