예제 #1
0
KmlPastebufferType Kml::ParseOnePlacemarkPoint( TiXmlNode* node, wxString& name ) {
    double newLat = 0., newLon = 0.;
    dPointList coordinates;

    if( ParseCoordinates( node->ToElement(), coordinates ) ) {
        newLat = coordinates[0].y;
        newLon = coordinates[0].x;
    }

    if( newLat == 0.0 && newLon == 0.0 ) {
        wxString msg( _T("KML Parser failed to convert <Point> coordinates.") );
        wxLogMessage( msg );
        return KML_PASTE_INVALID;
    }
    wxString pointName = wxEmptyString;
	TiXmlElement* e = node->Parent()->FirstChild( "name" )->ToElement();
    if( e ) pointName = wxString( e->GetText(), wxConvUTF8 );

    wxString pointDescr = wxEmptyString;
    e = node->Parent()->FirstChildElement( "description" );

    // If the <description> is an XML element we must convert it to text,
    // otherwise it gets lost.
    if( e ) {
        TiXmlNode* n = e->FirstChild();
        if( n ) switch( n->Type() ){
            case TiXmlNode::TINYXML_TEXT:
                pointDescr = wxString( e->GetText(), wxConvUTF8 );
                break;
            case TiXmlNode::TINYXML_ELEMENT:
                TiXmlPrinter printer;
                printer.SetIndent( "\t" );
                n->Accept( &printer );
                pointDescr = wxString( printer.CStr(), wxConvUTF8 );
                break;
        }
    }

    // Extended data will override description.
    TiXmlNode* n = node->Parent()->FirstChild( "ExtendedData" );
    if( n ) {
        TiXmlPrinter printer;
        printer.SetIndent( "\t" );
        n->Accept( &printer );
        pointDescr = wxString( printer.CStr(), wxConvUTF8 );
    }

    // XXX leak ?
    parsedRoutePoint = new RoutePoint();
    parsedRoutePoint->m_lat = newLat;
    parsedRoutePoint->m_lon = newLon;
    parsedRoutePoint->m_bIsolatedMark = true;
    parsedRoutePoint->m_bPtIsSelected = false;
    parsedRoutePoint->m_MarkDescription = pointDescr;
    parsedRoutePoint->SetName( pointName );

    return KML_PASTE_WAYPOINT;
}
// QC:A (discussion possible sur l'utilisation de snprintf. Les buffers statiques ne sont pas thread safe.)
char* ScriptVariable::getstr() const {
	if(isPointer()) {
		return getPointee()->getstr();
	}

	if(type == VAR_NULL) {
		return NULL;
	}

	if(type == VAR_INT) {
		static char number[32];
		snprintf(number, 32, "%d", value);
		number[31] ='\0';
		return number;
	}

	if(type == VAR_XML) {
		static TiXmlPrinter printer;
		printer = TiXmlPrinter();
		printer.SetStreamPrinting();
		TiXmlNode* node = (TiXmlNode*) data;
		node->Accept(&printer);
		return (char*)printer.CStr();
	}

	if(type == VAR_OBJ) {
		static char address[256];
		snprintf(address, 256, "(*%p:%s)", data, ((ScriptableObject*)data)->getClassName());
		address[255] ='\0';
		return address;
	}

	if(type == VAR_PAIR) {
		static char number[64];
		snprintf(number, 64, "(%ld:%ld)", (long) data, (long) params);
		number[63] ='\0';
		return number;
	}

	if(type == VAR_PACK) {
		static char info[4096]; // XXX : NOT thread safe
		snprintf(info, 4096, "(*%p => \"%s\")", data, params);
		info[4095] ='\0';
		return info;
	}

	if(type == VAR_TBL) {
		static char info[4096]; // XXX : NOT thread safe
		snprintf(info, 4096, "(tbl[%ld]:*%p)", (long)(data?(((ScriptTable*)data)->size()):0), data);
		info[4095] ='\0';
		return info;
	}

	if(type == VAR_FCT) {
		return params;
	}

	return data;
}