本文整理汇总了C++中Any::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ Any::toString方法的具体用法?C++ Any::toString怎么用?C++ Any::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Any
的用法示例。
在下文中一共展示了Any::toString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: commandPlaySound
void SoundInterface::commandPlaySound(void) {
int32_t freg = cb->popValue().toInt();
float balance = cb->popValue().toFloat();
float volume = cb->popValue().toFloat();
Any any = cb->popValue();
// If passed parameter is integer, the sound is preloaded. Otherwise load it.
if (any.type() == Any::Int) {
CBChannel* channel = new CBChannel;
channel->setMixer(al_get_default_mixer());
int32_t id = any.toInt();
channel->playSound((*sounds[id]), volume, balance, freg);
int32_t nextChannel = nextChannelId();
channels[nextChannel] = channel;
}
else {
CBChannel* channel = new CBChannel;
channel->setMixer(al_get_default_mixer());
ALLEGRO_PATH *path = any.toString().getPath();
const char *cpath = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);
channel->playSound(cpath, volume, balance, freg);
int32_t nextChannel = nextChannelId();
channels[nextChannel] = channel;
}
}
示例2: convertToVariant
void convertToVariant(NPP npp, const Any& any, NPVariant* variant, bool result)
{
switch (any.getType())
{
case Any::Empty:
NULL_TO_NPVARIANT(*variant);
break;
case Any::Bool:
BOOLEAN_TO_NPVARIANT(any.toBoolean(), *variant);
break;
case Any::Int32:
case Any::Uint32:
INT32_TO_NPVARIANT(static_cast<int32_t>(any), *variant);
break;
case Any::Int64:
case Any::Uint64:
case Any::Float32:
case Any::Float64:
DOUBLE_TO_NPVARIANT(static_cast<double>(any), *variant);
break;
case Any::Dynamic:
if (any.isString())
{
std::string value = any.toString();
if (value.length() == 0)
{
STRINGN_TO_NPVARIANT(0, 0, *variant);
}
else if (!result)
{
STRINGN_TO_NPVARIANT(value.c_str(), static_cast<uint32_t>(value.length()), *variant);
}
else {
void* buffer = NPN_MemAlloc(value.length());
if (!buffer)
{
STRINGN_TO_NPVARIANT(0, 0, *variant);
}
else
{
memmove(buffer, value.c_str(), value.length());
STRINGN_TO_NPVARIANT(static_cast<NPUTF8*>(buffer), static_cast<uint32_t>(value.length()), *variant);
}
}
}
else
{
assert(any.isObject());
convertToVariant(npp, any.toObject(), variant, result);
}
break;
default:
VOID_TO_NPVARIANT(*variant);
break;
}
}