File indexing completed on 2024-05-12 03:50:41
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org> 0004 // 0005 0006 #ifndef MARBLE_WAYPOINTPARSER_H 0007 #define MARBLE_WAYPOINTPARSER_H 0008 0009 #include "RoutingWaypoint.h" 0010 #include "marble_export.h" 0011 0012 #include <QMap> 0013 #include <QVariant> 0014 #include <QStringList> 0015 0016 class QTextStream; 0017 0018 namespace Marble 0019 { 0020 0021 class MARBLE_EXPORT WaypointParser 0022 { 0023 public: 0024 /** Fields which can be parsed */ 0025 enum Field { 0026 Longitude, 0027 Latitude, 0028 JunctionType, 0029 RoadName, 0030 TotalSecondsRemaining, 0031 RoadType 0032 }; 0033 0034 /** Constructor */ 0035 WaypointParser(); 0036 0037 /** Parses the given stream and returns the extracted waypoint list */ 0038 RoutingWaypoints parse( QTextStream &stream ) const; 0039 0040 /** Associate the zero-based field no index with the given semantic type */ 0041 void setFieldIndex( Field field, int index ); 0042 0043 /** The line separator used in the stream passed to #parse. Default is "\n" */ 0044 void setLineSeparator( const QString &separator ); 0045 0046 /** The field separator. Default is ',' */ 0047 void setFieldSeparator( const QChar &separator ); 0048 0049 /** Associate the given string key with the given junction type */ 0050 void addJunctionTypeMapping( const QString &key, RoutingWaypoint::JunctionType value ); 0051 0052 private: 0053 template<class T> 0054 T readField( Field field, const QStringList &fields, const T &defaultValue = T() ) const { 0055 int index = m_fieldIndices[field]; 0056 if ( index >= 0 && index < fields.size() ) { 0057 return QVariant( fields[index] ).value<T>(); 0058 } 0059 0060 return defaultValue; 0061 } 0062 0063 QString m_lineSeparator; 0064 0065 QChar m_fieldSeparator; 0066 0067 QMap<Field, int> m_fieldIndices; 0068 0069 QMap<QString, RoutingWaypoint::JunctionType> m_junctionTypeMapping; 0070 0071 Q_DISABLE_COPY( WaypointParser ) 0072 }; 0073 0074 } // namespace Marble 0075 0076 #endif // MARBLE_WAYPOINTPARSER_H