Example #1
0
//  *******************************************************************************************************************
const weak_ptr<IXMLNode> cXMLNode::VAddElement(const cString & ElementName, const cString & ElementValue)
{
	const shared_ptr<cXMLNode> pNode(DEBUG_NEW cXMLNode());
	pNode->m_pElement = m_pDoc->NewElement(ElementName.GetData());
	pNode->m_pDoc = m_pDoc;

	if (!ElementValue.IsEmpty())
	{
		XMLText * pText = m_pDoc->NewText(ElementValue.GetData());
		pNode->m_pElement->InsertEndChild(pText);
	}

	m_pElement->LinkEndChild(pNode->m_pElement);
	m_ChildNodes.push_back(pNode);
	return pNode;
}
Example #2
0
//  *******************************************************************************************************************
void cString::Insert(const int index, const cString & text)
{
    if (index >= 0 && index <= GetLength())
    {
        m_str.insert(index, text.GetData());
    }
}
Example #3
0
//  *******************************************************************************************************************
const shared_ptr<IXMLNode> cXMLNode::Parse(const cString & XML, const unsigned int Size)
{
	SP_LOG(3, "Parsing XML file ");
	const shared_ptr<cXMLNode> pNode(DEBUG_NEW cXMLNode());

	pNode->m_pDoc = shared_ptr<XMLDocument>(DEBUG_NEW XMLDocument());
	int error = pNode->m_pDoc->Parse(XML.GetData(), Size);
	SP_ASSERT_ERROR(error == XML_NO_ERROR)(pNode->m_pDoc->GetErrorStr1())(pNode->m_pDoc->GetErrorStr2()).SetCustomMessage("Could not parse XML file");

	pNode->m_pElement = pNode->m_pDoc->FirstChildElement();

	pNode->AddChildElements();
	return pNode;
}
Example #4
0
//  *******************************************************************************************************************
const shared_ptr<IXMLNode> cXMLNode::Load(const cString & FilePath)
{
	SP_LOG(3, "Loading XML file")(FilePath);
	const shared_ptr<cXMLNode> pNode(DEBUG_NEW cXMLNode());

	pNode->m_pDoc = shared_ptr<XMLDocument>(DEBUG_NEW XMLDocument());
	int error = pNode->m_pDoc->LoadFile(FilePath.GetData());
	SP_ASSERT_ERROR(error == XML_NO_ERROR)(FilePath).SetCustomMessage("Could not load XML file");

	pNode->m_pElement = pNode->m_pDoc->FirstChildElement();

	pNode->AddChildElements();
	return pNode;
}
Example #5
0
//  *******************************************************************************************************************
const shared_ptr<IXMLNode> cXMLNode::InitializeForSave(const cString & RootName, const cString & StyleSheetPath)
{
	const shared_ptr<cXMLNode> pNode(DEBUG_NEW cXMLNode());
	pNode->m_pDoc = shared_ptr<XMLDocument>(DEBUG_NEW XMLDocument());

	pNode->m_pDoc->InsertEndChild(pNode->m_pDoc->NewDeclaration(NULL));

	if (!StyleSheetPath.IsEmpty())
	{
		cString str = "xml-stylesheet type=\"text/xsl\" href=\"" + StyleSheetPath + "\"";
		pNode->m_pDoc->InsertEndChild(pNode->m_pDoc->NewDeclaration(str.GetData()));
	}
	pNode->m_pElement = pNode->m_pDoc->NewElement(RootName.GetData());  
	pNode->m_pDoc->InsertEndChild(pNode->m_pElement);

	return pNode;
}
Example #6
0
//  *******************************************************************************************************************
tOptional<int> cString::FindLastNotOfAny(const cString & characters, const int lastIndex) const
{
    if (IsEmpty())
    {
        return tOptional<int>();
    }

    tOptional<int> val;

    std::string::size_type pos = m_str.find_last_not_of(characters.GetData(), lastIndex);
    if(pos == std::string::npos)
    {
        val.clear();
    }
    else
    {
        val = pos;
    }

    return val;
}
Example #7
0
//  *******************************************************************************************************************
tOptional<int> cString::FindFirstOfAny(const cString & characters, const int offset) const
{
    if (IsEmpty())
    {
        return tOptional<int>();
    }

    tOptional<int> val;

    std::string::size_type pos = m_str.find_first_of(characters.GetData(), offset);
    if(pos == std::string::npos)
    {
        val.clear();
    }
    else
    {
        val = pos;
    }

    return val;
}
Example #8
0
//  *******************************************************************************************************************
void cXMLNode::VSave(const cString & FilePath)
{
	m_pDoc->SaveFile(FilePath.GetData());
}
Example #9
0
//  *******************************************************************************************************************
cString cXMLNode::VGetNodeAttribute(const cString & AttributeName) const
{
	return m_pElement->Attribute(AttributeName.GetData());
}
Example #10
0
//  *******************************************************************************************************************
void cXMLNode::VAddAttribute(const cString & AttributeName, const bool AttributeValue)
{
	m_pElement->SetAttribute(AttributeName.GetData(), AttributeValue);
}
Example #11
0
//  *******************************************************************************************************************
void cXMLNode::VAddComment(const cString & Comment)
{
	m_pElement->InsertEndChild(m_pDoc->NewComment(Comment.GetData()));
}
void cGeneticAlgorithm::GenerateHtml(const cString& fileNamePrefix)
{
	static int htmlIndex = 0;
	IFileIO * pFile = IFileIO::CreateFileIO();
	GenomeDataList data = m_Population[0].m_Data;
	data.push_back(data[0]);

	if(pFile->VOpenFile(cStringUtilities::MakeFormatted("Routes/%s_%d.html", fileNamePrefix.GetData(), htmlIndex), ios_base::out))
	{
		pFile->VWriteLine("<!DOCTYPE html>\n");
		pFile->VWriteLine("<html lang=\"en\">\n");
		pFile->VWriteLine("\t<head>\n");
		pFile->VWriteLine("\t\t<meta charset=\"utf-8\">\n");
		//pFile->VWriteLine("\t<meta name="viewport" content="initial-scale=1.0, user-scalable=no">\n");
		//pFile->VWriteLine("\t<meta name="description" content="Randy Olson uses machine learning to find the optimal road trip across the U.S.">
		pFile->VWriteLine("\t\t<meta name=\"author\" content=\"Ankur Sheel\">\n");

		pFile->VWriteLine("\t\t<title>The optimal road trip using GA</title>\n");
		pFile->VWriteLine("\t\t<style>\n");
		pFile->VWriteLine("\t\t\thtml, body, #map-canvas {\n");
		pFile->VWriteLine("\t\t\t\theight: 100%;\n");
		pFile->VWriteLine("\t\t\t\tmargin: 0px;\n");
		pFile->VWriteLine("\t\t\t\tpadding: 0px\n");
		pFile->VWriteLine("\t\t\t}\n");
		pFile->VWriteLine("\t\t\t#panel {\n");
		pFile->VWriteLine("\t\t\t\tposition: absolute;\n");
		pFile->VWriteLine("\t\t\t\ttop: 5px;\n");
		pFile->VWriteLine("\t\t\t\tleft: 50%;\n");
		pFile->VWriteLine("\t\t\t\tmargin-left: -180px;\n");
		pFile->VWriteLine("\t\t\t\tz-index: 5;\n");
		pFile->VWriteLine("\t\t\t\tbackground-color: #fff;\n");
		pFile->VWriteLine("\t\t\t\tpadding: 10px;\n");
		pFile->VWriteLine("\t\t\t\tborder: 1px solid #999;\n");
		pFile->VWriteLine("\t\t\t}\n");
		pFile->VWriteLine("\t\t</style>\n");
		pFile->VWriteLine("\t\t<script src=\"https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true\"></script>\n");
		pFile->VWriteLine("\t\t<script>\n");

		const int googleWaypointsAllowed  = 8;
		int numberOfDirectionVariables = static_cast<int>(ceil(data.size() / static_cast<float>(googleWaypointsAllowed)));
		for (int directionIndex = 1; directionIndex <= numberOfDirectionVariables; directionIndex++)
		{
			pFile->VWriteLine(cStringUtilities::MakeFormatted("\t\t\tvar directionsDisplay%d\n", directionIndex));
		}
		pFile->VWriteLine("\t\t\tvar markerOptions = {icon: \"http://maps.gstatic.com/mapfiles/markers2/marker.png\"};\n");
		pFile->VWriteLine("\t\t\tvar directionsDisplayOptions = {preserveViewport: true,\n");
		pFile->VWriteLine("\t\t\t\tmarkerOptions: markerOptions};\n");
		pFile->VWriteLine("\t\t\tvar directionsService = new google.maps.DirectionsService();\n");
		pFile->VWriteLine("\t\t\tvar map;\n");
		pFile->VWriteLine("\t\t\t\n");
		pFile->VWriteLine("\t\t\tfunction initialize() {\n");
		pFile->VWriteLine("\t\t\t\tvar center = new google.maps.LatLng(39, -96);\n");
		pFile->VWriteLine("\t\t\t\tvar mapOptions = {\n");
		pFile->VWriteLine("\t\t\t\t\tzoom: 5,\n");
		pFile->VWriteLine("\t\t\t\t\tcenter: center\n");
		pFile->VWriteLine("\t\t\t\t};\n");
		pFile->VWriteLine("\t\t\t\tmap = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);\n");
		for (int directionIndex = 1; directionIndex <= numberOfDirectionVariables; directionIndex++)
		{
			pFile->VWriteLine(cStringUtilities::MakeFormatted("\t\t\t\tdirectionsDisplay%d.setMap(map);\n", directionIndex));
			pFile->VWriteLine(cStringUtilities::MakeFormatted("\t\t\t\tdirectionsDisplay%d.setPanel(document.getElementById('directionsPanel'));\n", directionIndex));
		}
		pFile->VWriteLine("\t\t\t}\n");
		pFile->VWriteLine("\t\t\t\n");
		pFile->VWriteLine("\t\t\tfunction calcRoute(start, end, routes) {\n");
		pFile->VWriteLine("\t\t\t\tswitch (start) {\n");
		int directionIndex = 1;
		for (int startIndex = 0; startIndex < data.size(); startIndex= startIndex + googleWaypointsAllowed)
		{
			cString route = "\t\t\t\t\tcase \"" + m_WaypointNames[data[startIndex]].GetString() + "\":\n";
			route += cStringUtilities::MakeFormatted("\t\t\t\t\t\tdirectionsDisplay%d= new google.maps.DirectionsRenderer(directionsDisplayOptions);\n", directionIndex);
			route += "\t\t\t\t\t\tbreak;\n";
			pFile->VWriteLine(route);
			directionIndex++;
		}
		pFile->VWriteLine("\t\t\t\t}\n");
		pFile->VWriteLine("\n");
		pFile->VWriteLine("\t\t\t\tvar waypts = [];\n");
		pFile->VWriteLine("\t\t\t\t\tfor (var i = 0; i < routes.length; i++) {\n");
		pFile->VWriteLine("\t\t\t\t\t\twaypts.push({\n");
		pFile->VWriteLine("\t\t\t\t\t\tlocation:routes[i],\n");
		pFile->VWriteLine("\t\t\t\t\t\tstopover:true});\n");
		pFile->VWriteLine("\t\t\t\t}\n");
		pFile->VWriteLine("\n");
		pFile->VWriteLine("\t\t\t\tvar request = \"\";\n");
		pFile->VWriteLine("\t\t\t\tif (waypts.length > 0) {\n");
		pFile->VWriteLine("\t\t\t\t\trequest = {\n");
		pFile->VWriteLine("\t\t\t\t\t\torigin: start,\n");
		pFile->VWriteLine("\t\t\t\t\t\tdestination: end,\n");
		pFile->VWriteLine("\t\t\t\t\t\twaypoints: waypts,\n");
		pFile->VWriteLine("\t\t\t\t\t\toptimizeWaypoints: false,\n");
		pFile->VWriteLine("\t\t\t\t\t\ttravelMode: google.maps.TravelMode.DRIVING\n");
		pFile->VWriteLine("\t\t\t\t\t};\n");
		pFile->VWriteLine("\t\t\t\t}\n");
		pFile->VWriteLine("\t\t\t\telse {\n");
		pFile->VWriteLine("\t\t\t\t\trequest = {\n");
		pFile->VWriteLine("\t\t\t\t\t\torigin: start,\n");
		pFile->VWriteLine("\t\t\t\t\t\tdestination: end,\n");
		pFile->VWriteLine("\t\t\t\t\t\ttravelMode: google.maps.TravelMode.DRIVING\n");
		pFile->VWriteLine("\t\t\t\t\t};\n");
		pFile->VWriteLine("\t\t\t\t}\n");
		pFile->VWriteLine("\t\t\t\tdirectionsService.route(request, function(response, status) {\n");
		pFile->VWriteLine("\t\t\t\t\tif (status == google.maps.DirectionsStatus.OK) {\n");
		pFile->VWriteLine("\t\t\t\t\t\tswitch (start) {\n");
		
		directionIndex = 1;
		for (int startIndex = 0; startIndex < data.size(); startIndex= startIndex + googleWaypointsAllowed)
		{
			cString route = "\t\t\t\t\t\t\tcase \"" + m_WaypointNames[data[startIndex]].GetString() + "\":\n";
			route += cStringUtilities::MakeFormatted("\t\t\t\t\t\t\t\tdirectionsDisplay%d.setDirections(response);\n", directionIndex);
			route += "\t\t\t\t\t\t\t\tbreak;\n";
			pFile->VWriteLine(route);
			directionIndex++;
		}
		pFile->VWriteLine("\t\t\t\t\t\t}\n");
		pFile->VWriteLine("\t\t\t\t\t}\n");
		pFile->VWriteLine("\t\t\t\t});\n");
		pFile->VWriteLine("\t\t\t}\n");
		pFile->VWriteLine("\t\t\tgoogle.maps.event.addDomListener(window, 'load', initialize);\n");
		int waypointIndex = 0;
		while (waypointIndex < data.size())
		{
			int startIndex = waypointIndex;
			int endIndex = startIndex + googleWaypointsAllowed;
			if(endIndex >= data.size())
			{
				endIndex = data.size() - 1;
			}
			cString route = "\t\t\tcalcRoute(\"" + m_WaypointNames[data[startIndex]].GetString() + "\", \"" + m_WaypointNames[data[endIndex]].GetString() + "\", [";
			startIndex++;
			for (; startIndex < endIndex; startIndex++)
			{
				route += "\"" + m_WaypointNames[data[startIndex]].GetString() + "\"";
				if (startIndex < (endIndex - 1))
				{
					route += ", ";
				}
			}
			route += "]);\n";
			waypointIndex += googleWaypointsAllowed;
			pFile->VWriteLine(route);
		}
		pFile->VWriteLine("\t\t</script>\n");
		pFile->VWriteLine("\t</head>\n");
		pFile->VWriteLine("\t<body>\n");
		pFile->VWriteLine("\t\t<div id=\"map-canvas\" style=\"float:left;width:70%; height:100%\"></div>\n");
		pFile->VWriteLine("\t\t<div id=\"directionsPanel\" style=\"float:right;width:30%;height 100%\">\n");
		//pFile->VWriteLine("\t\t<p>Total Distance: <span id=\"total\"></span></p>\n");

		pFile->VWriteLine("\t</body>\n");
		pFile->VWriteLine("</html>\n");
		pFile->VCloseFile();
	}
	SafeDelete(&pFile);
	htmlIndex++;
}
Example #13
0
//  *******************************************************************************************************************
void cString::operator+=(const cString & str)
{
    m_str.append(str.GetData());
}
Example #14
0
//  *******************************************************************************************************************
int cString::CompareInsensitive(const cString & str) const
{
    return _stricmp(GetData(), str.GetData());
}