Beispiel #1
0
EntityLoader::EntityLoader():
   mLoaders()
{
  registerLoader(new MeshComponentLoader());
  registerLoader(new ParticleComponentLoader());
  registerLoader(new PhysicsComponentLoader());
}
void CrosswordLoadSupportLocator::registerFormats()
{
    // Load and save XWC files (v1.0.1)
    registerLoader(new CrosswordFormat(XWC101), new XWCLoader());
    registerSaver(new CrosswordFormat(XWC101), new XWCSaver());

    // Load and save XWC3D files (v1.0.0)
    registerLoader(new CrosswordFormat(XWC3D100), new XWC3DLoader());
    registerSaver(new CrosswordFormat(XWC3D100), new XWC3DSaver());

    // Across Lite Text support
    //registerLoader(new CrosswordFormat(ACROSSLITETEXT), new AcrossLiteTextLoader());
    // registerSaver(new CrosswordFormat(ACROSSLITETEXT), new AcrossLiteTextSaver());

    // TODO More file support
}
Beispiel #3
0
bool ResCache::init() {
	bool retValue = true;

	for( ResourceFiles::iterator fileItr = m_files.begin(); fileItr != m_files.end(); ++fileItr ) {
		if( !(*fileItr)->VOpen() ) {
			GEN_FATAL("unable to load filename: " + (*fileItr)->VGetResourceFileName());
			retValue = false;
		}
	}

	if( retValue )
		registerLoader(std::shared_ptr<IResourceLoader>(new DefaultResourceLoader()));

	return retValue;
}//ResCache::init
Beispiel #4
0
void ResourceManager::setupResourceLoaders(Class* klass)
{
	for( size_t i = 0; i < klass->childs.size(); i++ )
	{
		Class* child = klass->childs[i];

		if( !child->childs.empty() )
			setupResourceLoaders(child);
	
		if( ClassIsAbstract(child ) ) continue;

		auto loader = (ResourceLoader*) ClassCreateInstance(
			child, GetResourcesAllocator());

		registerLoader( loader );
	}
}
Beispiel #5
0
int main(int argc, char ** argv)
{
    lua_State * L = luaL_newstate();
    
    if (!readTOC(L, argv[0]))
    {
        if (argc < 2)
        {
            // display usage message and exit
            printf("This copy of enceladus has no embedded lua program to run\n");
            printf("Please embed one: enceladus main.lua lib.lua ...\n");
            return 1;
        }
        
        // parse command line and embed lua code, then exit
        parse_args(&argc, &argv);
        
        char * outname = embed(L, argc, argv);
        if (outname)
        {
            printf("Embed successful. Output file: %s\n", outname);
        } else {
            fprintf(stderr, "Embed failed. Aborting.\n");
        }
        
        return 0;
    }
    
    // TOC read successful - we have an embedded lua program to run
    // initialize standard libraries
    luaL_openlibs(L);
    
    // load any statically linked libraries
    enceladus_init_static_libs(L);
    
    // grab the entry point
    // the name is on top of the stack and the table of packed files right
    // below, thanks to readTOC
    lua_gettable(L, -2); // toc{} main()
    if (lua_type(L, -1) != LUA_TFUNCTION)
    {
        fprintf(stderr, "Error loading entry point: %s\n", lua_tostring(L, -1));
        return 1;
    }
    
    // install our custom loader for the embedded libraries
    lua_insert(L, -2);
    if (!registerLoader(L))
    {
        fprintf(stderr, "Error registering custom loader: %s\n", lua_tostring(L, -1));
        return 1;
    }
    
    // marshal arguments into lua
    lua_newtable(L); // toc{} main() arg{}
    for (int i = 0; i < argc; ++i)
    {
        lua_pushstring(L, argv[i]); // toc{} main() arg{} argv[i]
        lua_rawseti(L, -2, i); // toc{} main() arg{}
    }
    lua_setglobal(L, "arg"); // toc{} main()
    
    for (int i = 1; i < argc; ++i)
    {
        lua_pushstring(L, argv[i]); // toc{} main() argv[i]...
    }
    
    // call
    lua_getglobal(L, "debug"); // ... debug
    lua_getfield(L, -1, "traceback"); // ... debug debug.traceback
    lua_insert(L, 1); // debug.traceback ... debug
    lua_pop(L, 1); // debug.traceback ...
    
    if (lua_pcall(L, argc-1, 0, 1) != 0)
    {
        // error handling
        fprintf(stderr, "error: %s\n", lua_tostring(L, -1));
        return 1;
    }
    
    return 0;
}
namespace Ms2Preproc {

class TopXInYRegionsAlgorithm : public libpipe::rtc::Algorithm
{

public:
    static libpipe::rtc::Algorithm* create()
    {
        return new TopXInYRegionsAlgorithm;
    }

    virtual ~TopXInYRegionsAlgorithm()
    {
    }

