Ejemplo n.º 1
0
void ConfigFileWriter::writeRouterModelFile(std::string filename,
                                            NodeSet& ns)
{
    std::fstream out;

    std::set<std::string>::iterator it = ns.modelsUsed().begin();

    if (it != ns.modelsUsed().end())
    {
        out.open(filename.c_str(), std::fstream::out | std::fstream::trunc);
    }

    while (it != ns.modelsUsed().end())
    {
        ParameterMap* parameters = Config::instance().getModelParameterList(*it);
        const Parameter& model = parameters->getParameter("ROUTER-MODEL");
        if (model != Parameter::unknownParameter)
        {
            out << model << std::endl;
            ParameterMap::iterator pit = parameters->begin();
            while (pit != parameters->end())
            {
                if (pit->first != "ROUTER-MODEL")
                    out << pit->second << std::endl;
                pit++;
            }
            out << std::endl;
        }
        it++;
    }
}
bool CSVWriter::init(const ParameterMap& params, const Ports<StreamInfo>& inp)
{
	assert(inp.size()==1);
	const StreamInfo& in = inp[0].data;

	string outputFile = getStringParam("File", params);
	m_precision = getIntParam("Precision",params);
	if (m_precision > (BUFSIZE-10)) {
		cerr << "WARNING: precision is too large ! use precision " << BUFSIZE - 10 << endl;
		m_precision = BUFSIZE - 10;
	}

	int res = preparedirs(outputFile.c_str());
	if (res!=0)
		return false;

	m_fout.open(outputFile.c_str(), ios_base::trunc);
	if (!m_fout.is_open() || m_fout.bad())
		return false;

	if (getStringParam("Metadata",params)=="True") {
		// write metadata at the beginnig of the file
		string paramStr = getStringParam("Attrs",params);
		map<string,string> params = decodeAttributeStr(paramStr);
		ostringstream oss;
		for (map<string,string>::const_iterator it=params.begin();it!=params.end();it++)
			oss << "% " << it->first << "=" << it->second << endl;
		m_fout.write(oss.str().c_str(),oss.str().size());
	}

	return true;
}
Ejemplo n.º 3
0
bool SpecificWorker::setParametersAndPossibleActivation(const ParameterMap &prs, bool &reactivated)
{
	printf("<<< setParametersAndPossibleActivation\n");
	// We didn't reactivate the component
	reactivated = false;

	// Update parameters
	params.clear();
	for (ParameterMap::const_iterator it=prs.begin(); it!=prs.end(); it++)
	{
		printf("param:%s   value:%s\n", it->first.c_str(), it->second.value.c_str());
		params[it->first] = it->second;
	}
	printf("----\n");

	try
	{
		action = "";
		for (uint i=0; i<params["action"].value.size(); i++)
		{
			action += params["action"].value[i];
			if (i+2<params["action"].value.size())
			{
				if (params["action"].value[i+1] == '_' and params["action"].value[i+2] == '_')
					break;
			}
		}
		std::transform(action.begin(), action.end(), action.begin(), ::tolower);
		//
		// action = params["action"].value;

		if (action == "graspobject")
		{
			active = true;
		}
		else
		{
			active = true;
		}
	}
	catch (...)
	{
		printf("exception in setParametersAndPossibleActivation %d\n", __LINE__);
		return false;
	}

	// Check if we should reactivate the component
	if (active)
	{
		active = true;
		reactivated = true;
	}

	printf("setParametersAndPossibleActivation >>>\n");

	return true;
}
// Called to parse a RCSS keyword declaration.
bool PropertyParserKeyword::ParseValue(Property& property, const String& value, const ParameterMap& parameters) const
{
	ParameterMap::const_iterator iterator = parameters.find(value);
	if (iterator == parameters.end())
		return false;

	property.value = Variant((*iterator).second);
	property.unit = Property::KEYWORD;

	return true;
}
Ejemplo n.º 5
0
 void OutputFormat::setParameters(const std::string& outDir,
     const ParameterMap& formatParams)
 {
   m_outDir = outDir;
   m_params.clear();
   ParameterDescriptorList pList = getParameters();
   for (ParameterDescriptorList::iterator it=pList.begin();
       it!=pList.end(); it++) {
     ParameterMap::const_iterator pIt = formatParams.find(it->m_identifier);
     if (pIt!=formatParams.end()) {
       m_params[it->m_identifier] = pIt->second;
     } else {
       m_params[it->m_identifier] = it->m_defaultValue;
     }
   }
 }
