2019-09-08 16:42:10 +00:00
# include "gpx.h"
# include "cache.h"
# include "debug.h"
# include <iostream>
# include <fstream>
# include <string>
# include <gpx/GPX.h>
# include "gpx/Parser.h"
# include "gpx/Report.h"
class ReportDebug : public gpx : : Report {
public :
ReportDebug ( ) { }
~ ReportDebug ( ) { }
void report ( const gpx : : Node * node , gpx : : Report : : Warning warning , const std : : string & extra ) {
std : : string msg ;
if ( node ! = nullptr ) {
msg + = ( node - > getType ( ) = = gpx : : Node : : ATTRIBUTE ? " Attribute " : " Element " ) + node - > getName ( ) + " : " ;
}
msg + = gpx : : Report : : text ( warning ) ;
if ( ! extra . empty ( ) ) {
msg + = " : " + extra ;
}
Debug ( 3 ) < < msg + " . \n " ;
}
} ;
2020-02-11 16:34:23 +00:00
GPX : : GPX ( const std : : string & path ) {
2019-09-08 16:42:10 +00:00
std : : ifstream stream ( path ) ;
if ( stream . is_open ( ) ) {
ReportDebug report ;
gpx : : Parser parser ( & report ) ;
root = parser . parse ( stream ) ;
if ( root = = nullptr ) {
Debug ( 1 ) < < " Parsing of file " < < path < < " failed due to " < < parser . errorText ( ) < < " on line " < < parser . errorLineNumber ( ) < < " and column " < < parser . errorColumnNumber ( ) < < ' \n ' ;
} else {
items = root - > wpts ( ) . list ( ) ;
}
}
}
GPX : : ~ GPX ( ) {
delete root ;
}
2020-02-11 16:34:23 +00:00
Caches GPX : : get_user_caches ( __attribute__ ( ( unused ) ) const std : : string & uuid , __attribute__ ( ( unused ) ) int count ) const {
2019-09-08 16:42:10 +00:00
Caches list ;
for ( auto & el : items ) {
if ( el - > sym ( ) . getValue ( ) = = " Geocache Found " ) {
Cache c ;
c . code = el - > name ( ) . getValue ( ) ;
c . name = el - > desc ( ) . getValue ( ) ;
c . pos . lat = stof ( el - > lat ( ) . getValue ( ) ) ;
c . pos . lon = stof ( el - > lon ( ) . getValue ( ) ) ;
2019-09-11 17:48:03 +00:00
c . type = el - > type ( ) . getValue ( ) ;
2020-03-20 00:49:06 +00:00
c . status = unknown ;
2019-09-11 17:48:03 +00:00
if ( c . type . starts_with ( " Geocache| " ) )
2019-09-23 20:04:23 +00:00
c . type . erase ( 0 , 9 ) ;
2019-09-11 17:48:03 +00:00
if ( c . type . ends_with ( " Cache " ) )
2019-09-23 20:04:23 +00:00
c . type . erase ( c . type . end ( ) - 6 , c . type . end ( ) ) ;
2019-09-11 17:48:03 +00:00
if ( c . type . ends_with ( " -cache " ) )
2019-09-23 20:04:23 +00:00
c . type . erase ( c . type . end ( ) - 6 , c . type . end ( ) ) ;
2019-09-11 17:48:03 +00:00
if ( c . type = = ( " unknown " ) )
c . type = " Unknown " ;
2019-09-08 16:42:10 +00:00
if ( c . code . starts_with ( " GC " ) )
2019-09-11 17:48:03 +00:00
c . origin = " GC " ;
2019-09-08 16:42:10 +00:00
else if ( c . code . starts_with ( " OP " ) )
2019-09-11 17:48:03 +00:00
c . origin = " OC.pl " ;
2019-09-08 16:42:10 +00:00
else if ( c . code . starts_with ( " TR " ) | | c . code . starts_with ( " VI " ) | | c . code . starts_with ( " MV " ) )
2019-09-11 17:48:03 +00:00
c . origin = " GC.su " ;
2019-09-08 16:42:10 +00:00
2020-02-29 01:04:55 +00:00
list . push_back ( c ) ;
2019-09-08 16:42:10 +00:00
}
}
Debug ( 2 ) < < " Caches read from GPX file: " < < list . size ( ) < < ' \n ' ;
return list ;
}