    void update(libpipe::Request& req)
    {

        boost::shared_ptr<libpipe::rtc::SharedData<mgf::MgfFile> > mgfInputFile =
            boost::dynamic_pointer_cast<
            libpipe::rtc::SharedData<mgf::MgfFile> >(
                this->getPort("MGFInputFile"));
        boost::shared_ptr<libpipe::rtc::SharedData<mgf::MgfFile> > mgfParsedFile =
            boost::dynamic_pointer_cast<
            libpipe::rtc::SharedData<mgf::MgfFile> >(
                this->getPort("MGFParsedFile"));
        LIBPIPE_PIPELINE_TRACE(req, "Starting TopXInYRegions");

        mgfInputFile->shared_lock();
        mgfParsedFile->lock();
        // copy the file so that input is not changed.
        mgfParsedFile->set(new mgf::MgfFile(*mgfInputFile->get()));
        mgfInputFile->unlock();

        // Top X in Y regions

        for (mgf::MgfFile::iterator i = mgfParsedFile->get()->begin();
                i != mgfParsedFile->get()->end(); ++i) {
            // get a temporary object and make sure it is big enough
            mgf::MgfSpectrum m;
            m.resize(2 * i->size());
            // get the top X in Y regions, including duplicated from overlaps
            mgf::MgfSpectrum::iterator sEnd = run(i->begin(), i->end(),
                                                  m.begin(), LessThanMass(), LessThanAbundance());
            // make sure we have enough space in the original object
            i->resize(std::distance(m.begin(), sEnd));
            // unique copy expectes a sorted range
            std::sort(m.begin(), sEnd, LessThanMass());
            // copy all unique peaks back into the original MgfSpectrum
            mgf::MgfSpectrum::iterator iEnd = std::unique_copy(m.begin(),
                                              sEnd, i->begin());
            // crop to fit
            i->resize(std::distance(i->begin(), iEnd));
        }

        mgfParsedFile->unlock();

        LIBPIPE_PIPELINE_TRACE(req, "TopXInYRegions is finished");

    }

protected:

private:
    TopXInYRegionsAlgorithm() :
        libpipe::rtc::Algorithm()
    {
        ports_["MGFInputFile"] = boost::make_shared<
                                 libpipe::rtc::SharedData<mgf::MgfFile> >();
        ports_["MGFParsedFile"] = boost::make_shared<
                                  libpipe::rtc::SharedData<mgf::MgfFile> >(new mgf::MgfFile);
    }

    template<class In, class Out, class MassComp, class AbundanceComp>
    Out run(In begin, In end, Out out, MassComp massComp,
            AbundanceComp abundanceComp)
    {
        // sort a copy
        std::vector<typename In::value_type> v(begin, end);
        std::sort(v.begin(), v.end(), massComp);
        // split the m/z domain in y_ equisized regions
        double maxMz = (v.end() - 1)->first;
        double minMz = (v.begin())->first;
        double increment = (maxMz - minMz)
                           / static_cast<double>(parameters_.get<unsigned int>(
                                       "nregions"));
        if (increment > 2.5) {
            for (unsigned int k = 0;
                    k < parameters_.get<unsigned int>("nregions"); ++k) {
                // iterate over all regions and apply TopX
                double regionBegin = minMz + k * increment - 2.5;
                regionBegin = regionBegin > minMz ? regionBegin : minMz;
                double regionEnd = minMz + (k + 1) * increment + 2.5;
                In regionBeginIt = std::lower_bound(v.begin(), v.end(),
                                                    regionBegin, massComp);
                In regionEndIt = std::upper_bound(v.begin(), v.end(),
                                                  regionEnd, massComp);
                // run TopX on region
                Out nout = runTopX(regionBeginIt, regionEndIt, out,
                                   abundanceComp);
                out = nout;

            }
        } else {
            Out nout = runTopX(v.begin(), v.end(), out, abundanceComp);
            out = nout;
        }
        return out;
    }

    template<class In, class Out, class Comp>
    Out runTopX(In begin, In end, Out out, Comp comp)
    {
        typename In::difference_type size = std::distance(begin, end);
        unsigned int x = parameters_.get<unsigned int>("top");

        // FIXME: Make the static_cast in the next step safe.
        if (static_cast<unsigned int>(size) > x) {
            // sort a copy
            std::vector<typename In::value_type> v(begin, end);
            std::sort(v.begin(), v.end(), comp);
            std::copy(v.rbegin(), v.rbegin() + x, out);
            std::advance(out, x);
        } else {
            // accept all peaks
            std::copy(begin, end, out);
            std::advance(out, size);
        }
        return out;
    }

    static const bool registerLoader()
    {
        std::string ids = "TopXInYRegionsAlgorithm";
        return libpipe::rtc::AlgorithmFactory::instance().registerType(ids,
                TopXInYRegionsAlgorithm::create);
    }
    /// true is class is registered in Algorithm Factory
    static const bool registered_;
};
const bool TopXInYRegionsAlgorithm::registered_ = registerLoader();
}