ECS/Project/Project/RDFP/RDFP.cpp
//	Parse a single resource from the file, starting at the specified line.
Parse a single resource from the file, starting at the specified line.
Parse a single resource from the file starting at the specified line .
bool RDFP::parseResource(const std::vector<std::string>& RD, int lineIndex, std::map<std::string, ResourceDescription>& RDM)
{
	auto resourceDescriptionEnd = std::find(RD.begin() + lineIndex, RD.end(), "#end Resource");
	if (resourceDescriptionEnd > RD.end())
	{
		std::cerr << "Error! Resource not completed before End of File. Resource starts at : " << lineIndex << std::endl;
		return false;
	}
	int linesNumber = (int)std::distance(RD.begin() + lineIndex, resourceDescriptionEnd);
	if (linesNumber < 2)
	{
		std::cerr << "Error! Resource is incomplete! Resource starts at : " << lineIndex << std::endl;
		return false;
	}
	std::string resourceNameLine = RD[lineIndex + 1];
	std::string resourceTypeLine = RD[lineIndex + 2];
	std::string resourceName = StringModifiers::split_string(resourceNameLine, "=")[1];
	std::string resourceType = StringModifiers::split_string(resourceTypeLine, "=")[1];
	(RDM[resourceName].getProperties())["Resource Name"] = StringModifiers::trimmed(resourceName);
	(RDM[resourceName].getProperties())["Resource Type"] = StringModifiers::trimmed(resourceType);
	for (int i = lineIndex + 3; i < (lineIndex + linesNumber); i++)
	{
		if (shouldIgnoreLine(RD[i]))
			continue;
		std::string currentProperty = StringModifiers::trimmed(StringModifiers::split_string(RD[i], "=")[0]);
		std::string currentValue = StringModifiers::trimmed(StringModifiers::split_string(RD[i], "=")[1]);
		(RDM[resourceName].getProperties())[currentProperty] = currentValue;
	}
	return true;
}
bool RDFP :: parseResource ( const std :: vector < std :: string > & RD , int lineIndex , std :: map < std :: string , ResourceDescription > & RDM ) { auto resourceDescriptionEnd = std :: find ( RD . begin ( ) + lineIndex , RD . end ( ) , " " ) ; if ( resourceDescriptionEnd > RD . end ( ) ) { std :: cerr << " " << lineIndex << std :: endl ; return false ; } int linesNumber = ( int ) std :: distance ( RD . begin ( ) + lineIndex , resourceDescriptionEnd ) ; if ( linesNumber < 2 ) { std :: cerr << " " << lineIndex << std :: endl ; return false ; } std :: string resourceNameLine = RD [ lineIndex + 1 ] ; std :: string resourceTypeLine = RD [ lineIndex + 2 ] ; std :: string resourceName = StringModifiers :: split_string ( resourceNameLine , " " ) [ 1 ] ; std :: string resourceType = StringModifiers :: split_string ( resourceTypeLine , " " ) [ 1 ] ; ( RDM [ resourceName ] . getProperties ( ) ) [ " " ] = StringModifiers :: trimmed ( resourceName ) ; ( RDM [ resourceName ] . getProperties ( ) ) [ " " ] = StringModifiers :: trimmed ( resourceType ) ; for ( int i = lineIndex + 3 ; i < ( lineIndex + linesNumber ) ; i ++ ) { if ( shouldIgnoreLine ( RD [ i ] ) ) continue ; std :: string currentProperty = StringModifiers :: trimmed ( StringModifiers :: split_string ( RD [ i ] , " " ) [ 0 ] ) ; std :: string currentValue = StringModifiers :: trimmed ( StringModifiers :: split_string ( RD [ i ] , " " ) [ 1 ] ) ; ( RDM [ resourceName ] . getProperties ( ) ) [ currentProperty ] = currentValue ; } return true ; }
Parse a single resource from the file, starting at the specified line.
Parse a single resource from the file starting at the specified line .
//	Locate the End of the State Type Description. //	Check if we reached the end of the file before the end of the description. //	Compute the number of lines between the start and the end of the resource. //	Check if we have the minimum number of lines. //	The State Name and Type. //	Iterate over all the remaining resources. //	Check if we should ignore the specified line. //	Get the current property and the value. //	Add it to the current map.