Beispiel #1
0
std::string SharedBase::parseAndSerialize(const std::string& line) {
    //NOTE - The reason we try a pre-defined list of types rather than having
    //the templated job override a virtual parseAndSerialize interface is so
    //that standard users don't have to define istream methods for their custom
    //types.  Only the very first job (that gets input work) would need it
    //defined.  Easy workaround if anyone needs that ability: have a
    //string->UserType job before the real first job.
    std::string typeName = this->getInputTypeName();

    #define TRY_TYPE(T) \
            if (typeName == typeid(T).name()) { \
                T val = boost::lexical_cast<T>(line); \
                return serialization::encodeAsPtr(val); \
            }

    TRY_TYPE(std::string);
    TRY_TYPE(job_stream::python::SerializedPython);
    TRY_TYPE(float);
    TRY_TYPE(double);
    TRY_TYPE(uint64_t);
    TRY_TYPE(int64_t);
    TRY_TYPE(unsigned int);
    TRY_TYPE(int);
    TRY_TYPE(unsigned short);
    TRY_TYPE(short);
    TRY_TYPE(unsigned char);
    TRY_TYPE(char);

    std::ostringstream ss;
    ss << "Unrecognized work type for input: " << typeName;
    throw std::runtime_error(ss.str());
    #undef TRY_TYPE
}
Beispiel #2
0
//
// Create a texture from a Data Source
// (filename is used to help detection of type)
//
Texture * Texture::Create(IDataSource *ds, const char *filename)
{
	Texture *tex;

	if (filename) {
		// Looks like it's a PNG
		if (std::strstr(filename, ".png")) {
			TRY_TYPE(TexturePNG);
		}
		// Looks like it's a BMP
		if (std::strstr(filename, ".bmp")) {
			TRY_TYPE(TextureBitmap);
		}
		// Looks like it's a TGA
		if (std::strstr(filename, ".tga")) {
			TRY_TYPE(TextureTarga);
		}
	}

	// Now go through each type 1 by 1
	TRY_TYPE(TexturePNG);
	TRY_TYPE(TextureBitmap);
	TRY_TYPE(TextureTarga);

	// Couldn't find it
	return 0;
}