本文整理汇总了C++中Any类的典型用法代码示例。如果您正苦于以下问题:C++ Any类的具体用法?C++ Any怎么用?C++ Any使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Any类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
}
示例2: filenameTable
/** Returns a table mapping scene names to filenames */
static Table<std::string, std::string>& filenameTable() {
static Table<std::string, std::string> filenameTable;
if (filenameTable.size() == 0) {
// Create a table mapping scene names to filenames
Array<std::string> filenameArray;
FileSystem::ListSettings settings;
settings.files = true;
settings.directories = false;
settings.includeParentPath = true;
settings.recursive = true;
FileSystem::list("*.scn.any", filenameArray, settings);
for (int i = 0; i < filenameArray.size(); ++i) {
Any a;
a.load(filenameArray[i]);
std::string name = a["name"].string();
alwaysAssertM(! filenameTable.containsKey(name),
"Duplicate scene names in " + filenameArray[i] + " and " +
filenameTable["name"]);
filenameTable.set(name, filenameArray[i]);
}
}
return filenameTable;
}
示例3: DANCE_TRACE
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"));
}
}
示例4: perform_evaluation_impl
void
AsynchronousApplication::
perform_evaluation_impl( const utilib::Any &domain,
const AppRequest::request_map_t &requests,
utilib::seed_t &seed,
AppResponse::response_map_t &responses )
{
Any evalID = spawn_evaluation(domain, requests, seed);
while ( true )
{
AppResponse::response_map_t tmp_responses;
utilib::seed_t tmp_seed;
Any tmp_evalId;
tmp_evalId = async_collect_evaluation(tmp_responses, tmp_seed);
try {
if ( evalID.references_same_data_as(tmp_evalId) ||
evalID == tmp_evalId )
{
responses = tmp_responses;
seed = tmp_seed;
return;
}
else
{
evaluatedBuffer.push_back
( Evaluation(tmp_evalId, tmp_seed, tmp_responses) );
}
} catch ( utilib::any_not_comparable& ) {
// silently ignore non-comparable EvalIDs
}
}
}
示例5: UtcDaliAnyConstructors
int UtcDaliAnyConstructors(void)
{
TestApplication application;
tet_infoline("Test Any constructors.");
// Test default constructor.
Any value;
DALI_TEST_CHECK( typeid( void ) == value.GetType() );
// Test constructor Any( const Type& )
Any value1 = 4u;
// Test constructor Any( const Any& )
Any value2 = value1;
// Test constructor Any( const Any& ) with a non initialized Any
Any value3 = value;
DALI_TEST_CHECK( typeid( unsigned int ) == value1.GetType() );
DALI_TEST_CHECK( typeid( unsigned int ) == value2.GetType() );
DALI_TEST_CHECK( typeid( void ) == value3.GetType() );
unsigned int uiValue1 = 0u;
unsigned int uiValue2 = 0u;
value1.Get( uiValue1 );
value2.Get( uiValue2 );
DALI_TEST_EQUALS( uiValue1, uiValue2, TEST_LOCATION );
END_TEST;
}
示例6: 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()");
}
}
示例7: toAny
Any Entity::toAny() const {
Any a = m_sourceAny;
debugAssert(! a.isNil());
if (a.isNil()) {
// Fallback for release mode failure
return a;
}
if (m_movedSinceLoad) {
a["frame"] = m_frame;
}
const shared_ptr<SplineTrack>& splineTrack = dynamic_pointer_cast<SplineTrack>(m_track);
if (notNull(splineTrack) && splineTrack->changed()) {
// Update the spline
const PhysicsFrameSpline& spline = splineTrack->spline();
if (spline.control.size() == 1) {
// Write out in short form for the single control point
const PhysicsFrame& p = spline.control[0];
if (p.rotation == Quat()) {
// No rotation
a["track"] = p.translation;
} else {
// Full coordinate frame
a["track"] = CFrame(p);
}
} else {
// Write the full spline
a["track"] = spline;
}
}
a.setName("Entity");
return a;
}
示例8: 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.");
}
}
}
示例9: 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;
}
}
示例10: 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 );
}
示例11: tileSheet
shared_ptr<TileSheet> TileSheet::create(const Any& any) {
shared_ptr<TileSheet> tileSheet(new TileSheet());
AnyTableReader r(any);
Any legend;
r.getIfPresent("legend", legend);
for (Table<String, Any>::Iterator it = legend.table().begin(); it.hasMore(); ++it) {
const String& mapLabel = it.key();
const shared_ptr<Tile>& tile = Tile::create(mapLabel, it.value());
// TODO: Switch to report
debugAssertM(! tileSheet->m_tileByID.containsKey(tile->id()), "Duplicate tile ID");
tileSheet->m_tileByID.set(tile->id(), tile);
tileSheet->m_tileByMapLabel.set(tile->mapLabel(), tile);
}
r.getFilenameIfPresent("color", tileSheet->m_colorFilename);
r.getFilenameIfPresent("blueprint", tileSheet->m_blueprintFilename);
// Even though we lazy load these (since the server can't load graphics),
// we check immediately to ensure that the files exist
if (! FileSystem::exists(tileSheet->m_colorFilename)) {
report("File not found: \"" + tileSheet->m_colorFilename + "\".", ReportLevel::ERROR);
}
if (! FileSystem::exists(tileSheet->m_blueprintFilename)) {
report("File not found: \"" + tileSheet->m_blueprintFilename + "\".", ReportLevel::ERROR);
}
r.verifyDone();
return tileSheet;
}
示例12: if
Any Any::get(std::string key) {
if(type == OBJECT) {
std::vector<std::string> elems;
if(key.length() == 0) {
return this;
} else {
Susi::Util::Helpers::split(key, '.', elems);
Any found = this->objectValue;
Any next = this->objectValue;
for(size_t e=0; e<elems.size(); e++)
{
std::string elem = elems[e];
found = next[elem];
next = found;
if(found.getType() == Susi::Util::Any::UNDEFINED) {
throw std::runtime_error("key doesn't exist!"+key);
} else if(e == (elems.size()-2) && found.getType() != Susi::Util::Any::OBJECT) {
throw WrongTypeException(OBJECT, type);
}
}
return found;
}
} else {
throw WrongTypeException(OBJECT, type);
}
}
示例13: 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);
}
}
}
}
}
示例14: toLower
Matrix4::Matrix4(const Any& any) {
any.verifyName("Matrix4");
any.verifyType(Any::ARRAY);
const std::string& name = toLower(any.name());
if (name == "matrix4") {
any.verifySize(16);
for (int r = 0; r < 4; ++r) {
for (int c = 0; c < 4; ++c) {
elt[r][c] = any[r * 4 + c];
}
}
} else if (name == "matrix4::scale") {
if (any.size() == 1) {
*this = scale(any[0].number());
} else if (any.size() == 3) {
*this = scale(any[0], any[1], any[2]);
} else {
any.verify(false, "Matrix4::scale() takes either 1 or 3 arguments");
}
} else if (name == "matrix4::translation") {
if (any.size() == 3) {
*this = translation(any[0], any[1], any[2]);
} else {
any.verify(false, "Matrix4::translation() takes either 1 or 3 arguments");
} } else {
any.verify(false, "Expected Matrix4 constructor");
}
}
示例15: assert
void AnyTest::testDefaultCtor()
{
const Any value;
assert (value.empty());
assert (0 == AnyCast<int>(&value));
assert (value.type() == typeid(void));
}