本文整理汇总了C++中Any::type方法的典型用法代码示例。如果您正苦于以下问题:C++ Any::type方法的具体用法?C++ Any::type怎么用?C++ Any::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Any
的用法示例。
在下文中一共展示了Any::type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Any Any::operator + (const Any &r) const {
switch (this->type()) {
case Any::Int:
switch (r.type()) {
case Any::Int: return this->getInt() + r.getInt();
case Any::Float: return this->getInt() + r.getFloat();
case Any::String: return boost::lexical_cast<string>(this->getInt()) + r.getString();
}
break;
case Any::Float:
switch (r.type()) {
case Any::Int: return this->getFloat() + r.getInt();
case Any::Float: return this->getFloat() + r.getFloat();
case Any::String: return boost::lexical_cast<string>(this->getFloat()) + r.getString();
}
break;
case Any::String:
switch (r.type()) {
case Any::Int: return this->getString() + boost::lexical_cast<string>(r.getInt());
case Any::Float: return this->getString() + boost::lexical_cast<string>(r.getFloat());
case Any::String: return this->getString() + r.getString();
}
break;
}
FIXME("Unsupported operation %s + %s", this->typeInfo().name(), r.typeInfo().name());
return 0;
}
示例2: shr
int32_t Any::shr (const Any &l, const Any &r) {
if (l.type() == Any::Int && r.type() == Any::Int) {
int32_t a = l.getInt();
int32_t b = r.getInt();
uint32_t ret = *reinterpret_cast<uint32_t*>( &a ) >> *reinterpret_cast<uint32_t*>( &b );
return *reinterpret_cast<int32_t*>( &ret );
}
示例3: if
Texture::Encoding::Encoding(const Any& a) {
*this = Encoding();
if (a.type() == Any::STRING) {
format = ImageFormat::fromString(a);
} else if (a.nameBeginsWith("Color4")) {
readMultiplyFirst = a;
}
else if (anyNameIsColor3Variant(a)) {
readMultiplyFirst = Color4(Color3(a), 1.0f);
} else if (a.type() == Any::NUMBER) {
readMultiplyFirst = Color4::one() * float(a.number());
} else {
AnyTableReader r(a);
r.getIfPresent("frame", frame);
r.getIfPresent("readMultiplyFirst", readMultiplyFirst);
r.getIfPresent("readAddSecond", readAddSecond);
String fmt;
if (r.getIfPresent("format", fmt)) {
format = ImageFormat::fromString(fmt);
}
}
}
示例4: Any
Any Converter<float>::convert(const Any& a)
{
if (typeid(int) == a.type())
return Any(helper<float, int>::convert(a));
else if (typeid(const char *) == a.type())
return Any(helper<float, const char *>::convert(a));
return any_cast<float>(a);
}
示例5: if
Any Converter<int>::convert(const Any& a)
{
if (Type::from<float>() == a.type())
return helper<int, double>::convert(a);
else if (Type::from<const char *>() == a.type())
return helper<int, const char *>::convert(a);
return any_cast<int>(a);
}
示例6: Any
Any Converter<float>::convert(const Any& a)
{
if (Type::from<int>() == a.type())
return Any(helper<float, int>::convert(a));
else if (Type::from<const char *>() == a.type())
return Any(helper<float, const char *>::convert(a));
return any_cast<float>(a);
}
示例7: if
Any Converter<int>::convert(const Any& a)
{
if (typeid(float) == a.type())
return helper<int, double>::convert(a);
else if (typeid(const char *) == a.type())
return helper<int, const char *>::convert(a);
return any_cast<int>(a);
}
示例8: r
Texture::Specification::Specification(const Any& any, bool assumesRGBForAuto, Dimension defaultDimension) {
*this = Specification();
assumeSRGBSpaceForAuto = assumesRGBForAuto;
dimension = defaultDimension;
if (any.type() == Any::STRING) {
filename = any.string();
if (filename == "<whiteCube>") {
filename = "<white>";
dimension = Texture::DIM_CUBE_MAP;
}
if (! beginsWith(filename, "<")) {
filename = any.resolveStringAsFilename();
if (FilePath::containsWildcards(filename)) {
// Assume this is a cube map
dimension = Texture::DIM_CUBE_MAP;
}
}
} else if ((any.type() == Any::NUMBER) ||
any.nameBeginsWith("Color4") ||
anyNameIsColor3Variant(any)) {
filename = "<white>";
encoding.readMultiplyFirst = Color4(any);
} else {
any.verifyNameBeginsWith("Texture::Specification");
AnyTableReader r(any);
r.getFilenameIfPresent("filename", filename);
r.getFilenameIfPresent("alphaFilename", alphaFilename);
r.getIfPresent("encoding", encoding);
r.getIfPresent("assumeSRGBSpaceForAuto", assumeSRGBSpaceForAuto);
{
Any a;
if (r.getIfPresent("dimension", a)) {
dimension = toDimension(a);
}
}
r.getIfPresent("generateMipMaps", generateMipMaps);
r.getIfPresent("preprocess", preprocess);
r.getIfPresent("visualization", visualization);
r.getIfPresent("cachable", cachable);
r.verifyDone();
if (! any.containsKey("dimension") && FilePath::containsWildcards(filename)) {
// Assume this is a cube map
dimension = Texture::DIM_CUBE_MAP;
}
}
}
示例9: testParse
static void testParse() {
{
const String& src = "name[ \"foo\", b4r, { a = b, c = d}]";
Any a = Any::parse(src);
a.verifyType(Any::ARRAY);
a[0].verifyType(Any::STRING);
testAssert(a[0].string() == "foo");
testAssert(a[1].string() == "b4r");
testAssert(a[2]["a"].string() == "b");
}
{
const String& src =
"[v = 1,\r\n/*\r\n*/\r\nx = 1]";
Any a = Any::parse(src);
testAssert(a.type() == Any::TABLE);
testAssert(a.size() == 2);
Any val1 = a["v"];
testAssert(val1.type() == Any::NUMBER);
testAssert(val1.number() == 1);
}
{
const String& src =
"{\n\
val0 : (1);\n\
\n\
// Comment 1\n\
val1 : 3;\n\
\
// Comment 2\n\
// Comment 3\n\
val2 : None;\n\
val3 : none;\n\
val4 : NIL;\n\
}";
Any a = Any::parse(src);
testAssert(a.type() == Any::TABLE);
testAssert(a.size() == 5);
Any val1 = a["val1"];
testAssert(val1.type() == Any::NUMBER);
testAssert(val1.number() == 3);
testAssert(val1.comment() == "Comment 1");
testAssert(a["val2"].isNil());
testAssert(a["val3"].string() == "none");
testAssert(a["val4"].isNil());
}
示例10: 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;
}
}
示例11: any_safe
void
Any_Handler::extract_into_any (const Any& desc,
CORBA::Any& toconfig)
{
DANCE_TRACE("Any_Handler::extract_into_any");
try
{
DynamicAny::DynAny_var dyn = DYNANY_HANDLER->extract_into_dynany (desc.type (),
desc.value ());
CORBA::Any_var any_safe (dyn->to_any ());
toconfig = *any_safe;
dyn->destroy ();
}
catch (CORBA::Exception &ex)
{
DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO
ACE_TEXT ("Any_Handler::extract_into_any -")
ACE_TEXT (" Caught CORBA Exception while extracting into")
ACE_TEXT (" dynany: %C\n"),
ex._info ().c_str ()));
throw Config_Error (ACE_TEXT (""),
ACE_TEXT ("CORBA Exception while extracting into dynany\n"));
}
catch (Config_Error &ex)
{
throw ex;
}
catch (...)
{
throw Config_Error (ACE_TEXT (""), ACE_TEXT ("Caught error whilst parsing XML into Any\n"));
}
}
示例12: r
Sampler::Sampler(const Any& any) {
*this = Sampler::defaults();
any.verifyNameBeginsWith("Sampler");
if (any.type() == Any::TABLE) {
AnyTableReader r(any);
r.getIfPresent("maxAnisotropy", maxAnisotropy);
r.getIfPresent("maxMipMap", maxMipMap);
r.getIfPresent("minMipMap", minMipMap);
r.getIfPresent("mipBias", mipBias);
r.getIfPresent("xWrapMode", xWrapMode);
if (! r.getIfPresent("yWrapMode", yWrapMode)) {
yWrapMode = xWrapMode;
}
r.getIfPresent("depthReadMode", depthReadMode);
r.getIfPresent("interpolateMode", interpolateMode);
r.verifyDone();
} else {
any.verifySize(0);
const String& n = any.name();
if (n == "Sampler::defaults") {
// Done!
} else if (n == "Sampler::buffer") {
*this = Sampler::buffer();
} else if (n == "Sampler::cubeMap") {
*this = Sampler::cubeMap();
} else if (n == "Sampler::shadow") {
*this = Sampler::shadow();
} else if (n == "Sampler::video") {
*this = Sampler::video();
} else {
any.verify(false, "Unrecognized name for Sampler constructor or factory method.");
}
}
}
示例13: switch
ArticulatedModel::Instruction::Identifier::Identifier(const Any& a) {
switch (a.type()) {
case Any::NUMBER:
id = ID(iRound(a.number()));
a.verify(id >= 0, "Illegal ID");
break;
case Any::STRING:
name = a.string();
break;
case Any::ARRAY:
a.verifySize(0);
if (a.name() == "root") {
*this = root();
} else if (a.name() == "all") {
*this = all();
} else {
a.verify(false, "Illegal function call: " + a.name());
}
break;
default:
a.verify(false, "Expected a name, integer ID, root(), or all()");
}
}
示例14: toLower
PhysicsFrame::PhysicsFrame(const Any& a) {
const std::string& n = toLower(a.name());
*this = PhysicsFrame();
if (beginsWith(n, "vector3")) {
*this = PhysicsFrame(Vector3(a));
} else if (beginsWith(n, "matrix3")) {
*this = PhysicsFrame(Matrix3(a));
} else if (beginsWith(n, "cframe") || beginsWith(n, "coordinateframe")) {
*this = PhysicsFrame(CoordinateFrame(a));
} else if (beginsWith(n, "pframe") || beginsWith(n, "physicsframe")) {
if (a.type() == Any::ARRAY) {
a.verifySize(2);
rotation = a[0];
translation = a[1];
} else {
for (Any::AnyTable::Iterator it = a.table().begin(); it.hasMore(); ++it) {
const std::string& n = toLower(it->key);
if (n == "translation") {
translation = it->value;
} else if (n == "rotation") {
rotation = it->value;
} else {
a.verify(false, "Illegal table key: " + it->key);
}
}
}
}
}
示例15: testDefaultCtor
void AnyTest::testDefaultCtor()
{
const Any value;
assert (value.empty());
assert (0 == AnyCast<int>(&value));
assert (value.type() == typeid(void));
}