⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datastorereader.cpp

📁 GPS Manager is a GUI for downloading, organizing, maintaining, and uploading GPS data (i.e. tracks,
💻 CPP
字号:
/*gpsmgr: A program for managing GPS informationCopyright (C) 2003 Austin BinghamThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.You can reach the author at:    abingham@spamcop.net*/#include "datastorereader.h"#include "datastore.h"#include "saxReaderBase.h"#include <sstream>using namespace gpsmgr::io::util;namespace{    SAXReaderBase::Phase P_DATASTORE;        SAXReaderBase::Phase P_WAYPOINT;    SAXReaderBase::Phase P_WP_NAME;    SAXReaderBase::Phase P_WP_POSITION;    SAXReaderBase::Phase P_WP_LAT;    SAXReaderBase::Phase P_WP_LON;    SAXReaderBase::Phase P_WP_ALTITUDE;    SAXReaderBase::Phase P_WP_SYMBOL;    SAXReaderBase::Phase P_WP_DISPLAYOPTION;    SAXReaderBase::Phase P_WP_COMMENT;    SAXReaderBase::Phase P_WP_GROUP;    SAXReaderBase::Phase P_TRACK;    SAXReaderBase::Phase P_TRK_NAME;    SAXReaderBase::Phase P_TRK_COMMENT;    SAXReaderBase::Phase P_TRK_POINT;    SAXReaderBase::Phase P_TRK_POSITION;    SAXReaderBase::Phase P_TRK_LAT;    SAXReaderBase::Phase P_TRK_LON;    SAXReaderBase::Phase P_TRK_ALTITUDE;    SAXReaderBase::Phase P_TRK_TIME;    }namespace gpsmgr { namespace io {        class DataStoreReader : public SAXReaderBase    {    public:	DataStoreReader(DataStore& ds) :	    mDataStore (&ds)	    {		addTagMapping("datastore", &P_DATASTORE);		addTagMapping("waypoint", &P_WAYPOINT, &P_DATASTORE);		addTagMapping("name", &P_WP_NAME, &P_WAYPOINT);		addTagMapping("position", &P_WP_POSITION, &P_WAYPOINT);		addTagMapping("lat", &P_WP_LAT, &P_WP_POSITION);		addTagMapping("lon", &P_WP_LON, &P_WP_POSITION);		addTagMapping("altitude", &P_WP_ALTITUDE, &P_WAYPOINT);		addTagMapping("symbol", &P_WP_SYMBOL, &P_WAYPOINT);		addTagMapping("displayoption", &P_WP_DISPLAYOPTION, &P_WAYPOINT);		addTagMapping("comment", &P_WP_COMMENT, &P_WAYPOINT);		addTagMapping("group", &P_WP_GROUP, &P_WAYPOINT);		addTagMapping("track", &P_TRACK);		addTagMapping("name", &P_TRK_NAME, &P_TRACK);		addTagMapping("comment", &P_TRK_COMMENT, &P_TRACK);		addTagMapping("track_point", &P_TRK_POINT, &P_TRACK);		addTagMapping("position", &P_TRK_POSITION, &P_TRK_POINT);		addTagMapping("lat", &P_TRK_LAT, &P_TRK_POSITION);		addTagMapping("lon", &P_TRK_LON, &P_TRK_POSITION);		addTagMapping("altitude", &P_TRK_ALTITUDE, &P_TRK_POINT);		addTagMapping("time", &P_TRK_TIME, &P_TRK_POINT);				ignoreUnmappedTags(true);	    }	bool characters (const QString& ch)	    {		using namespace std;		const Phase* phase = getCurrentPhase();		if (phase == &P_WP_NAME)		{		    mCurrWaypoint.setName(ch);		}		if (phase == &P_WP_LAT)		{		    LatLon ll = mCurrWaypoint.position();		    Latitude lat;		    istringstream iss(ch.latin1());		    iss >> lat;		    ll.setLat(lat);		    mCurrWaypoint.setPosition(ll);		}		else if (phase == &P_WP_LON)		{		    LatLon ll = mCurrWaypoint.position();		    		    Longitude lon;		    istringstream iss(ch.latin1());		    iss >> lon;		    ll.setLon(lon);		    mCurrWaypoint.setPosition(ll);		}		else if (phase == &P_WP_ALTITUDE)		{		    DistFt alt;		    istringstream iss(ch.latin1());		    iss >> alt;		    mCurrWaypoint.setAltitude(alt);		}		else if (phase == &P_WP_SYMBOL)		{		    mCurrWaypoint.setSymbol(ch);		}		else if (phase == &P_WP_DISPLAYOPTION)		{		    mCurrWaypoint.setDisplayOption(ch);		}		else if (phase == &P_WP_COMMENT)		{		    mCurrWaypoint.setComment(ch);		}		else if (phase == &P_WP_GROUP)		{		    mCurrWaypoint.addGroup(ch);		}		else if (phase == &P_TRK_NAME)		{		    mCurrTrack.setName(ch);		}   		else if (phase == &P_TRK_COMMENT)		{		    mCurrTrack.setComment(ch);		}		else if (phase == &P_TRK_LAT)		{		    LatLon ll = mCurrTrackPoint.position();		    Latitude lat;		    istringstream iss(ch.latin1());		    iss >> lat;		    ll.setLat(lat);		    mCurrTrackPoint.setPosition(ll);		}		else if (phase == &P_TRK_LON)		{		    LatLon ll = mCurrTrackPoint.position();		    Longitude lon;		    istringstream iss(ch.latin1());		    iss >> lon;		    ll.setLon(lon);		    mCurrTrackPoint.setPosition(ll);		}		else if (phase == &P_TRK_ALTITUDE)		{		    DistFt alt;		    istringstream iss(ch.latin1());		    iss >> alt;		    mCurrTrackPoint.setAltitude(alt);		}		else if (phase == &P_TRK_TIME)		{		    UnixTime tm;		    istringstream iss(ch.latin1());		    iss >> tm;		    mCurrTrackPoint.setTime(tm);		}		return true;	    }	    protected:	bool startElementPostPhaseChange(const QString& namespaceURI,					 const QString& localName,					 const QString& rawName,					 const QXmlAttributes& atts,					 Phase* phase)	    {		if (phase == &P_WAYPOINT)		{		    mCurrWaypoint.clearGroups();		}		else if (phase == &P_TRACK)		{		    mCurrTrack.clearGroups();		}				return true;	    }		bool endElementPrePhaseChange(const QString& namespaceURI,				      const QString& localName,				      const QString& rawName,				      Phase* phase)	    {		if (phase == &P_WAYPOINT)		{		    mDataStore->waypoints().add(mCurrWaypoint);		}		else if (phase == &P_TRACK)		{		    mDataStore->tracks().add(mCurrTrack);		}		else if (phase == &P_TRK_POINT)		{		    mCurrTrack.points().push_back(mCurrTrackPoint);		}				return true;	    }	    private:	DataStore* mDataStore;	DataStore::WaypointType mCurrWaypoint;	DataStore::TrackType mCurrTrack;	DataStore::TrackType::PointType mCurrTrackPoint;    };    void readDataStore(QXmlInputSource& input, DataStore& ds)    {	DataStoreReader(ds).parse(input);    }        void readDataStore(const string& filename, DataStore& ds)    {	QFile file(filename);	QXmlInputSource is(file);	readDataStore(is, ds);    }    } }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -