Ejemplo n.º 1
0
string CGIOutput::URLDecodeString(string s) {
  string outputString=s;

  stringReplaceAll (&outputString, "+", " ");
  stringReplaceAll (&outputString, "%23", "#");
  stringReplaceAll (&outputString, "%28", "(");
  stringReplaceAll (&outputString, "%29", ")");
  stringReplaceAll (&outputString, "%20", " ");
  stringReplaceAll (&outputString, "%2C", ",");

  return outputString;
}
Ejemplo n.º 2
0
string CGIOutput::URLEncodeString(string s) {
  string outputString=s;

  stringReplaceAll (&outputString, " ", "+");
  stringReplaceAll (&outputString, "#", "%23");
  stringReplaceAll (&outputString, "(", "%28");
  stringReplaceAll (&outputString, ")", "%29");
  stringReplaceAll (&outputString, " ", "%20");
  stringReplaceAll (&outputString, ",", "%2C");

  return outputString;
}
Ejemplo n.º 3
0
void SceneModel::visualize( NewRayMarchWidget * widg, bool propogateErrors )
{
	std::string file;
	ScriptParser * parser = ScriptParser::makeRegular();

	InSceneJointWidget * topJoint = new InSceneJointWidget( structures[0] );
	for( unsigned int structureIndex = 1; structureIndex < structures.size(); structureIndex++ )
	{
		topJoint = new InSceneJointWidget( topJoint, new InSceneJointWidget( structures[structureIndex] ) );
	}

	try
	{
		std::ifstream t("Assets/clparts/clheader.cl");
		std::string header((std::istreambuf_iterator<char>(t)),
						 std::istreambuf_iterator<char>());
		t.close();

		file += header;


		std::string partsString = "";
		std::string sceneCalcString = "";

		//Get the string representing all of the parts as well as their tree structure
		traverseJointRelationships( topJoint, &partsString, &sceneCalcString, parser );
		file += partsString;

		//Create all of the cases for the normal switch statement
		std::string normalCases = "";
		for( unsigned int structureIndex = 0; structureIndex < structures.size(); structureIndex++ )
		{
			normalCases += "\t\tcase " + std::to_string( structureIndex ) + ": result = normalFunction_" + std::to_string( structureIndex ) + "( origin, direction, distTraveled, sceneVars ); break;\n";
		}

		//Draw everything together
		std::ifstream inj("Assets/clparts/clcalcinjection.cl");
		std::string calcInjection = std::string((std::istreambuf_iterator<char>(inj)),
						std::istreambuf_iterator<char>());
		inj.close();
		stringReplaceAll( &calcInjection, "$$DISTCALCINJECTION$$", sceneCalcString );
		stringReplaceAll( &calcInjection, "$$NORMALINJECTION$$", normalCases );
		file += calcInjection;


		//Put the core kernel in
		std::ifstream ft("Assets/clparts/clcombinedfooter.cl");
		std::string footer = std::string((std::istreambuf_iterator<char>(ft)),
						std::istreambuf_iterator<char>());
		ft.close();
		file += footer;

		std::cout << file << std::endl;


		std::ofstream of_c("Assets/temp/testAll.cl", std::ios_base::binary);
		of_c << file;
		of_c.close();
		
		widg->load( "Assets/temp/testAll.cl" );
	}
	catch( char * except )
	{
		if( propogateErrors )
			throw except;
	}
}
Ejemplo n.º 4
0
std::string SceneModel::getStructureRepresentation( ScriptParser * parser, InSceneStructureWidget * structure, int index )
{
	//Write accessors to the scene variables
	std::string sceneVars = "";
	for( unsigned int i = 1; i < variables.size(); i++ )
	{
		sceneVars += "\r\tfrac " + variables[i].name + " = sceneVarData["+std::to_string(i)+"];";
	}
	sceneVars += "\r\r";

	//Parse the scripts that represent the outlets in relation to scene variables
	auto chil = structure->outletList->findChildren<QLineEdit*>();
	std::string outletStatements = "";
	for( int i = 0; i < chil.size(); i++ )
	{
		std::string s = chil.at(i)->text().toStdString();
		ScriptNode * node = parser->parseLine( s );
		Block b;
		b.addChild( node );
		for( unsigned int j = 1; j < variables.size(); j++ )
		{
			b.variablesInScope[ variables[j].name ] = VariablePacket( Value() );
		}
		outletStatements += "\r\tfrac " + structure->st.outletNames[ i ] + " = " + ScriptParser::textOf( node, 0, false ) + ";";
	}
	outletStatements += "\r\r";

	StructureObject structObject = StructureObject::load( structure->st.name );
	Block * script = parser->parse( structObject.codeBlocks[ structure->currentType ] );

	//Declare outlets
	for( int i = 0; i < structure->st.numOutlets; i++ )
	{
		script->variablesInScope[ structure->st.outletNames[i] ] = VariablePacket( Value() );
	}

	//Declare parameters
	script->variablesInScope[ "x" ] = VariablePacket( Value() );
	script->variablesInScope[ "y" ] = VariablePacket( Value() );
	script->variablesInScope[ "z" ] = VariablePacket( Value() );
	script->variablesInScope[ "r" ] = VariablePacket( Value(), true );
	script->variablesInScope[ "g" ] = VariablePacket( Value(), true );
	script->variablesInScope[ "b" ] = VariablePacket( Value(), true );

	//Pull ray cast functionality part
	std::string rayPart = "";
	std::string scriptPart = "";
	if( structure->currentType == 0 )
	{
		std::ifstream t("Assets/clparts/clpartSUBSET.cl");
		rayPart = std::string((std::istreambuf_iterator<char>(t)),
							std::istreambuf_iterator<char>());
		t.close();
	}
	else
	if( structure->currentType == 1 )
	{
		std::ifstream t("Assets/clparts/clpartDISTANCE.cl");
		rayPart = std::string((std::istreambuf_iterator<char>(t)),
							std::istreambuf_iterator<char>());
		t.close();
	}
	else
	if( structure->currentType == 2 )
	{
		script->variablesInScope[ "dx" ] = VariablePacket( Value() );
		script->variablesInScope[ "dy" ] = VariablePacket( Value() );
		script->variablesInScope[ "dz" ] = VariablePacket( Value() );
		script->variablesInScope[ "dist" ] = VariablePacket( Value(), true );

		std::ifstream t("Assets/clparts/clpartTRACE.cl");
		rayPart = std::string((std::istreambuf_iterator<char>(t)),
							std::istreambuf_iterator<char>());
		t.close();
	}

	//Seam everything together and replace hotlinks
	scriptPart = sceneVars + outletStatements + parser->textOf( script, 0, true );
	stringReplaceAll( &rayPart, "$$FUNCTIONINJECTION$$", scriptPart );
	stringReplaceAll( &rayPart, "$$NUM$$", std::to_string( index ) );
	
	return rayPart + "\n\n";
}
Foam::string Foam::equationReader::stringPreconditioner
(
    const string& rawText
)
{
    string rawWorking(rawText);

    // Negative exponent workaround
    for (label i = 0; i < 10; i++)
    {
        string strTemp(name(i));
        string strTempU(name(i));
        string strTemp2(name(i));
        strTemp.append("e-");
        strTempU.append("E-");
        strTemp2.append("&");
        stringReplaceAll(rawWorking, strTemp, strTemp2);
        stringReplaceAll(rawWorking, strTempU, strTemp2);
    }

    stringReplaceAll(rawWorking, "^", " : ");
    stringReplaceAll(rawWorking, "(", " ( ");
    stringReplaceAll(rawWorking, ")", " ) ");
    stringReplaceAll(rawWorking, "+", " + ");
    stringReplaceAll(rawWorking, "-", " - ");
    stringReplaceAll(rawWorking, "&", "e-");
    stringReplaceAll(rawWorking, "*", " * ");
    stringReplaceAll(rawWorking, "/", " / ");
    stringReplaceAll(rawWorking, ",", " , ");

    return rawWorking;
}