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);
        }
    }
}
Example #2
0
/** 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;
}
Example #3
0
    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"));
        }
    }
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
      }
   }
}
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;
}
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()");
    }
}
Example #7
0
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;
}
Example #8
0
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.");
        }
    }
}
Example #9
0
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;
	}
}
Example #10
0
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 );
	}
Example #11
0
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;
}
Example #12
0
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);
	}
}
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);
                }
            }
        }
    }
}
Example #14
0
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");
    }
}
Example #15
0
void AnyTest::testDefaultCtor()
{
	const Any value;
	
	assert (value.empty());
	assert (0 == AnyCast<int>(&value));
	assert (value.type() == typeid(void));
}
Example #16
0
Any VisibleEntity::toAny() const {
    Any a = Entity::toAny();
    a.setName("VisibleEntity");
    a.set("visible", m_visible);

    // Model and pose must already have been set, so no need to change anything
    return a;
}
Example #17
0
Any PlayerEntity::toAny(const bool forceAll) const {
    Any a = VisibleEntity::toAny(forceAll);
    a.setName("PlayerEntity");

    a["velocity"] = m_velocity;

    return a;
}
Example #18
0
UprightFrame::UprightFrame(const Any& any) {
    any.verifyName("UprightFrame");
    any.verifyType(Any::TABLE);

    translation = any["translation"];
    pitch = any["pitch"];
    yaw = any["yaw"];
}
Example #19
0
Any MarkerEntity::toAny() const {
    Any a = Entity::toAny();
    a.setName("MarkerEntity");
    a["color"] = m_color;
    a["osBoxArray"] = m_osBoxArray;

    return a;
}
Example #20
0
void MathInterface::functionAbs(void) {
	Any v = cb->popValue();
	if (v.type() == Any::Float) {
		cb->pushValue(abs(v.getFloat()));
		return;
	}
	cb->pushValue(abs(v.getInt()));
	return;
}
Example #21
0
	bool Any::containsKey(const std::string& x) const {
		beforeRead();
		verifyType(TABLE);

		Any* a = m_data->value.t->getPointer(x);

		// Don't return true for placeholder objects
		return (a != NULL) && (!a->isPlaceholder());
	}
Example #22
0
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);
}
Example #23
0
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);
}
Example #24
0
void MathInterface::functionWrapAngle(void) {
	Any a = cb->popValue();
	if (a.type() == Any::Float) {
		cb->pushValue(wrapAngle(a.getFloat()));
	}
	else { // Has to be int
		cb->pushValue(wrapAngle(a.getInt()));
	}
}
Example #25
0
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);
}
Example #26
0
Any PlayerEntity::toAny() const {
    Any a = VisibleEntity::toAny();
    a.setName("PlayerEntity");

    a["velocity"] = m_velocity;
    a["collisionSphere"] = m_collisionProxySphere;

    return a;
}
Example #27
0
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);
}
Example #28
0
Any Any::operator << (const Any &r) const {
	if (this->type() == Any::Int && r.type() == Any::Int) {
		int32_t a = this->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 );
	}
	FIXME("Unsupported operation %s << %s", this->typeInfo().name(), r.typeInfo().name());
	return 0;
}
Example #29
0
bool Any::operator == ( const Any& rhs ) const
{
    if( (this == &rhs) || (empty() && rhs.empty( )))
        return true;

    if( empty() != rhs.empty() || type() != rhs.type( ))
        return false;

    return *content == *rhs.content;
}
ArticulatedModel::PoseSpline::PoseSpline(const Any& any) : castsShadows(true) {
    any.verifyName("ArticulatedModel::PoseSpline");
    for (Any::AnyTable::Iterator it = any.table().begin(); it.isValid(); ++it) {
        if (it->key == "castsShadows") {
            castsShadows = it->value;
        } else {
            partSpline.getCreate(it->key) = it->value;
        }
    }
}