예제 #1
0
        PointExtractorUPtr getPointExtractor(std::stringstream& code)
        {
            char first;
            code.get(first);

            switch (first)
            {
            case 'B':
            {
                auto sex = getSetExtractor(code);

                return PointExtractorUPtr(
                    new BaryCenterExtractor(sex)
                    );
            }
                break;

            case 'P':
            {
                auto uex = getUnitExtractor(code);

                return PointExtractorUPtr(
                    new UnitPositionExtractor(uex)
                    );
            }
                break;

            default:
                throw FactoryException("PointExtractor code not found");
            }
        }
예제 #2
0
MOUL::Creatable* MOUL::Factory::Create(uint16_t type)
{
    switch (type) {
/* THAR BE MAJICK HERE */
#define CREATABLE_TYPE(id, cre) \
    case id: return new cre(id);
#include "creatable_types.inl"
#undef CREATABLE_TYPE
    case 0x8000: return static_cast<Creatable*>(0);
    default:
        fprintf(stderr, "[Factory] Tried to create unknown type %04X\n", type);
        throw FactoryException(FactoryException::e_UnknownType);
    }
}
예제 #3
0
/**
* Make all the object from the the \Parser string, vector<string>
* @return dataMap
*/
dataMap ObjectFactory::transformToObjet(){
	dataMap theObjectMap;
	parserMap theStringMap;

	//string theFichier = "./liste.txt";

	this->theParser->countNbLineInFile();
	int nbLignesFichiers = this->theParser->getNbLigne();

	//Get file
	vector<string> lesLines;
	try{
		lesLines = this->theParser->copyFile();
	}catch(ParserFichier::ParserException e){
		e.what();
	}

	if (nbLignesFichiers < 1)
	{
		throw FactoryException("countNbLineInFile return a < 1 integer", "ObjectFactory.cpp::transformToObjet::43", "> 1 INTEGER") ;
	}


	for (int i = 0; i < nbLignesFichiers; ++i) {
		Medicament theMedoc;
		 // Access to the i line
		theStringMap = this->theParser->splitLine(this->theParser->oneLine(i, lesLines));

		//Check if not empty avoid output_range exception
		if (!theStringMap.begin()->first.empty())
		{
			//new Medicament from the i->first element of the map
			theMedoc.setNomMedicament(theStringMap.begin()->first);

			for (int j = 0; j < theStringMap.begin()->second.size(); ++j)
			{
				//new Effet corresponding to the i->second[j]
				Effet theEffet(theStringMap.begin()->second[j]);
				theMedoc.appendToEffets(theEffet);
				++this->nbEffets; //iterate for nbEffet created during the generation
			}

		}
		// Insert into the dataMap <int, Medicament>
		theObjectMap.insert(std::make_pair(i, theMedoc));
	}


	return theObjectMap;
};
예제 #4
0
        SetExtractorUPtr getSetExtractor(std::stringstream& code)
        {
            char first;
            code.get(first);

            switch (first)
            {
            case 'A':
            {
                return SetExtractorUPtr(
                    new AlliesArmyExtractor()
                    );
            }
                break;

            case 'O':
            {
                return SetExtractorUPtr(
                    new OpponentArmyExtractor()
                    );
            }
            break;

            case 'N':
            {
                char comp;
                char second;
                unsigned int number;

                code.get(comp);
                code.get(second);
                code >> number;

                auto sex = getSetExtractor(code);

                if (second == 'D')
                {
                    auto pex = getPointExtractor(code);
                    return SetExtractorUPtr(new NFarNearExtractor(comp == 'L' ? false : true, number, sex, pex));
                }
                else
                {
                    unsigned int capIndex = second - '0';

                    if (capIndex > 6)
                        capIndex = 6;

                    return SetExtractorUPtr(new NMinMaxCapacityExtractor(comp == 'L' ? NMinMaxCapacityExtractor::MIN : NMinMaxCapacityExtractor::MAX, number, capIndex, sex));
                }
            }
            break;

            case 'T':
            {
                char comp;
                char second;
                float threshold;

                code.get(comp);
                code.get(second);
                
                code << std::setprecision(4) << std::fixed;
                code >> threshold;

                auto sex = getSetExtractor(code);

                if (second == 'D')
                {
                    auto pex = getPointExtractor(code);
                    return SetExtractorUPtr(new ThresholdDistanceExtractor(comp == 'L' ? true : false, threshold, sex, pex));
                }
                else
                {
                    unsigned int capIndex = second - '0';

                    if (capIndex > 6)
                        capIndex = 6;

                    return SetExtractorUPtr(new ThresholdCapacityExtractor(comp == 'L' ? true : false, threshold, capIndex, sex));
                }
            }
            break;

            default:
                throw FactoryException("SetExtractor code not found");
            }
        }