Ejemplo n.º 6
0
bool SpecificWorker::setParametersAndPossibleActivation(const ParameterMap &prs, bool &reactivated)
{
	printf("<<< setParametersAndPossibleActivation\n");
	// We didn't reactivate the component
	reactivated = false;

	// Update parameters
	params.clear();
	for (ParameterMap::const_iterator it=prs.begin(); it!=prs.end(); it++)
	{
		params[it->first] = it->second;
	}

	try
	{
		action = params["action"].value;
		std::transform(action.begin(), action.end(), action.begin(), ::tolower);
		//TYPE YOUR ACTION NAME
		if (action == "actionname")
		{
			active = true;
		}
		else
		{
			active = true;
		}
	}
	catch (...)
	{
		printf("exception in setParametersAndPossibleActivation %d\n", __LINE__);
		return false;
	}

	// Check if we should reactivate the component
	if (active)
	{
		active = true;
		reactivated = true;
	}

	printf("setParametersAndPossibleActivation >>>\n");

	return true;
}
Ejemplo n.º 7
0
bool GenericWorker::setParametersAndPossibleActivation(const ParameterMap &prs, bool &reactivated)
{
	// We didn't reactivate the component
	reactivated = false;

	// Update parameters
	for (ParameterMap::const_iterator it=prs.begin(); it!=prs.end(); it++)
	{
		params[it->first] = it->second;
	}

	try
	{
		// Action
		p.action = createAction(params["action"].value);

		// Fill received plan
		p.plan.clear();
		QStringList actionList = QString::fromStdString(params["plan"].value).split(QRegExp("[()]+"), QString::SkipEmptyParts);
		for (int32_t actionString=0; actionString<actionList.size(); actionString++)
		{
			std::vector<string> elementsVec;
			QStringList elements = actionList[actionString].remove(QChar('\n')).split(QRegExp("\\s+"), QString::SkipEmptyParts);
			for (int32_t elem=0; elem<elements.size(); elem++)
			{
				elementsVec.push_back(elements[elem].toStdString());
			}
			p.plan.push_back(elementsVec);
		}
	}
	catch (...)
	{
		return false;
	}

	// Check if we should reactivate the component
	if (isActive())
	{
		activate(p);
		reactivated = true;
	}

	return true;
}
Ejemplo n.º 8
0
 std::string Component::getStringParam(const std::string& id, const ParameterMap& params)
 {
   ParameterMap::const_iterator it=params.find(id);
   if (it!=params.end()) {
     if (it->second.size()==0) {
       cerr << "ERROR: parameter " << id << " is empty !" << endl;
       return EMPTY_STRING;
     }
     return it->second;
   }
   ParameterDescriptorList pList = getParameterDescriptorList();
   for (ParameterDescriptorList::const_iterator descIt=pList.begin();
       descIt!=pList.end(); descIt++)
   {
     if (descIt->m_identifier==id)
       return descIt->m_defaultValue;
   }
   cerr << "ERROR: no parameter " << id << " for component " << getIdentifier() << " !" << endl;
   return EMPTY_STRING;
 }
bool SpecificWorker::setParametersAndPossibleActivation(const ParameterMap &prs, bool &reactivated)
{
	// We didn't reactivate the component
	reactivated = false;

	// Update parameters
	params.clear();
	for (ParameterMap::const_iterator it=prs.begin(); it!=prs.end(); it++)
	{
		params[it->first] = it->second;
	}

	try
	{
		action = params["action"].value;
		std::transform(action.begin(), action.end(), action.begin(), ::tolower);


		if (action == "findobjectvisually")
		{
			active = true;
		}
		else
		{
			active = true;
		}
	}
	catch (...)
	{
		return false;
	}

	// Check if we should reactivate the component
	if (active)
	{
		active = true;
		reactivated = true;
	}

	return true;
}
Ejemplo n.º 10
0
int LuaBinding::ActorAdd()
{
    const char* actorAlias = NULL;
    Vector2i actorPosition;
    if (!Peek(1, &actorAlias) || !Peek(2, &actorPosition))
    {
        return ERROR_TYPE_PARAMETER;
    }

    const char* actorName = NULL;
    Peek(3, &actorName);

    ParameterMap parameters;
    Peek(4, &parameters);

    IWorldContext* worldContext = System::QueryWorldContext();
    if (worldContext == NULL)
    {
        return ERROR_TYPE_STATE;
    }

    const boost::shared_ptr<Actor> actor = worldContext->AddActor(actorAlias, actorPosition, actorName).lock();
    if (!actor)
    {
        return ERROR_TYPE_STATE;
    }

    const boost::shared_ptr<ActorPropertyScript> property = actor->GetProperty<ActorPropertyScript>().lock();
    if (property)
    {
        for (ParameterMap::iterator iter = parameters.begin(); iter != parameters.end(); ++iter)
        {
            property->SetParameter(iter->first.c_str(), iter->second);
        }
    }

    Push(actor->GetId());
    return 1;
}
Ejemplo n.º 11
0
 void printParams(ostream& out, const ParameterMap& params)
 {
   for (ParameterMap::const_iterator pit=params.begin();
       pit!=params.end(); pit++)
     out << " " << pit->first << "=\"" << pit->second << "\"";
 }