├── Screenshot.png ├── OpenStreetPad ├── en.lproj │ └── InfoPlist.strings ├── parser.osp ├── TestData.pbf ├── fills │ ├── jam.png │ ├── forest.png │ ├── military.png │ └── graveyard.png ├── icons │ ├── atm.png │ └── parking.png ├── OSPMainViewController.h ├── Model │ ├── MapCSS │ │ ├── OSPMapCSSPlaceholderTest.h │ │ ├── OSPMapCSSColour.h │ │ ├── OSPMapCSSPlaceholderSpecifier.h │ │ ├── OSPMapCSSCommaSize.h │ │ ├── OSPMapCSSCommaSelector.h │ │ ├── OSPMapCSSCommaSpecifier.h │ │ ├── NSString+OpenStreetPad.h │ │ ├── OSPMapCSSKey.h │ │ ├── OSPMapCSSNamed.h │ │ ├── OSPMapCSSEval.h │ │ ├── OSPMapCSSTagSpec.h │ │ ├── OSPMapCSSCommaSize.m │ │ ├── OSPMapCSSDeclaration.h │ │ ├── OSPMapCSSEvalSpecifier.h │ │ ├── OSPMapCSSCommaSelector.m │ │ ├── OSPMapCSSTest.h │ │ ├── OSPMapCSSSpecifierList.h │ │ ├── OSPMapCSSUrl.h │ │ ├── OSPMapCSSCommaSpecifier.m │ │ ├── OSPMapCSSImport.h │ │ ├── OSPMapCSSZoom.h │ │ ├── OSPMapCSSClass.h │ │ ├── OSPMapCSSTag.h │ │ ├── OSPMapCSSURLSpecifier.h │ │ ├── OSPMapCSSColourSpecifier.h │ │ ├── OSPMapCSSNamedSpecifier.h │ │ ├── OSPMapCSSSizeSpecifier.h │ │ ├── OSPMapCSSUnaryTest.h │ │ ├── OSPMapCSSKey.m │ │ ├── OSPMapCSSNamed.m │ │ ├── OSPMapCSSEval.m │ │ ├── OSPMapCSSStyledObject.h │ │ ├── OSPMapCSSTagSpec.m │ │ ├── OSPMapCSSTagSpecifier.h │ │ ├── OSPMapCSSSelector.h │ │ ├── OSPMapCSSRule.h │ │ ├── OSPMapCSSSpecifier.h │ │ ├── NSString+OpenStreetPad.m │ │ ├── OSPMapCSSRuleset.h │ │ ├── OSPMapCSSTest.m │ │ ├── OSPMapCSSStyle.h │ │ ├── OSPMapCSSStyleSheet.h │ │ ├── OSPMapCSSEvalSpecifier.m │ │ ├── OSPMapCSSStyledObject.m │ │ ├── OSPMapCSSImport.m │ │ ├── OSPMapCSSSize.h │ │ ├── OSPMapCSSPlaceholderTest.m │ │ ├── OSPMapCSSObject.h │ │ ├── OSPMapCSSSubselector.h │ │ ├── OSPMapCSSDeclaration.m │ │ ├── OSPMapCSSClass.m │ │ ├── OSPMapCSSUrl.m │ │ ├── OSPMapCSSBinaryTest.h │ │ ├── OSPMapCSSSpecifierList.m │ │ ├── OSPMapCSSSizeSpecifier.m │ │ ├── OSPMapCSSURLSpecifier.m │ │ ├── OSPMapCSSStyle.m │ │ ├── OSPMapCSSNamedSpecifier.m │ │ ├── OSPMapCSSColour.m │ │ ├── OSPMapCSSColourSpecifier.m │ │ ├── OSPMapCSSSpecifier.m │ │ ├── OSPMapCSSTag.m │ │ ├── OSPMapCSSUnaryTest.m │ │ ├── OSPMapCSSZoom.m │ │ ├── OSPMapCSSTagSpecifier.m │ │ ├── OSPMapCSSPlaceholderSpecifier.m │ │ ├── OSPMapCSSSize.m │ │ ├── OSPMapCSSObject.m │ │ ├── OSPMapCSSStyleSheet.m │ │ ├── OSPMapCSSSelector.m │ │ └── OSPMapCSSBinaryTest.m │ ├── OSPMaths.h │ ├── OSPMaths.m │ ├── API │ │ ├── OSPRelation.h │ │ ├── OSPNode.h │ │ ├── OSPAPIObjectReference.h │ │ ├── OSPWay.h │ │ ├── OSPMember.h │ │ ├── OSPAPIObjectReference.m │ │ ├── OSPNode.m │ │ ├── OSPAPIObject.h │ │ ├── OSPRelation.m │ │ ├── OSPMember.m │ │ └── OSPAPIObject.m │ ├── OSPTileArray.h │ ├── OSPValue.h │ ├── OSPMapArea.h │ ├── OSPQuadTree.h │ ├── OSPNonRectangularArea.h │ ├── OSPMap.h │ ├── OSPMapArea.m │ ├── OSPNonRectangularArea.m │ ├── OSPValue.m │ ├── OSPCoordinateRect.h │ └── OSPMap.m ├── UIColor+CSS.h ├── DataSources │ ├── OSPOpenStreetMapPBFParser.h │ ├── NSString+XMLEscaping.h │ ├── OSPOpenStreetMapXMLParser.h │ ├── OSPDataStore.h │ ├── OSPMapServer.h │ ├── OSPOpenStreetMapXMLWriter.h │ ├── OSPOpenStreetMapPBFFile.h │ ├── OSPOpenStreetMapXMLFile.h │ ├── OSPOpenStreetMapParser.m │ ├── OSPOpenStreetMapParser.h │ ├── OSPXMLWriter.h │ ├── OSPDataSource.m │ ├── Protocol Buffers │ │ ├── TextFormat.h │ │ ├── MutableExtensionRegistry.h │ │ ├── AbstractMessage_Builder.h │ │ ├── AbstractMessage.h │ │ ├── Main.m │ │ ├── Bootstrap.h │ │ ├── GeneratedMessage_Builder.h │ │ ├── WireFormat.m │ │ ├── MutableField.h │ │ ├── Utilities.h │ │ ├── ForwardDeclarations.h │ │ ├── GeneratedMessage.h │ │ ├── GeneratedMessage.m │ │ ├── ProtocolBuffers.h │ │ ├── ExtensionField.h │ │ ├── UnknownFieldSet.h │ │ ├── Field.h │ │ ├── WireFormat.h │ │ ├── ExtensionRegistry.m │ │ ├── UnknownFieldSet_Builder.h │ │ ├── MutableExtensionRegistry.m │ │ ├── Utilities.m │ │ ├── ConcreteExtensionField.h │ │ ├── AbstractMessage.m │ │ ├── Message.h │ │ ├── ExtendableMessage.h │ │ ├── ExtendableMessage_Builder.h │ │ ├── GeneratedMessage_Builder.m │ │ ├── ExtensionRegistry.h │ │ ├── ExtendableMessage.m │ │ ├── MutableField.m │ │ └── AbstractMessage_Builder.m │ ├── OSPDataSource.h │ ├── OSPOpenStreetMapPBFFile.m │ ├── OSPOpenStreetMapXMLFile.m │ └── NSString+XMLEscaping.m ├── OSPMapCSSParser.h ├── OpenStreetPad-Prefix.pch ├── Cocoa Extensions │ ├── NSData+ZipCompression.h │ ├── PSYEnumerable.h │ └── NSData+ZipCompression.m ├── main.m ├── OSPMapCSSHashColourRecogniser.h ├── OSPAppDelegate.h ├── OSPMapCSSHashColourToken.h ├── OSPMapView.h ├── OSPMetaTileView.h ├── landuse.mcs ├── OSPMapCSSHashColourToken.m ├── OpenStreetPad-Info.plist ├── OSPMainViewController.m ├── OSPAppDelegate.m ├── osm.mcs └── OSPMapCSSHashColourRecogniser.m ├── OSPParserGenerator ├── OSPParserGenerator-Prefix.pch └── OSPParserGenerator.1 ├── README.md └── LICENSE /Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beelsebob/OpenStreetPad/HEAD/Screenshot.png -------------------------------------------------------------------------------- /OpenStreetPad/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /OpenStreetPad/parser.osp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beelsebob/OpenStreetPad/HEAD/OpenStreetPad/parser.osp -------------------------------------------------------------------------------- /OpenStreetPad/TestData.pbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beelsebob/OpenStreetPad/HEAD/OpenStreetPad/TestData.pbf -------------------------------------------------------------------------------- /OpenStreetPad/fills/jam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beelsebob/OpenStreetPad/HEAD/OpenStreetPad/fills/jam.png -------------------------------------------------------------------------------- /OpenStreetPad/icons/atm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beelsebob/OpenStreetPad/HEAD/OpenStreetPad/icons/atm.png -------------------------------------------------------------------------------- /OpenStreetPad/fills/forest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beelsebob/OpenStreetPad/HEAD/OpenStreetPad/fills/forest.png -------------------------------------------------------------------------------- /OpenStreetPad/fills/military.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beelsebob/OpenStreetPad/HEAD/OpenStreetPad/fills/military.png -------------------------------------------------------------------------------- /OpenStreetPad/icons/parking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beelsebob/OpenStreetPad/HEAD/OpenStreetPad/icons/parking.png -------------------------------------------------------------------------------- /OpenStreetPad/fills/graveyard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beelsebob/OpenStreetPad/HEAD/OpenStreetPad/fills/graveyard.png -------------------------------------------------------------------------------- /OSPParserGenerator/OSPParserGenerator-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'OSPParserGenerator' target in the 'OSPParserGenerator' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /OpenStreetPad/OSPMainViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OpenStreetPadViewController.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OSPMainViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSPlaceholderTest.h: -------------------------------------------------------------------------------- 1 | // 2 | // PlaceholderTest.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 01/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSTest.h" 10 | 11 | @interface OSPMapCSSPlaceholderTest : OSPMapCSSTest 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /OpenStreetPad/UIColor+CSS.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+CSS.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 30/12/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIColor (CSS) 12 | 13 | + (id)colourWithCSSName:(NSString *)colourName; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPMaths.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMaths.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 13/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #define degreesToRadians(x) (M_PI * x / 180.0) 10 | #define radiansToDegrees(x) (180.0 * x / M_PI) 11 | 12 | double normalisedRadians(double angle); 13 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSColour.h: -------------------------------------------------------------------------------- 1 | // 2 | // Colour.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSColour : NSObject 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSPlaceholderSpecifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // PlaceholderSpecifier.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 01/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSSpecifier.h" 10 | 11 | @interface OSPMapCSSPlaceholderSpecifier : OSPMapCSSSpecifier 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPOpenStreetMapPBFParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPOpenStreetMapPBFParser.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 21/04/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPOpenStreetMapParser.h" 10 | 11 | @interface OSPOpenStreetMapPBFParser : OSPOpenStreetMapParser 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/NSString+XMLEscaping.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+XMLEscaping.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 04/03/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (XMLEscaping) 12 | 13 | - (id)stringByAddingXMLEscaping; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSCommaSize.h: -------------------------------------------------------------------------------- 1 | // 2 | // CommaSize.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSCommaSize : NSObject 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSCommaSelector.h: -------------------------------------------------------------------------------- 1 | // 2 | // CommaSelector.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 02/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSCommaSelector : NSObject 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSCommaSpecifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSCommaSpecifier.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSCommaSpecifier : NSObject 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/NSString+OpenStreetPad.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+OpenStreetPad.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 05/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (OpenStreetPad) 12 | 13 | - (BOOL)ospTruthValue; 14 | - (BOOL)ospUntruthValue; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSKey.h: -------------------------------------------------------------------------------- 1 | // 2 | // Key.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSKey : NSObject 14 | 15 | @property (readwrite, copy) NSString *key; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPMaths.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMaths.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 13/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPMaths.h" 10 | 11 | double normalisedRadians(double angle) 12 | { 13 | const double a = fmod(angle, 2.0 * M_PI); 14 | return a < -M_PI ? 2.0 * M_PI + a : a > M_PI ? a - 2.0 * M_PI : a; 15 | } 16 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPOpenStreetMapXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPOpenStreetMapXMLParser.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 28/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPOpenStreetMapParser.h" 12 | 13 | @interface OSPOpenStreetMapXMLParser : OSPOpenStreetMapParser 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSNamed.h: -------------------------------------------------------------------------------- 1 | // 2 | // Named.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSNamed : NSObject 14 | 15 | @property (readwrite, copy) NSString *name; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OpenStreetPad/OSPMapCSSParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSParser.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 29/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPMapCSSStyleSheet.h" 12 | 13 | @interface OSPMapCSSParser : NSObject 14 | 15 | - (OSPMapCSSStyleSheet *)parse:(NSString *)mapCSS; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSEval.h: -------------------------------------------------------------------------------- 1 | // 2 | // Eval.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSEval : NSObject 14 | 15 | @property (readwrite, copy) NSString *expression; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OpenStreetPad/OpenStreetPad-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'OpenStreetPad' target in the 'OpenStreetPad' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_4_0 8 | #warning "This project uses features only available in iOS SDK 4.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /OpenStreetPad/Cocoa Extensions/NSData+ZipCompression.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+ZipCompression.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 21/04/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSData (ZipCompression) 12 | 13 | - (NSData *)dataByDecompressingZip; 14 | - (NSData *)dataByCompressingZip; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSTagSpec.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSTagSpec.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSTagSpec : NSObject 14 | 15 | @property (readwrite, copy) NSString *tag; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/API/OSPRelation.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPRelation.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPAPIObject.h" 10 | 11 | @class OSPMember; 12 | 13 | @interface OSPRelation : OSPAPIObject 14 | 15 | @property (readwrite,copy) NSArray *members; 16 | 17 | - (void)addMember:(OSPMember *)member; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSCommaSize.m: -------------------------------------------------------------------------------- 1 | // 2 | // CommaSize.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSCommaSize.h" 10 | 11 | @implementation OSPMapCSSCommaSize 12 | 13 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 14 | { 15 | return [syntaxTree children][1]; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSDeclaration.h: -------------------------------------------------------------------------------- 1 | // 2 | // Declaration.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSDeclaration : NSObject 14 | 15 | @property (readwrite, copy) NSArray *styles; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSEvalSpecifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // EvalSpecifier.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSSpecifier.h" 10 | 11 | #import "OSPMapCSSEval.h" 12 | 13 | @interface OSPMapCSSEvalSpecifier : OSPMapCSSSpecifier 14 | 15 | @property (readwrite, retain) OSPMapCSSEval *eval; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSCommaSelector.m: -------------------------------------------------------------------------------- 1 | // 2 | // CommaSelector.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 02/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSCommaSelector.h" 10 | 11 | @implementation OSPMapCSSCommaSelector 12 | 13 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 14 | { 15 | return [syntaxTree children][1]; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSTest.h: -------------------------------------------------------------------------------- 1 | // 2 | // Test.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPAPIObject.h" 12 | 13 | #import "CoreParse.h" 14 | 15 | @interface OSPMapCSSTest : NSObject 16 | 17 | - (BOOL)matchesObject:(OSPAPIObject *)object; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSSpecifierList.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSSpecifierList.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSSpecifierList : NSObject 14 | 15 | @property (readwrite, strong) NSArray *specifiers; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSUrl.h: -------------------------------------------------------------------------------- 1 | // 2 | // Url.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSUrl : NSObject 14 | 15 | @property (readwrite, strong) NSURL *content; 16 | 17 | - (id)initWithURL:(NSURL *)url; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool 16 | { 17 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([OSPAppDelegate class])); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSCommaSpecifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSCommaSpecifier.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSCommaSpecifier.h" 10 | 11 | @implementation OSPMapCSSCommaSpecifier 12 | 13 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 14 | { 15 | return [syntaxTree children][1]; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPDataStore.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPDataStore.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 28/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol OSPDataStore 12 | 13 | - (void)addObject:(OSPAPIObject *)apiObject; 14 | 15 | @end 16 | 17 | @protocol OSPPersistingStore 18 | 19 | - (void)save; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSImport.h: -------------------------------------------------------------------------------- 1 | // 2 | // Import.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 02/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSImport : NSObject 14 | 15 | @property (readwrite, copy) NSString *url; 16 | @property (readwrite, copy) NSString *mediaType; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSZoom.h: -------------------------------------------------------------------------------- 1 | // 2 | // Zoom.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 01/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSZoom : NSObject 14 | 15 | @property (readwrite, assign) float minimumZoom; 16 | @property (readwrite, assign) float maximumZoom; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSClass.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSClass.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSClass : NSObject 14 | 15 | @property (readwrite, assign) BOOL positive; 16 | @property (readwrite, copy ) NSString *className; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPTileArray.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPTileArray.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 21/01/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPCoordinateRect.h" 12 | 13 | @interface OSPTileArray : NSObject 14 | 15 | - (void)addTile:(OSPTile)t; 16 | - (BOOL)containsTile:(OSPTile)t; 17 | - (NSArray *)notIncludedSubtilesOfTile:(OSPTile)t; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSTag.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tag.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | @interface OSPMapCSSTag : NSObject 14 | 15 | @property (readwrite, assign, getter = isPseudoTag) BOOL pseudoTag; 16 | @property (readwrite, copy) NSString *tagName; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSURLSpecifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // URLSpecifier.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSSpecifier.h" 10 | 11 | #import "OSPMapCSSUrl.h" 12 | 13 | @interface OSPMapCSSURLSpecifier : OSPMapCSSSpecifier 14 | 15 | @property (readwrite, retain) OSPMapCSSUrl *url; 16 | 17 | - (id)initWithURL:(OSPMapCSSUrl *)url; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/OSPMapCSSHashColourRecogniser.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSHashColourRecogniser.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 20/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #if TARGET_OS_IPHONE 10 | #import "CoreParse.h" 11 | #else 12 | #import 13 | #endif 14 | 15 | @interface OSPMapCSSHashColourRecogniser : NSObject 16 | 17 | + (id)hashColourRecogniser; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSColourSpecifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // ColourSpecifier.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSSpecifier.h" 10 | 11 | @interface OSPMapCSSColourSpecifier : OSPMapCSSSpecifier 12 | 13 | #if TARGET_OS_IPHONE 14 | @property (readwrite, retain) UIColor *colour; 15 | 16 | - (id)initWithColour:(UIColor *)colour; 17 | #endif 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSNamedSpecifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // NamedSpecifier.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPMapCSSSpecifier.h" 12 | 13 | @interface OSPMapCSSNamedSpecifier : OSPMapCSSSpecifier 14 | 15 | @property (readwrite, copy) NSString *name; 16 | 17 | - (id)initWithName:(NSString *)name; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSSizeSpecifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // SizeListSpecifier.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSSpecifier.h" 10 | 11 | #import "OSPMapCSSSize.h" 12 | 13 | @interface OSPMapCSSSizeSpecifier : OSPMapCSSSpecifier 14 | 15 | @property (readwrite, copy) OSPMapCSSSize *size; 16 | 17 | - (id)initWithSize:(OSPMapCSSSize *)size; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPMapServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapServer.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 07/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPDataSource.h" 12 | 13 | @interface OSPMapServer : OSPDataSource 14 | 15 | + (id)serverWithURL:(NSURL *)serverURL; 16 | - (id)initWithURL:(NSURL *)serverURL; 17 | 18 | @property (readonly , copy) NSURL *serverURL; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPValue.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPValue.h 3 | // OpenStreetPad 4 | // 5 | // Created by Tom Davie on 04/09/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPCoordinateRect.h" 12 | 13 | @interface OSPValue : NSObject 14 | 15 | + (id)valueWithRect:(OSPCoordinateRect)rect; 16 | + (id)valueWithTile:(OSPTile)tile; 17 | 18 | - (OSPCoordinateRect)rectValue; 19 | - (OSPTile)tileValue; 20 | 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/API/OSPNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPNode.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPAPIObject.h" 10 | 11 | #import 12 | 13 | @interface OSPNode : OSPAPIObject 14 | 15 | @property (/*nonatomic,*/ readwrite, assign) CLLocationCoordinate2D location; 16 | @property (/*nonatomic,*/ readonly , assign) OSPCoordinate2D projectedLocation; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /OpenStreetPad/OSPAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // OpenStreetPadAppDelegate.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class OSPMainViewController; 12 | 13 | @interface OSPAppDelegate : UIResponder 14 | 15 | @property (strong, nonatomic) UIWindow *window; 16 | 17 | @property (strong, nonatomic) OSPMainViewController *viewController; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPMapArea.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapArea.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 13/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | 10 | #import "OSPCoordinateRect.h" 11 | 12 | typedef struct 13 | { 14 | OSPCoordinate2D centre; 15 | float zoomLevel; 16 | } OSPMapArea; 17 | 18 | OSPMapArea OSPMapAreaMake(OSPCoordinate2D centre, float zoomLevel); 19 | 20 | OSPCoordinateRect OSPRectForMapAreaInRect(OSPMapArea area, CGRect bounds); 21 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPOpenStreetMapXMLWriter.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPOpenStreetMapXMLWriter.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 03/03/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPDataSource.h" 12 | 13 | @interface OSPOpenStreetMapXMLWriter : NSObject 14 | 15 | - (id)initWithStream:(NSOutputStream *)stream; 16 | 17 | - (void)writeDataProvider:(id)dataProvider; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPQuadTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPQuadTree.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 20/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPCoordinateRect.h" 12 | 13 | @interface OSPQuadTree : NSObject 14 | 15 | - (id)initWithBounds:(OSPCoordinateRect)initBounds; 16 | 17 | - (void)addObject:(id)o; 18 | 19 | - (NSSet *)objectsInBounds:(OSPCoordinateRect)bounds; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/API/OSPAPIObjectReference.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPAPIObjectReference.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 29/08/2011. 6 | // Copyright (c) 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPAPIObject.h" 10 | 11 | #import "OSPMember.h" 12 | 13 | @interface OSPAPIObjectReference : OSPAPIObject 14 | 15 | + (id)apiObjectReferenceWithType:(OSPMemberType)type identity:(NSInteger)identity; 16 | - (id)initWithType:(OSPMemberType)type identity:(NSInteger)identity; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPOpenStreetMapPBFFile.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPOpenStreetMapPBFFile.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 21/04/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPDataSource.h" 12 | 13 | @interface OSPOpenStreetMapPBFFile : OSPDataSource 14 | 15 | + (id)osmFileWithPath:(NSString *)path; 16 | - (id)initWithPath:(NSString *)path; 17 | 18 | @property (readwrite, strong) NSString *path; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSUnaryTest.h: -------------------------------------------------------------------------------- 1 | // 2 | // UnaryTest.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSTest.h" 10 | 11 | #import "OSPMapCSSTag.h" 12 | 13 | @interface OSPMapCSSUnaryTest : OSPMapCSSTest 14 | 15 | @property (readwrite, assign, getter=isNegated) BOOL negated; 16 | @property (readwrite, strong) NSString *tagName; 17 | 18 | - (id)initWithTagName:(NSString *)tagName negated:(BOOL)negated; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSKey.m: -------------------------------------------------------------------------------- 1 | // 2 | // Key.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSKey.h" 10 | 11 | @implementation OSPMapCSSKey 12 | 13 | @synthesize key; 14 | 15 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 16 | { 17 | self = [super init]; 18 | 19 | if (nil != self) 20 | { 21 | [self setKey:[[syntaxTree children][0] identifier]]; 22 | } 23 | 24 | return self; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSNamed.m: -------------------------------------------------------------------------------- 1 | // 2 | // Named.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSNamed.h" 10 | 11 | @implementation OSPMapCSSNamed 12 | 13 | @synthesize name; 14 | 15 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 16 | { 17 | self = [super init]; 18 | 19 | if (nil != self) 20 | { 21 | [self setName:[[syntaxTree children][0] identifier]]; 22 | } 23 | 24 | return self; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSEval.m: -------------------------------------------------------------------------------- 1 | // 2 | // Eval.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSEval.h" 10 | 11 | @implementation OSPMapCSSEval 12 | 13 | @synthesize expression; 14 | 15 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 16 | { 17 | self = [super init]; 18 | 19 | if (nil != self) 20 | { 21 | [self setExpression:[[syntaxTree children][2] content]]; 22 | } 23 | 24 | return self; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSStyledObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSStyledObject.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 20/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPAPIObject.h" 10 | 11 | @interface OSPMapCSSStyledObject : NSObject 12 | 13 | @property (readwrite,weak) OSPAPIObject *object; 14 | @property (readwrite,copy) NSDictionary *style; 15 | 16 | + (id)object:(OSPAPIObject *)o withStyle:(NSDictionary *)style; 17 | - (id)initWithObject:(OSPAPIObject *)o style:(NSDictionary *)style; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSTagSpec.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSTagSpec.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSTagSpec.h" 10 | 11 | @implementation OSPMapCSSTagSpec 12 | 13 | @synthesize tag; 14 | 15 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 16 | { 17 | self = [super init]; 18 | 19 | if (nil != self) 20 | { 21 | [self setTag:[[syntaxTree children][2] content]]; 22 | } 23 | 24 | return self; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSTagSpecifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSTagSpecifier.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | #import "OSPMapCSSSpecifier.h" 14 | #import "OSPMapCSSTagSpec.h" 15 | 16 | @interface OSPMapCSSTagSpecifier : OSPMapCSSSpecifier 17 | 18 | @property (readwrite, retain) OSPMapCSSTagSpec *tag; 19 | 20 | - (OSPMapCSSSpecifier *)specifierWithAPIObject:(OSPAPIObject *)object; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPOpenStreetMapXMLFile.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPOpenStreetMapXMLFile.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 28/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPDataSource.h" 12 | 13 | #import "OSPDataStore.h" 14 | 15 | @interface OSPOpenStreetMapXMLFile : OSPDataSource 16 | 17 | + (id)osmFileWithPath:(NSString *)path; 18 | - (id)initWithPath:(NSString *)path; 19 | 20 | @property (readwrite, strong) NSString *path; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSSelector.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSSelector.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 01/04/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | #import "OSPAPIObject.h" 14 | 15 | @interface OSPMapCSSSelector : NSObject 16 | 17 | @property (readwrite, strong) NSArray *subselectors; 18 | @property (readwrite, strong) NSString *layerIdentifier; 19 | 20 | - (BOOL)matchesObject:(OSPAPIObject *)object atZoom:(float)zoom; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPOpenStreetMapParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPOpenStreetMapParser.m 3 | // 4 | // 5 | // Created by Thomas Davie on 04/03/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPOpenStreetMapParser.h" 10 | 11 | @implementation OSPOpenStreetMapParser 12 | 13 | @synthesize delegate; 14 | 15 | - (id)initWithStream:(NSInputStream *)stream 16 | { 17 | return [super init]; 18 | } 19 | 20 | - (void)parse 21 | { 22 | [NSException raise:@"Abstract Class Exception" format:@"OSPOSMParser is an abstract class, use a concrete subclass"]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSRule.h: -------------------------------------------------------------------------------- 1 | // 2 | // Rule.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 02/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPAPIObject.h" 12 | 13 | #import "CoreParse.h" 14 | 15 | @interface OSPMapCSSRule : NSObject 16 | 17 | @property (readwrite, copy) NSArray *selectors; 18 | @property (readwrite, copy) NSArray *declarations; 19 | 20 | - (NSDictionary *)applyToObject:(OSPAPIObject *)object atZoom:(float)zoom stop:(BOOL *)stop; 21 | 22 | - (BOOL)isOnlyMeta; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSSpecifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // Specifier.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | #import "OSPAPIObject.h" 14 | #import "OSPMapCSSSize.h" 15 | #import "OSPMapCSSUrl.h" 16 | 17 | @interface OSPMapCSSSpecifier : NSObject 18 | 19 | - (NSString *)stringValue; 20 | - (OSPMapCSSSize *)sizeValue; 21 | #if TARGET_OS_IPHONE 22 | - (UIColor *)colourValue; 23 | #endif 24 | - (OSPMapCSSUrl *)urlValue; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/NSString+OpenStreetPad.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+OpenStreetPad.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 05/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "NSString+OpenStreetPad.h" 10 | 11 | @implementation NSString (OpenStreetPad) 12 | 13 | - (BOOL)ospTruthValue 14 | { 15 | NSString *l = [self lowercaseString]; 16 | return [l isEqual:@"yes"] || [l isEqual:@"true"] || [l isEqual:@"1"]; 17 | } 18 | 19 | - (BOOL)ospUntruthValue 20 | { 21 | NSString *l = [self lowercaseString]; 22 | return [l isEqual:@"no"] || [l isEqual:@"false"]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPNonRectangularArea.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPNonRectangularArea.h 3 | // OpenStreetPad 4 | // 5 | // Created by Tom Davie on 04/09/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPCoordinateRect.h" 12 | 13 | @interface OSPNonRectangularArea : NSObject 14 | 15 | + (id)emptyArea; 16 | + (id)areaWithRects:(NSArray *)rects; 17 | 18 | - (id)initWithRects:(NSArray *)rects; 19 | 20 | - (OSPNonRectangularArea *)areaBySubtractingArea:(OSPNonRectangularArea *)other; 21 | 22 | - (void)addRect:(OSPCoordinateRect)rect; 23 | 24 | - (NSArray *)allRects; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSRuleset.h: -------------------------------------------------------------------------------- 1 | // 2 | // Ruleset.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 02/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPAPIObject.h" 12 | 13 | #import "CoreParse.h" 14 | 15 | @interface OSPMapCSSRuleset : NSObject 16 | 17 | @property (readwrite, copy) NSArray *rules; 18 | 19 | - (void)deleteMetaAndLoadImportsRelativeToURL:(NSURL *)baseURL; 20 | 21 | - (NSDictionary *)applyToObject:(OSPAPIObject *)object atZoom:(float)zoom; 22 | - (NSDictionary *)styleForCanvasAtZoom:(float)zoom; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /OpenStreetPad/OSPMapCSSHashColourToken.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSHashColourToken.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 20/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #if TARGET_OS_IPHONE 10 | #import 11 | 12 | #import "CoreParse.h" 13 | #else 14 | #import 15 | #endif 16 | 17 | @interface OSPMapCSSHashColourToken : CPToken 18 | 19 | #if TARGET_OS_IPHONE 20 | @property (readwrite,retain) UIColor *colour; 21 | #endif 22 | 23 | + (id)tokenWithRed:(uint8_t)r green:(uint8_t)g blue:(uint8_t)b; 24 | - (id)initWithRed:(uint8_t)r green:(uint8_t)g blue:(uint8_t)b; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /OpenStreetPad/OSPMapView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapView.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | #import "OSPMapArea.h" 13 | #import "OSPMetaTileView.h" 14 | 15 | #import "OSPMapCSSStyleSheet.h" 16 | 17 | @interface OSPMapView : UIView 18 | 19 | @property (readwrite, nonatomic, assign) OSPMapArea mapArea; 20 | @property (readwrite, nonatomic, strong) OSPMapCSSStyleSheet *stylesheet; 21 | 22 | - (id)initWithFrame:(CGRect)frame serverURL:(NSURL *)serverURL mapBounds:(OSPMapArea)mapArea; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /OpenStreetPad/OSPMetaTileView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMetaTileView.h 3 | // OpenStreetPad 4 | // 5 | // Created by Tom Davie on 04/09/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPMapServer.h" 12 | 13 | #import "OSPMapArea.h" 14 | 15 | #import "OSPMapCSSStyleSheet.h" 16 | 17 | @interface OSPMetaTileView : UIView 18 | 19 | @property (readwrite, nonatomic, strong) OSPDataSource *dataSource; 20 | @property (readwrite, nonatomic, assign) OSPMapArea mapArea; 21 | 22 | @property (readwrite, strong) OSPMapCSSStyleSheet *stylesheet; 23 | 24 | - (void)setNeedsDisplayInMapArea:(OSPCoordinateRect)area; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // Test.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSTest.h" 10 | 11 | #import "OSPMapCSSPlaceholderTest.h" 12 | 13 | @implementation OSPMapCSSTest 14 | 15 | + (id)allocWithZone:(NSZone *)zone 16 | { 17 | return self == [OSPMapCSSTest class] ? [OSPMapCSSPlaceholderTest allocWithZone:zone] : [super allocWithZone:zone]; 18 | } 19 | 20 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 21 | { 22 | return [super init]; 23 | } 24 | 25 | - (BOOL)matchesObject:(OSPAPIObject *)object 26 | { 27 | return NO; 28 | } 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSStyle.h: -------------------------------------------------------------------------------- 1 | // 2 | // Style.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | #import "OSPMapCSSSpecifierList.h" 13 | 14 | @class OSPMapCSSRule; 15 | 16 | @interface OSPMapCSSStyle : NSObject 17 | 18 | @property (readwrite, assign) BOOL containsRule; 19 | @property (readwrite, retain) OSPMapCSSRule *rule; 20 | @property (readwrite, assign, getter = isExit) BOOL exit; 21 | @property (readwrite, copy) NSString *key; 22 | @property (readwrite, retain) OSPMapCSSSpecifierList *specifiers; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/API/OSPWay.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPWay.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPAPIObject.h" 10 | 11 | @interface OSPWay : OSPAPIObject 12 | 13 | @property (readwrite,strong,nonatomic) NSArray *nodes; 14 | @property (readonly) NSArray *nodeObjects; 15 | 16 | - (id)wayByCopyingTagsAndNodes; 17 | 18 | - (void)addNodeWithId:(NSInteger)nodeId; 19 | 20 | - (OSPCoordinate2D)projectedCentroid; 21 | 22 | - (double)length; 23 | - (double)textOffsetForTextWidth:(double)width; 24 | - (OSPCoordinate2D)positionOnWayWithOffset:(double)xOffset heightAboveWay:(double)yOffset backwards:(BOOL)backwards; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSStyleSheet.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSStyleSheet.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 05/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPMapCSSRuleset.h" 12 | 13 | #import "OSPAPIObject.h" 14 | 15 | @interface OSPMapCSSStyleSheet : NSObject 16 | 17 | @property (readwrite, strong) OSPMapCSSRuleset *ruleset; 18 | 19 | - (id)initWithRules:(OSPMapCSSRuleset *)ruleset; 20 | 21 | - (void)deleteMetaAndLoadImportsRelativeToURL:(NSURL *)baseURL; 22 | 23 | - (NSArray *)styledObjects:(NSSet *)objects atZoom:(float)zoom; 24 | - (NSDictionary *)styleForCanvasAtZoom:(float)zoom; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSEvalSpecifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // EvalSpecifier.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSEvalSpecifier.h" 10 | 11 | @implementation OSPMapCSSEvalSpecifier 12 | 13 | @synthesize eval; 14 | 15 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 16 | { 17 | self = [super initWithSyntaxTree:syntaxTree]; 18 | 19 | if (nil != self) 20 | { 21 | [self setEval:[syntaxTree children][0]]; 22 | } 23 | 24 | return self; 25 | } 26 | 27 | - (NSString *)description 28 | { 29 | return [NSString stringWithFormat:@"eval(\"%@\")", [[self eval] expression]]; 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPMap.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMap.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPDataSource.h" 12 | #import "OSPDataStore.h" 13 | 14 | #import "OSPAPIObject.h" 15 | 16 | #import "OSPNode.h" 17 | #import "OSPWay.h" 18 | #import "OSPRelation.h" 19 | #import "OSPMember.h" 20 | 21 | @interface OSPMap : NSObject 22 | 23 | - (OSPNode *)nodeWithId:(NSInteger)nodeId; 24 | - (OSPWay *)wayWithId:(NSInteger)wayId; 25 | - (OSPRelation *)relationWithId:(NSInteger)relationId; 26 | - (OSPAPIObject *)apiObjectOfType:(OSPMemberType)type withId:(NSInteger)objectId; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSStyledObject.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSStyledObject.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 20/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSStyledObject.h" 10 | 11 | @implementation OSPMapCSSStyledObject 12 | 13 | @synthesize object; 14 | @synthesize style; 15 | 16 | + (id)object:(OSPAPIObject *)o withStyle:(NSDictionary *)style 17 | { 18 | return [[self alloc] initWithObject:o style:style]; 19 | } 20 | 21 | - (id)initWithObject:(OSPAPIObject *)o style:(NSDictionary *)s 22 | { 23 | self = [super init]; 24 | 25 | if (nil != self) 26 | { 27 | [self setObject:o]; 28 | [self setStyle:s]; 29 | } 30 | 31 | return self; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSImport.m: -------------------------------------------------------------------------------- 1 | // 2 | // Import.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 02/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSImport.h" 10 | 11 | @implementation OSPMapCSSImport 12 | 13 | @synthesize url; 14 | @synthesize mediaType; 15 | 16 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 17 | { 18 | self = [super init]; 19 | 20 | if (nil != self) 21 | { 22 | [self setUrl:[[syntaxTree children][3] content]]; 23 | [self setMediaType:[[syntaxTree children][5] identifier]]; 24 | } 25 | 26 | return self; 27 | } 28 | 29 | - (NSString *)description 30 | { 31 | return [NSString stringWithFormat:@"@import url(\"%@\") %@\n", [self url], [self mediaType]]; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSSize.h: -------------------------------------------------------------------------------- 1 | // 2 | // Size.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | typedef enum 14 | { 15 | OSPMapCSSUnitPt , 16 | OSPMapCSSUnitPx , 17 | OSPMapCSSUnitPercent, 18 | OSPMapCSSUnitNone 19 | } OSPMapCSSUnit; 20 | 21 | OSPMapCSSUnit OSPMapCSSUnitFromNSString(NSString *s); 22 | NSString *NSStringFromOSPMapCSSUnit(OSPMapCSSUnit u); 23 | 24 | @interface OSPMapCSSSize : NSObject 25 | 26 | @property (readwrite, assign) float value; 27 | @property (readwrite, assign) OSPMapCSSUnit unit; 28 | 29 | - (id)initWithValue:(NSNumber *)value units:(OSPMapCSSUnit)unit; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OpenStreetPad 2 | ============= 3 | 4 | OpenStreetPad is an OpenStreetMap renderer based on MapCSS styles. In it's current state it is integrated into an application that shows a single OSPMapView. There are currently several bugs and shortcomings in OpenStreetPad, but they should be fixed pretty rapidly. 5 | 6 | ScreenShot 7 | ========== 8 | ![Screenshot](https://github.com/beelsebob/OpenStreetPad/raw/master/Screenshot.png) 9 | 10 | CoreParse 11 | ========= 12 | To use OpenStreetPad, you must clone [CoreParse](http://www.github.com/beelsebob/CoreParse) into the same directory you clone OpenStreetPad into: 13 | 14 | > git clone git://github.com/beelsebob/CoreParse.git 15 | > 16 | > git clone git://github.com/beelsebob/OpenStreetPad.git 17 | 18 | Once you've done this, open the OpenStreetPad and build the OpenStreetPad target. You should not need to build any other target. 19 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPOpenStreetMapParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPOpenStreetMapParser.h 3 | // 4 | // 5 | // Created by Thomas Davie on 04/03/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPAPIObject.h" 12 | 13 | @class OSPOpenStreetMapParser; 14 | 15 | @protocol OSPOpenStreetMapParserDelegate 16 | 17 | - (void)parser:(OSPOpenStreetMapParser *)parser didFindAPIObject:(OSPAPIObject *)object; 18 | - (void)parser:(OSPOpenStreetMapParser *)parser didFailWithError:(NSError *)error; 19 | - (void)parserDidEndDocument:(OSPOpenStreetMapParser *)parser; 20 | 21 | @end 22 | 23 | @interface OSPOpenStreetMapParser : NSObject 24 | 25 | @property (readwrite, weak) id delegate; 26 | 27 | - (id)initWithStream:(NSInputStream *)stream; 28 | 29 | - (void)parse; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSPlaceholderTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // PlaceholderTest.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 01/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSPlaceholderTest.h" 10 | 11 | #import "OSPMapCSSUnaryTest.h" 12 | #import "OSPMapCSSBinaryTest.h" 13 | 14 | @implementation OSPMapCSSPlaceholderTest 15 | 16 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 17 | { 18 | CPSyntaxTree *condition = [syntaxTree children][1]; 19 | switch ([[condition children] count]) 20 | { 21 | case 1: 22 | case 2: 23 | return (id)[[OSPMapCSSUnaryTest alloc] initWithSyntaxTree:condition]; 24 | case 3: 25 | return (id)[[OSPMapCSSBinaryTest alloc] initWithSyntaxTree:condition]; 26 | default: 27 | return nil; 28 | } 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSObject.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | typedef enum 14 | { 15 | OSPMapCSSObjectTypeNode, 16 | OSPMapCSSObjectTypeWay, 17 | OSPMapCSSObjectTypeRelation, 18 | OSPMapCSSObjectTypeArea, 19 | OSPMapCSSObjectTypeLine, 20 | OSPMapCSSObjectTypeCanvas, 21 | OSPMapCSSObjectTypeMeta, 22 | OSPMapCSSObjectTypeAll 23 | } OSPMapCSSObjectType; 24 | 25 | NSString *NSStringFromOSPMapCSSObjectType(OSPMapCSSObjectType t); 26 | OSPMapCSSObjectType OSPMapCSSObjectTypeFromNSString(NSString *s); 27 | 28 | @interface OSPMapCSSObject : NSObject 29 | 30 | @property (readwrite, assign) OSPMapCSSObjectType objectType; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSSubselector.h: -------------------------------------------------------------------------------- 1 | // 2 | // Subselector.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 02/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "CoreParse.h" 12 | 13 | #import "OSPMapCSSClass.h" 14 | #import "OSPMapCSSObject.h" 15 | 16 | #import "OSPAPIObject.h" 17 | 18 | @interface OSPMapCSSSubselector : NSObject 19 | 20 | @property (readwrite, assign) OSPMapCSSObjectType objectType; 21 | @property (readwrite, assign, getter=isConstrainedToZoomRange) BOOL constrainedToZoomRange; 22 | @property (readwrite, assign) float minimumZoom; 23 | @property (readwrite, assign) float maximumZoom; 24 | @property (readwrite, copy) NSArray *tests; 25 | 26 | - (BOOL)matchesObject:(OSPAPIObject *)object atZoom:(float)zoom; 27 | - (BOOL)zoomIsInRange:(float)zoom; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPXMLWriter.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPXMLWriter.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 03/03/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OSPXMLWriter : NSObject 12 | 13 | + (id)xmlWriterWithOutputStream:(NSOutputStream *)outputStream encoding:(NSStringEncoding)encoding; 14 | - (id)initWithOutputStream:(NSOutputStream *)outputStream encoding:(NSStringEncoding)encoding; 15 | 16 | @property (strong) NSOutputStream *outputStream; 17 | 18 | - (void)writeElement:(NSString *)element; 19 | - (void)writeElement:(NSString *)element withAttributes:(NSDictionary *)attributes; 20 | 21 | - (void)writeStartElement:(NSString *)element; 22 | - (void)writeStartElement:(NSString *)element withAttributes:(NSDictionary *)attributes; 23 | - (void)writeEndElement; 24 | 25 | - (void)writeText:(NSString *)text; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/API/OSPMember.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMember.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPAPIObject.h" 10 | 11 | #import "OSPMap.h" 12 | 13 | @class OSPRelation; 14 | 15 | @interface OSPMember : NSObject 16 | 17 | + (id)memberWithType:(OSPMemberType)memberType referencedObjectId:(NSInteger)referenceId role:(NSString *)role; 18 | - (id)initWithType:(OSPMemberType)memberType referencedObjectId:(NSInteger)referenceId role:(NSString *)role; 19 | 20 | @property (readwrite, assign) OSPMemberType referencedObjectType; 21 | @property (readwrite, assign) NSInteger referencedObjectId; 22 | @property (readwrite, copy ) NSString *role; 23 | @property (readwrite, weak ) OSPRelation *relation; 24 | 25 | @property (readonly) OSPAPIObject *referencedObject; 26 | 27 | @property (readonly) OSPCoordinateRect bounds; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSDeclaration.m: -------------------------------------------------------------------------------- 1 | // 2 | // Declaration.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSDeclaration.h" 10 | 11 | #import "OSPMapCSSStyle.h" 12 | 13 | @implementation OSPMapCSSDeclaration 14 | 15 | @synthesize styles; 16 | 17 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 18 | { 19 | self = [super init]; 20 | 21 | if (nil != self) 22 | { 23 | [self setStyles:[syntaxTree children][1]]; 24 | } 25 | 26 | return self; 27 | } 28 | 29 | - (NSString *)description 30 | { 31 | NSMutableString *desc = [NSMutableString stringWithString:@"{\n"]; 32 | 33 | for (OSPMapCSSStyle *style in [self styles]) 34 | { 35 | [desc appendFormat:@" %@\n", style]; 36 | } 37 | [desc appendString:@"}"]; 38 | return desc; 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /OpenStreetPad/landuse.mcs: -------------------------------------------------------------------------------- 1 | way[landuse] 2 | { 3 | z-index: -5; 4 | 5 | area[landuse="military"] 6 | { 7 | fill-image: url("fills/military.png"); 8 | width: 3pt; 9 | color: rgb(1.0, 0.46, 0.47); 10 | } 11 | 12 | area[landuse="residential"] 13 | { 14 | fill-color: rgba(0.9, 0.9, 0.9, 0.5); 15 | } 16 | 17 | area[landuse="retail"] 18 | { 19 | fill-color: rgb(0.94, 0.85, 0.85); 20 | color: rgb(0.95, 0.7, 0.7); 21 | width: 1pt; 22 | } 23 | 24 | area[landuse="forest"] 25 | { 26 | fill-image: url("fills/forest.png"); 27 | } 28 | 29 | area[landuse="cemetery"] 30 | { 31 | fill-image: url("fills/graveyard.png"); 32 | } 33 | 34 | area[landuse="railway"], 35 | area[landuse="industrial"] 36 | { 37 | fill-color: rgb(0.87, 0.82, 0.84); 38 | z-index: -4; 39 | } 40 | 41 | area[landuse="landfill"] 42 | { 43 | fill-color: rgb(0.72, 0.71, 0.58); 44 | } 45 | 46 | exit; 47 | } 48 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPMapArea.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapArea.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 13/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPMapArea.h" 10 | 11 | #define OSPTileSize 256.0 12 | 13 | inline OSPMapArea OSPMapAreaMake(OSPCoordinate2D centre, float zoomLevel) 14 | { 15 | return (OSPMapArea){.centre = centre, .zoomLevel = zoomLevel}; 16 | } 17 | 18 | inline OSPCoordinateRect OSPRectForMapAreaInRect(OSPMapArea area, CGRect bounds) 19 | { 20 | double coveragePerPixel = 1.0 / (pow(2.0, area.zoomLevel) * OSPTileSize); 21 | double width = CGRectGetWidth(bounds); 22 | double height = CGRectGetHeight(bounds); 23 | double projectedWidth = coveragePerPixel * width; 24 | double projectedHeight = coveragePerPixel * height; 25 | return OSPCoordinateRectMake(area.centre.x - projectedWidth * 0.5, area.centre.y - projectedHeight * 0.5, projectedWidth, projectedHeight); 26 | } 27 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPDataSource.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPDataSource.m 3 | // 4 | // 5 | // Created by Thomas Davie on 25/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPDataSource.h" 10 | 11 | @implementation OSPDataSource 12 | 13 | @synthesize delegate; 14 | 15 | - (void)loadObjectsInBounds:(OSPCoordinateRect)bounds withOutset:(double)outsetSize 16 | { 17 | [[NSException exceptionWithName:@"Abstract Superclass Exception" reason:@"OSPDataSource is an abstract superclass, use a concrete subclass" userInfo:nil] raise]; 18 | } 19 | 20 | - (NSSet *)objectsInBounds:(OSPCoordinateRect)bounds 21 | { 22 | [[NSException exceptionWithName:@"Abstract Superclass Exception" reason:@"OSPDataSource is an abstract superclass, use a concrete subclass" userInfo:nil] raise]; 23 | return nil; 24 | } 25 | 26 | - (NSSet *)allObjects 27 | { 28 | return [self objectsInBounds:OSPCoordinateRectMake(-180.0, -90.0, 360.0, 180.0)]; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /OpenStreetPad/OSPMapCSSHashColourToken.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSHashColourToken.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 20/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSHashColourToken.h" 10 | 11 | @implementation OSPMapCSSHashColourToken 12 | 13 | #if TARGET_OS_IPHONE 14 | @synthesize colour; 15 | #endif 16 | 17 | + (id)tokenWithRed:(uint8_t)r green:(uint8_t)g blue:(uint8_t)b 18 | { 19 | return [[self alloc] initWithRed:r green:g blue:b]; 20 | } 21 | 22 | - (id)initWithRed:(uint8_t)r green:(uint8_t)g blue:(uint8_t)b 23 | { 24 | self = [super init]; 25 | 26 | if (nil != self) 27 | { 28 | #if TARGET_OS_IPHONE 29 | [self setColour:[UIColor colorWithRed:(CGFloat)r / 255.0f green:(CGFloat)g / 255.0f blue:(CGFloat)b / 255.0f alpha:1.0f]]; 30 | #endif 31 | } 32 | 33 | return self; 34 | } 35 | 36 | - (NSString *)name 37 | { 38 | return @"HashColour"; 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/TextFormat.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | @interface PBTextFormat : NSObject { 16 | 17 | } 18 | 19 | + (int32_t) parseInt32:(NSString*) text; 20 | + (int32_t) parseUInt32:(NSString*) text; 21 | + (int64_t) parseInt64:(NSString*) text; 22 | + (int64_t) parseUInt64:(NSString*) text; 23 | 24 | + (NSData*) unescapeBytes:(NSString*) input; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSClass.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSClass.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSClass.h" 10 | 11 | @implementation OSPMapCSSClass 12 | 13 | @synthesize positive; 14 | @synthesize className; 15 | 16 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 17 | { 18 | self = [super init]; 19 | 20 | if (nil != self) 21 | { 22 | NSArray *c = [syntaxTree children]; 23 | id firstChild = c[0]; 24 | if ([firstChild isKindOfClass:[CPSyntaxTree class]]) 25 | { 26 | [self setPositive:YES]; 27 | [self setClassName:[[firstChild children][1] identifier]]; 28 | } 29 | else 30 | { 31 | [self setPositive:NO]; 32 | [self setClassName:[[c[1] children][1] identifier]]; 33 | } 34 | } 35 | 36 | return self; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/MutableExtensionRegistry.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ExtensionRegistry.h" 16 | 17 | @interface PBMutableExtensionRegistry : PBExtensionRegistry { 18 | @private 19 | NSMutableDictionary* mutableClassMap; 20 | } 21 | 22 | + (PBMutableExtensionRegistry*) registry; 23 | 24 | - (void) addExtension:(id) extension; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPDataSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPDataSource.h 3 | // 4 | // 5 | // Created by Thomas Davie on 25/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPCoordinateRect.h" 12 | 13 | #import "OSPAPIObject.h" 14 | 15 | @class OSPDataSource; 16 | 17 | @protocol OSPDataProvider 18 | 19 | - (NSSet *)objectsInBounds:(OSPCoordinateRect)bounds; 20 | - (NSSet *)allObjects; 21 | 22 | @end 23 | 24 | @protocol OSPDataSourceDelegate 25 | 26 | - (void)dataSource:(OSPDataSource *)mapServer didLoadObjectsInArea:(OSPCoordinateRect)area; 27 | - (BOOL)dataSource:(OSPDataSource *)mapServer shouldLoadObjectsInArea:(OSPCoordinateRect)area; 28 | 29 | @end 30 | 31 | @interface OSPDataSource : NSObject 32 | 33 | @property (readwrite, weak) id delegate; 34 | 35 | - (void)loadObjectsInBounds:(OSPCoordinateRect)bounds withOutset:(double)outsetSize; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSUrl.m: -------------------------------------------------------------------------------- 1 | // 2 | // Url.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSUrl.h" 10 | 11 | #import "OSPMapCSSEval.h" 12 | 13 | @implementation OSPMapCSSUrl 14 | 15 | @synthesize content; 16 | 17 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 18 | { 19 | self = [super init]; 20 | 21 | if (nil != self) 22 | { 23 | NSArray *c = [syntaxTree children]; 24 | [self setContent:[NSURL URLWithString:[c[[c count] == 1 ? 0 : 2] content]]]; 25 | } 26 | 27 | return self; 28 | } 29 | 30 | - (id)initWithURL:(NSURL *)url 31 | { 32 | self = [super init]; 33 | 34 | if (nil != self) 35 | { 36 | [self setContent:url]; 37 | } 38 | 39 | return self; 40 | } 41 | 42 | - (NSString *)description 43 | { 44 | return [NSString stringWithFormat:@"url(\"%@\")", [self content]]; 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/API/OSPAPIObjectReference.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPAPIObjectReference.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 29/08/2011. 6 | // Copyright (c) 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPAPIObjectReference.h" 10 | 11 | @interface OSPAPIObjectReference () 12 | 13 | @property (readwrite, assign) OSPMemberType type; 14 | 15 | @end 16 | 17 | @implementation OSPAPIObjectReference 18 | 19 | @synthesize type; 20 | 21 | + (id)apiObjectReferenceWithType:(OSPMemberType)type identity:(NSInteger)identity 22 | { 23 | return [[self alloc] initWithType:type identity:identity]; 24 | } 25 | 26 | - (id)initWithType:(OSPMemberType)initType identity:(NSInteger)identity 27 | { 28 | self = [super initUnsafely]; 29 | 30 | if (nil != self) 31 | { 32 | [self setType:initType]; 33 | [self setIdentity:identity]; 34 | } 35 | 36 | return self; 37 | } 38 | 39 | - (OSPMemberType)memberType 40 | { 41 | return [self type]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/AbstractMessage_Builder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "Message_Builder.h" 16 | 17 | /** 18 | * A partial implementation of the {@link Message.Builder} interface which 19 | * implements as many methods of that interface as possible in terms of 20 | * other methods. 21 | */ 22 | @interface PBAbstractMessage_Builder : NSObject { 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/AbstractMessage.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "Message.h" 16 | 17 | /** 18 | * A partial implementation of the {@link Message} interface which implements 19 | * as many methods of that interface as possible in terms of other methods. 20 | * 21 | * @author Cyrus Najmabadi 22 | */ 23 | @interface PBAbstractMessage : NSObject { 24 | @private 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSBinaryTest.h: -------------------------------------------------------------------------------- 1 | // 2 | // BinaryTest.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSTest.h" 10 | 11 | #import "OSPMapCSSTag.h" 12 | 13 | typedef enum 14 | { 15 | OSPMapCSSBinaryOperatorEquals, 16 | OSPMapCSSBinaryOperatorNotEquals, 17 | OSPMapCSSBinaryOperatorMatches, 18 | OSPMapCSSBinaryOperatorGreaterThan, 19 | OSPMapCSSBinaryOperatorLessThan, 20 | OSPMapCSSBinaryOperatorGreaterThanOrEqual, 21 | OSPMapCSSBinaryOperatorLessThanOrEqual 22 | } OSPMapCSSBinaryOperator; 23 | 24 | OSPMapCSSBinaryOperator OSPMapCSSBinaryOperatorFromNSString(NSString *s); 25 | NSString *NSStringFromOSPMapCSSBinaryOperator(OSPMapCSSBinaryOperator o); 26 | 27 | @interface OSPMapCSSBinaryTest : OSPMapCSSTest 28 | 29 | @property (readwrite, strong) NSString *tagName; 30 | @property (readwrite, assign) OSPMapCSSBinaryOperator operator; 31 | @property (readwrite, copy) NSString *value; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/API/OSPNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPNode.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPNode.h" 10 | 11 | @interface OSPNode () 12 | 13 | @property (/*nonatomic,*/readwrite,assign) OSPCoordinate2D projectedLocation; 14 | 15 | @end 16 | 17 | @implementation OSPNode 18 | 19 | @synthesize location; 20 | @synthesize projectedLocation; 21 | 22 | - (CLLocationCoordinate2D)location 23 | { 24 | @synchronized(self) 25 | { 26 | return location; 27 | } 28 | } 29 | 30 | - (void)setLocation:(CLLocationCoordinate2D)newLocation 31 | { 32 | @synchronized(self) 33 | { 34 | location = newLocation; 35 | [self setProjectedLocation:OSPCoordinate2DProjectLocation(newLocation)]; 36 | } 37 | } 38 | 39 | - (OSPCoordinateRect)bounds 40 | { 41 | return OSPCoordinateRectMake(projectedLocation.x, projectedLocation.y, 0.0, 0.0); 42 | } 43 | 44 | - (OSPMemberType)memberType 45 | { 46 | return OSPMemberTypeNode; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/Main.m: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "UnknownFieldSetTest.h" 16 | #import "WireFormatTests.h" 17 | 18 | int main (int argc, const char * argv[]) { 19 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 20 | // insert code here... 21 | NSLog(@"Hello, World!"); 22 | 23 | WireFormatTests* tests = [[[WireFormatTests alloc] init] autorelease]; 24 | [tests testParsePackedExtensions]; 25 | 26 | [pool drain]; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/Bootstrap.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ForwardDeclarations.h" 16 | 17 | #import "CodedInputStream.h" 18 | #import "CodedOutputStream.h" 19 | #import "ExtendableMessage.h" 20 | #import "ExtendableMessage_Builder.h" 21 | #import "ExtensionRegistry.h" 22 | #import "GeneratedMessage.h" 23 | #import "GeneratedMessage_Builder.h" 24 | #import "Message_Builder.h" 25 | #import "UnknownFieldSet.h" 26 | #import "UnknownFieldSet_Builder.h" 27 | #import "Utilities.h" 28 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/GeneratedMessage_Builder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "AbstractMessage_Builder.h" 16 | 17 | @interface PBGeneratedMessage_Builder : PBAbstractMessage_Builder { 18 | } 19 | 20 | /* @protected */ 21 | - (BOOL) parseUnknownField:(PBCodedInputStream*) input 22 | unknownFields:(PBUnknownFieldSet_Builder*) unknownFields 23 | extensionRegistry:(PBExtensionRegistry*) extensionRegistry 24 | tag:(int32_t) tag; 25 | 26 | - (void) checkInitialized; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/WireFormat.m: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "WireFormat.h" 16 | 17 | #import "Utilities.h" 18 | 19 | int32_t PBWireFormatMakeTag(int32_t fieldNumber, int32_t wireType) { 20 | return (fieldNumber << PBWireFormatTagTypeBits) | wireType; 21 | } 22 | 23 | 24 | int32_t PBWireFormatGetTagWireType(int32_t tag) { 25 | return tag & PBWireFormatTagTypeMask; 26 | } 27 | 28 | 29 | int32_t PBWireFormatGetTagFieldNumber(int32_t tag) { 30 | return logicalRightShift32(tag, PBWireFormatTagTypeBits); 31 | } 32 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSSpecifierList.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSSpecifierList.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSSpecifierList.h" 10 | 11 | #import "OSPMapCSSSpecifier.h" 12 | 13 | @implementation OSPMapCSSSpecifierList 14 | 15 | @synthesize specifiers; 16 | 17 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 18 | { 19 | self = [super init]; 20 | 21 | if (nil != self) 22 | { 23 | NSMutableArray *allButOneChild = [[syntaxTree children][1] mutableCopy]; 24 | [allButOneChild insertObject:[syntaxTree children][0] atIndex:0]; 25 | [self setSpecifiers:allButOneChild]; 26 | } 27 | 28 | return self; 29 | } 30 | 31 | - (NSString *)description 32 | { 33 | NSMutableString *desc = [NSMutableString string]; 34 | 35 | NSUInteger specNum = 0; 36 | for (OSPMapCSSSpecifier *s in [self specifiers]) 37 | { 38 | [desc appendFormat:(specNum < [[self specifiers] count] - 1) ? @"%@, " : @"%@", s]; 39 | specNum++; 40 | } 41 | return desc; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/MutableField.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "Field.h" 16 | 17 | @interface PBMutableField : PBField { 18 | } 19 | 20 | + (PBMutableField*) field; 21 | 22 | - (PBMutableField*) mergeFromField:(PBField*) other; 23 | 24 | - (PBMutableField*) clear; 25 | - (PBMutableField*) addVarint:(int64_t) value; 26 | - (PBMutableField*) addFixed32:(int32_t) value; 27 | - (PBMutableField*) addFixed64:(int64_t) value; 28 | - (PBMutableField*) addLengthDelimited:(NSData*) value; 29 | - (PBMutableField*) addGroup:(PBUnknownFieldSet*) value; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/Utilities.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | int64_t convertFloat64ToInt64(Float64 f); 16 | int32_t convertFloat32ToInt32(Float32 f); 17 | Float64 convertInt64ToFloat64(int64_t f); 18 | Float32 convertInt32ToFloat32(int32_t f); 19 | 20 | uint64_t convertInt64ToUInt64(int64_t i); 21 | int64_t convertUInt64ToInt64(uint64_t u); 22 | uint32_t convertInt32ToUInt32(int32_t i); 23 | int64_t convertUInt32ToInt32(uint32_t u); 24 | 25 | int32_t logicalRightShift32(int32_t value, int32_t spaces); 26 | int64_t logicalRightShift64(int64_t value, int32_t spaces); 27 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/ForwardDeclarations.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | @protocol PBMessage; 16 | @protocol PBMessage_Builder; 17 | @protocol PBExtensionField; 18 | 19 | @class PBAbstractMessage; 20 | @class PBCodedInputStream; 21 | @class PBCodedOutputStream; 22 | @class PBConcreteExtensionField; 23 | @class PBExtendableMessage_Builder; 24 | @class PBExtendableMessage; 25 | @class PBExtensionRegistry; 26 | @class PBField; 27 | @class PBGeneratedMessage; 28 | @class PBGeneratedMessage_Builder; 29 | @class PBMutableExtensionRegistry; 30 | @class PBMutableField; 31 | @class PBUnknownFieldSet; 32 | @class PBUnknownFieldSet_Builder; 33 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/GeneratedMessage.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "AbstractMessage.h" 16 | 17 | /** 18 | * All generated protocol message classes extend this class. This class 19 | * implements most of the Message and Builder interfaces using Java reflection. 20 | * Users can ignore this class and pretend that generated messages implement 21 | * the Message interface directly. 22 | * 23 | * @author Cyrus Najmabadi 24 | */ 25 | @interface PBGeneratedMessage : PBAbstractMessage { 26 | @private 27 | PBUnknownFieldSet* unknownFields; 28 | 29 | @protected 30 | int32_t memoizedSerializedSize; 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Thomas Davie 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/GeneratedMessage.m: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "GeneratedMessage.h" 16 | 17 | #import "UnknownFieldSet.h" 18 | 19 | @interface PBGeneratedMessage () 20 | @property (retain) PBUnknownFieldSet* unknownFields; 21 | @end 22 | 23 | 24 | @implementation PBGeneratedMessage 25 | 26 | @synthesize unknownFields; 27 | 28 | - (void) dealloc { 29 | self.unknownFields = nil; 30 | [super dealloc]; 31 | } 32 | 33 | 34 | - (id) init { 35 | if ((self = [super init])) { 36 | self.unknownFields = [PBUnknownFieldSet defaultInstance]; 37 | memoizedSerializedSize = -1; 38 | } 39 | 40 | return self; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSSizeSpecifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // SizeListSpecifier.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSSizeSpecifier.h" 10 | 11 | #import "OSPMapCSSSize.h" 12 | 13 | @implementation OSPMapCSSSizeSpecifier 14 | 15 | @synthesize size; 16 | 17 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 18 | { 19 | self = [super initWithSyntaxTree:syntaxTree]; 20 | 21 | if (nil != self) 22 | { 23 | [self setSize:[syntaxTree children][0]]; 24 | } 25 | 26 | return self; 27 | } 28 | 29 | - (id)initWithSize:(OSPMapCSSSize *)initSize 30 | { 31 | self = [super init]; 32 | 33 | if (nil != self) 34 | { 35 | [self setSize:initSize]; 36 | } 37 | 38 | return self; 39 | } 40 | 41 | - (NSString *)description 42 | { 43 | return [[self size] description]; 44 | } 45 | 46 | - (NSString *)stringValue 47 | { 48 | return [self description]; 49 | } 50 | 51 | - (OSPMapCSSSize *)sizeValue 52 | { 53 | return [self size]; 54 | } 55 | 56 | #if TARGET_OS_IPHONE 57 | - (UIColor *)colourValue 58 | { 59 | return nil; 60 | } 61 | #endif 62 | 63 | - (OSPMapCSSUrl *)urlValue 64 | { 65 | return nil; 66 | } 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSURLSpecifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // URLSpecifier.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSURLSpecifier.h" 10 | 11 | @implementation OSPMapCSSURLSpecifier 12 | 13 | @synthesize url; 14 | 15 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 16 | { 17 | self = [super initWithSyntaxTree:syntaxTree]; 18 | 19 | if (nil != self) 20 | { 21 | [self setUrl:[syntaxTree children][0]]; 22 | } 23 | 24 | return self; 25 | } 26 | 27 | - (id)initWithURL:(OSPMapCSSUrl *)initUrl 28 | { 29 | self = [super init]; 30 | 31 | if (nil != self) 32 | { 33 | [self setUrl:initUrl]; 34 | } 35 | 36 | return self; 37 | } 38 | 39 | - (NSString *)description 40 | { 41 | return [NSString stringWithFormat:@"url(%@)", [self url]]; 42 | } 43 | 44 | - (NSString *)stringValue 45 | { 46 | return [NSString stringWithFormat:@"%@", [self url]]; 47 | } 48 | 49 | - (OSPMapCSSSize *)sizeValue 50 | { 51 | return nil; 52 | } 53 | 54 | #if TARGET_OS_IPHONE 55 | - (UIColor *)colourValue 56 | { 57 | return nil; 58 | } 59 | #endif 60 | 61 | - (OSPMapCSSUrl *)urlValue 62 | { 63 | return [self url]; 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /OpenStreetPad/OpenStreetPad-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFiles 12 | 13 | CFBundleIdentifier 14 | com.inthebeginninggames.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | 1.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | 1.0 27 | LSRequiresIPhoneOS 28 | 29 | UISupportedInterfaceOrientations~ipad 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationPortraitUpsideDown 33 | UIInterfaceOrientationLandscapeLeft 34 | UIInterfaceOrientationLandscapeRight 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/ProtocolBuffers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "Bootstrap.h" 16 | 17 | #import "AbstractMessage.h" 18 | #import "AbstractMessage_Builder.h" 19 | #import "CodedInputStream.h" 20 | #import "CodedOutputStream.h" 21 | #import "ConcreteExtensionField.h" 22 | #import "ExtendableMessage.h" 23 | #import "ExtendableMessage_Builder.h" 24 | #import "ExtensionField.h" 25 | #import "ExtensionRegistry.h" 26 | #import "Field.h" 27 | #import "GeneratedMessage.h" 28 | #import "GeneratedMessage_Builder.h" 29 | #import "Message.h" 30 | #import "Message_Builder.h" 31 | #import "MutableExtensionRegistry.h" 32 | #import "MutableField.h" 33 | #import "UnknownFieldSet.h" 34 | #import "UnknownFieldSet_Builder.h" 35 | #import "Utilities.h" 36 | #import "WireFormat.h" 37 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSStyle.m: -------------------------------------------------------------------------------- 1 | // 2 | // Style.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSStyle.h" 10 | 11 | #import "OSPMapCSSRule.h" 12 | 13 | @implementation OSPMapCSSStyle 14 | 15 | @synthesize containsRule; 16 | @synthesize rule; 17 | @synthesize exit; 18 | @synthesize key; 19 | @synthesize specifiers; 20 | 21 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 22 | { 23 | self = [super init]; 24 | 25 | if (nil != self) 26 | { 27 | id styledef = [syntaxTree children][0]; 28 | 29 | if ([styledef isKindOfClass:[OSPMapCSSRule class]]) 30 | { 31 | [self setContainsRule:YES]; 32 | [self setRule:styledef]; 33 | } 34 | else 35 | { 36 | [self setExit:[[styledef children][0] isKindOfClass:[CPKeywordToken class]]]; 37 | if (![self isExit]) 38 | { 39 | [self setKey:[[styledef children][0] key]]; 40 | [self setSpecifiers:[styledef children][2]]; 41 | } 42 | } 43 | } 44 | 45 | return self; 46 | } 47 | 48 | - (NSString *)description 49 | { 50 | return [self isExit] ? @"exit" : [NSString stringWithFormat:@"%@: %@;", [self key], [self specifiers]]; 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSNamedSpecifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // NamedSpecifier.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSNamedSpecifier.h" 10 | 11 | #if TARGET_OS_IPHONE 12 | #import "UIColor+CSS.h" 13 | #endif 14 | 15 | @implementation OSPMapCSSNamedSpecifier 16 | 17 | @synthesize name; 18 | 19 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 20 | { 21 | self = [super initWithSyntaxTree:syntaxTree]; 22 | 23 | if (nil != self) 24 | { 25 | [self setName:[[syntaxTree children][0] name]]; 26 | } 27 | 28 | return self; 29 | } 30 | 31 | - (id)initWithName:(NSString *)initName 32 | { 33 | self = [super init]; 34 | 35 | if (nil != self) 36 | { 37 | [self setName:initName]; 38 | } 39 | 40 | return self; 41 | } 42 | 43 | - (NSString *)description 44 | { 45 | return [self name]; 46 | } 47 | 48 | - (NSString *)stringValue 49 | { 50 | return [self name]; 51 | } 52 | 53 | - (OSPMapCSSSize *)sizeValue 54 | { 55 | return nil; 56 | } 57 | 58 | #if TARGET_OS_IPHONE 59 | - (UIColor *)colourValue 60 | { 61 | return [UIColor colourWithCSSName:[self name]]; 62 | } 63 | #endif 64 | 65 | - (OSPMapCSSUrl *)urlValue 66 | { 67 | return [[OSPMapCSSUrl alloc] initWithURL:[NSURL URLWithString:[self name]]]; 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /OpenStreetPad/OSPMainViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OpenStreetPadViewController.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPMainViewController.h" 10 | 11 | @implementation OSPMainViewController 12 | 13 | - (void)didReceiveMemoryWarning 14 | { 15 | [super didReceiveMemoryWarning]; 16 | // Release any cached data, images, etc that aren't in use. 17 | } 18 | 19 | #pragma mark - View lifecycle 20 | 21 | - (void)viewDidLoad 22 | { 23 | [super viewDidLoad]; 24 | // Do any additional setup after loading the view, typically from a nib. 25 | } 26 | 27 | - (void)viewDidUnload 28 | { 29 | [super viewDidUnload]; 30 | // Release any retained subviews of the main view. 31 | // e.g. self.myOutlet = nil; 32 | } 33 | 34 | - (void)viewWillAppear:(BOOL)animated 35 | { 36 | [super viewWillAppear:animated]; 37 | } 38 | 39 | - (void)viewDidAppear:(BOOL)animated 40 | { 41 | [super viewDidAppear:animated]; 42 | } 43 | 44 | - (void)viewWillDisappear:(BOOL)animated 45 | { 46 | [super viewWillDisappear:animated]; 47 | } 48 | 49 | - (void)viewDidDisappear:(BOOL)animated 50 | { 51 | [super viewDidDisappear:animated]; 52 | } 53 | 54 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 55 | { 56 | // Return YES for supported orientations 57 | return YES; 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/ExtensionField.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "WireFormat.h" 16 | 17 | #import "ForwardDeclarations.h" 18 | 19 | @protocol PBExtensionField 20 | - (int32_t) fieldNumber; 21 | - (PBWireFormat) wireType; 22 | - (BOOL) isRepeated; 23 | - (Class) extendedClass; 24 | - (id) defaultValue; 25 | 26 | - (void) mergeFromCodedInputStream:(PBCodedInputStream*) input 27 | unknownFields:(PBUnknownFieldSet_Builder*) unknownFields 28 | extensionRegistry:(PBExtensionRegistry*) extensionRegistry 29 | builder:(PBExtendableMessage_Builder*) builder 30 | tag:(int32_t) tag; 31 | - (void) writeValue:(id) value includingTagToCodedOutputStream:(PBCodedOutputStream*) output; 32 | - (int32_t) computeSerializedSizeIncludingTag:(id) value; 33 | @end 34 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/API/OSPAPIObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPApiObject.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "OSPCoordinateRect.h" 12 | 13 | typedef enum 14 | { 15 | OSPMemberTypeNode = 0x0, 16 | OSPMemberTypeWay = 0x1, 17 | OSPMemberTypeRelation = 0x2, 18 | OSPMemberTypeNone = 0x3 19 | } OSPMemberType; 20 | 21 | NSString *NSStringFromOSPMemberType(OSPMemberType t); 22 | 23 | @class OSPMap; 24 | 25 | @class OSPAPIObjectReference; 26 | 27 | @interface OSPAPIObject : NSObject 28 | 29 | @property (readwrite, assign) NSInteger identity; 30 | @property (readwrite, assign) NSUInteger version; 31 | @property (readwrite, assign) NSUInteger changesetId; 32 | @property (readwrite, strong) NSString *user; 33 | @property (readwrite, assign) NSUInteger userId; 34 | @property (readwrite, assign) BOOL visible; 35 | @property (readwrite, strong) NSDate *timestamp; 36 | 37 | @property (readwrite, copy ) NSDictionary *tags; 38 | 39 | @property (readwrite, copy ) NSSet *parents; 40 | 41 | @property (readwrite, weak) OSPMap *map; 42 | 43 | @property (readonly) OSPMemberType memberType; 44 | 45 | - (id)initUnsafely; 46 | 47 | - (BOOL)isEqualToAPIObject:(OSPAPIObject *)object; 48 | 49 | - (NSSet *)childObjects; 50 | - (void)addParent:(OSPAPIObjectReference *)newParent; 51 | 52 | - (id)valueForTag:(NSString *)tagName; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSColour.m: -------------------------------------------------------------------------------- 1 | // 2 | // Colour.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSColour.h" 10 | 11 | #import "OSPMapCSSHashColourToken.h" 12 | 13 | @implementation OSPMapCSSColour 14 | 15 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 16 | { 17 | #if TARGET_OS_IPHONE 18 | CPToken *firstToken = [syntaxTree children][0]; 19 | 20 | if ([firstToken isKindOfClass:[CPKeywordToken class]]) 21 | { 22 | NSString *keyword = [(CPKeywordToken *)firstToken keyword]; 23 | if ([keyword isEqualToString:@"rgb"]) 24 | { 25 | return (OSPMapCSSColour *)[UIColor colorWithRed:[[[syntaxTree children][2] number] floatValue] green:[[[syntaxTree children][4] number] floatValue] blue:[[[syntaxTree children][6] number] floatValue] alpha:1.0f]; 26 | } 27 | else 28 | { 29 | return (OSPMapCSSColour *)[UIColor colorWithRed:[[[syntaxTree children][2] number] floatValue] green:[[[syntaxTree children][4] number] floatValue] blue:[[[syntaxTree children][6] number] floatValue] alpha:[[[syntaxTree children][8] number] floatValue]]; 30 | } 31 | } 32 | else if ([firstToken isKindOfClass:[OSPMapCSSHashColourToken class]]) 33 | { 34 | return (OSPMapCSSColour *)[(OSPMapCSSHashColourToken *)firstToken colour]; 35 | } 36 | #endif 37 | 38 | return nil; 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSColourSpecifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // ColourSpecifier.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSColourSpecifier.h" 10 | 11 | @implementation OSPMapCSSColourSpecifier 12 | 13 | #if TARGET_OS_IPHONE 14 | @synthesize colour; 15 | 16 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 17 | { 18 | self = [super initWithSyntaxTree:syntaxTree]; 19 | 20 | if (nil != self) 21 | { 22 | [self setColour:[syntaxTree children][0]]; 23 | } 24 | 25 | return self; 26 | } 27 | 28 | - (id)initWithColour:(UIColor *)initColour 29 | { 30 | self = [super init]; 31 | 32 | if (nil != self) 33 | { 34 | [self setColour:initColour]; 35 | } 36 | 37 | return self; 38 | } 39 | 40 | - (NSString *)description 41 | { 42 | CGFloat red; 43 | CGFloat green; 44 | CGFloat blue; 45 | CGFloat alpha; 46 | [[self colour] getRed:&red green:&green blue:&blue alpha:&alpha]; 47 | return [NSString stringWithFormat:@"rgba(%1.2f, %1.2f, %1.2f, %1.2f)", red, green, blue, alpha]; 48 | } 49 | 50 | - (NSString *)stringValue 51 | { 52 | return [self description]; 53 | } 54 | 55 | - (OSPMapCSSSize *)sizeValue 56 | { 57 | return nil; 58 | } 59 | 60 | - (UIColor *)colourValue 61 | { 62 | return [self colour]; 63 | } 64 | 65 | - (OSPMapCSSUrl *)urlValue 66 | { 67 | return nil; 68 | } 69 | 70 | #endif 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSSpecifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // Specifier.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSSpecifier.h" 10 | 11 | #import "OSPMapCSSPlaceholderSpecifier.h" 12 | 13 | @implementation OSPMapCSSSpecifier 14 | 15 | + (id)allocWithZone:(NSZone *)zone 16 | { 17 | return (self == [OSPMapCSSSpecifier class]) ? [OSPMapCSSPlaceholderSpecifier allocWithZone:zone] : [super allocWithZone:zone]; 18 | } 19 | 20 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 21 | { 22 | return [super init]; 23 | } 24 | 25 | - (NSString *)stringValue; 26 | { 27 | [[NSException exceptionWithName:@"Abstract class exception" reason:@"OSPMapCSSSpecifier is an abstract class" userInfo:nil] raise]; 28 | return nil; 29 | } 30 | 31 | - (OSPMapCSSSize *)sizeValue; 32 | { 33 | [[NSException exceptionWithName:@"Abstract class exception" reason:@"OSPMapCSSSpecifier is an abstract class" userInfo:nil] raise]; 34 | return nil; 35 | } 36 | 37 | #if TARGET_OS_IPHONE 38 | - (UIColor *)colourValue; 39 | { 40 | [[NSException exceptionWithName:@"Abstract class exception" reason:@"OSPMapCSSSpecifier is an abstract class" userInfo:nil] raise]; 41 | return nil; 42 | } 43 | #endif 44 | 45 | - (OSPMapCSSUrl *)urlValue 46 | { 47 | [[NSException exceptionWithName:@"Abstract class exception" reason:@"OSPMapCSSSpecifier is an abstract class" userInfo:nil] raise]; 48 | return nil; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/UnknownFieldSet.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ForwardDeclarations.h" 16 | 17 | @interface PBUnknownFieldSet : NSObject { 18 | @private 19 | NSDictionary* fields; 20 | } 21 | 22 | @property (readonly, retain) NSDictionary* fields; 23 | 24 | + (PBUnknownFieldSet*) defaultInstance; 25 | 26 | + (PBUnknownFieldSet*) setWithFields:(NSMutableDictionary*) fields; 27 | + (PBUnknownFieldSet*) parseFromData:(NSData*) data; 28 | 29 | + (PBUnknownFieldSet_Builder*) builder; 30 | + (PBUnknownFieldSet_Builder*) builderWithUnknownFields:(PBUnknownFieldSet*) other; 31 | 32 | - (void) writeAsMessageSetTo:(PBCodedOutputStream*) output; 33 | - (void) writeToCodedOutputStream:(PBCodedOutputStream*) output; 34 | - (NSData*) data; 35 | 36 | - (int32_t) serializedSize; 37 | - (int32_t) serializedSizeAsMessageSet; 38 | 39 | - (BOOL) hasField:(int32_t) number; 40 | - (PBField*) getField:(int32_t) number; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSTag.m: -------------------------------------------------------------------------------- 1 | // 2 | // Tag.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSTag.h" 10 | 11 | #import "OSPMapCSSKey.h" 12 | 13 | @implementation OSPMapCSSTag 14 | 15 | @synthesize pseudoTag; 16 | @synthesize tagName; 17 | 18 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 19 | { 20 | self = [super init]; 21 | 22 | if (nil != self) 23 | { 24 | NSArray *c = [syntaxTree children]; 25 | NSString *tn = nil; 26 | 27 | if ([c count] == 1) 28 | { 29 | tn = [c[0] content]; 30 | if ([tn characterAtIndex:0] == ':') 31 | { 32 | [self setPseudoTag:YES]; 33 | } 34 | } 35 | else 36 | { 37 | NSArray *possiblyTag = c[0]; 38 | BOOL ps = [possiblyTag count] == 0; 39 | [self setPseudoTag:ps]; 40 | tn = ps ? [NSMutableString string] : [[possiblyTag[0] key] mutableCopy]; 41 | for (NSArray *k in c[1]) 42 | { 43 | [(NSMutableString *)tn appendFormat:@":%@", [k[1] key]]; 44 | } 45 | } 46 | 47 | [self setTagName:[self isPseudoTag] ? [tn substringFromIndex:1] : tn]; 48 | } 49 | 50 | return self; 51 | } 52 | 53 | - (NSString *)description 54 | { 55 | return [self isPseudoTag] ? [NSString stringWithFormat:@":%@", [self tagName]] : [self tagName]; 56 | } 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/Field.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ForwardDeclarations.h" 16 | 17 | @interface PBField : NSObject { 18 | @protected 19 | NSMutableArray* mutableVarintList; 20 | NSMutableArray* mutableFixed32List; 21 | NSMutableArray* mutableFixed64List; 22 | NSMutableArray* mutableLengthDelimitedList; 23 | NSMutableArray* mutableGroupList; 24 | } 25 | 26 | - (NSArray*) varintList; 27 | - (NSArray*) fixed32List; 28 | - (NSArray*) fixed64List; 29 | - (NSArray*) lengthDelimitedList; 30 | - (NSArray*) groupList; 31 | 32 | + (PBField*) defaultInstance; 33 | 34 | - (void) writeTo:(int32_t) fieldNumber 35 | output:(PBCodedOutputStream*) output; 36 | 37 | - (int32_t) getSerializedSize:(int32_t) fieldNumber; 38 | - (void) writeAsMessageSetExtensionTo:(int32_t) fieldNumber 39 | output:(PBCodedOutputStream*) output; 40 | - (int32_t) getSerializedSizeAsMessageSetExtension:(int32_t) fieldNumber; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSUnaryTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // UnaryTest.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSUnaryTest.h" 10 | 11 | #import "NSString+OpenStreetPad.h" 12 | 13 | @implementation OSPMapCSSUnaryTest 14 | 15 | @synthesize negated; 16 | @synthesize tagName; 17 | 18 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 19 | { 20 | self = [super initWithSyntaxTree:syntaxTree]; 21 | 22 | if (nil != self) 23 | { 24 | switch ([[syntaxTree children] count]) 25 | { 26 | case 1: 27 | [self setNegated:NO]; 28 | [self setTagName:[[syntaxTree children][0] description]]; 29 | break; 30 | case 2: 31 | [self setNegated:YES]; 32 | [self setTagName:[[syntaxTree children][1] description]]; 33 | default: 34 | break; 35 | } 36 | } 37 | 38 | return self; 39 | } 40 | 41 | - (id)initWithTagName:(NSString *)tn negated:(BOOL)n 42 | { 43 | self = [super init]; 44 | 45 | if (nil != self) 46 | { 47 | [self setTagName:tn]; 48 | [self setNegated:n]; 49 | } 50 | 51 | return self; 52 | } 53 | 54 | - (NSString *)description 55 | { 56 | return [self isNegated] ? [NSString stringWithFormat:@"[!%@]", tagName] : [NSString stringWithFormat:@"[%@]", tagName]; 57 | } 58 | 59 | - (BOOL)matchesObject:(OSPAPIObject *)object 60 | { 61 | NSString *value = [object valueForTag:tagName]; 62 | 63 | return negated ? nil == value || [value ospUntruthValue] : nil != value && ![value ospUntruthValue]; 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSZoom.m: -------------------------------------------------------------------------------- 1 | // 2 | // Zoom.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 01/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSZoom.h" 10 | 11 | @implementation OSPMapCSSZoom 12 | 13 | @synthesize minimumZoom; 14 | @synthesize maximumZoom; 15 | 16 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 17 | { 18 | self = [super init]; 19 | 20 | if (nil != self) 21 | { 22 | CPSyntaxTree *range = [syntaxTree children][1]; 23 | 24 | switch ([[range children] count]) 25 | { 26 | case 1: 27 | { 28 | float r = [[[range children][0] number] floatValue]; 29 | [self setMinimumZoom:r]; 30 | [self setMaximumZoom:r]; 31 | break; 32 | } 33 | case 2: 34 | { 35 | if ([[range children][0] isKindOfClass:[CPKeywordToken class]]) 36 | { 37 | [self setMinimumZoom:-1.0]; 38 | [self setMaximumZoom:[[[range children][1] number] floatValue]]; 39 | } 40 | else 41 | { 42 | [self setMinimumZoom:[[[range children][0] number] floatValue]]; 43 | [self setMaximumZoom:-1.0]; 44 | } 45 | break; 46 | } 47 | case 3: 48 | { 49 | [self setMinimumZoom:[[[range children][0] number] floatValue]]; 50 | [self setMaximumZoom:[[[range children][2] number] floatValue]]; 51 | break; 52 | } 53 | default: 54 | break; 55 | } 56 | } 57 | 58 | return self; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/WireFormat.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | typedef enum { 16 | PBWireFormatVarint = 0, 17 | PBWireFormatFixed64 = 1, 18 | PBWireFormatLengthDelimited = 2, 19 | PBWireFormatStartGroup = 3, 20 | PBWireFormatEndGroup = 4, 21 | PBWireFormatFixed32 = 5, 22 | 23 | PBWireFormatTagTypeBits = 3, 24 | PBWireFormatTagTypeMask = 7 /* = (1 << PBWireFormatTagTypeBits) - 1*/, 25 | 26 | PBWireFormatMessageSetItem = 1, 27 | PBWireFormatMessageSetTypeId = 2, 28 | PBWireFormatMessageSetMessage = 3 29 | } PBWireFormat; 30 | 31 | int32_t PBWireFormatMakeTag(int32_t fieldNumber, int32_t wireType); 32 | int32_t PBWireFormatGetTagWireType(int32_t tag); 33 | int32_t PBWireFormatGetTagFieldNumber(int32_t tag); 34 | 35 | #define PBWireFormatMessageSetItemTag (PBWireFormatMakeTag(PBWireFormatMessageSetItem, PBWireFormatStartGroup)) 36 | #define PBWireFormatMessageSetItemEndTag (PBWireFormatMakeTag(PBWireFormatMessageSetItem, PBWireFormatEndGroup)) 37 | #define PBWireFormatMessageSetTypeIdTag (PBWireFormatMakeTag(PBWireFormatMessageSetTypeId, PBWireFormatVarint)) 38 | #define PBWireFormatMessageSetMessageTag (PBWireFormatMakeTag(PBWireFormatMessageSetMessage, PBWireFormatLengthDelimited)) 39 | -------------------------------------------------------------------------------- /OpenStreetPad/Cocoa Extensions/PSYEnumerable.h: -------------------------------------------------------------------------------- 1 | /* 2 | PSYEnumerable.h 3 | Created by Remy "Psy" Demarest on 21/4/2012. 4 | 5 | Copyright (c) 2012. Remy "Psy" Demarest 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | void PSYMultiDictionaryEnumerator(NSArray *enumaratedDicts, BOOL finishAll, void(^block)(id key, __unsafe_unretained const id *objects, BOOL *stop)); 27 | void PSYMultiEnumerator(NSArray *enumerated, BOOL finishAll, void(^block)(__unsafe_unretained const id *objects, BOOL *stop)); 28 | 29 | NSArray *PSYZipCollections(NSArray *collections, BOOL finishAll, id(^block)(__unsafe_unretained const id *objects, BOOL *stop)); 30 | NSDictionary *PSYZipDictionaries(NSArray *dicts, BOOL finishAll, id(^block)(id key, __unsafe_unretained const id *objects, BOOL *stop)); 31 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSTagSpecifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSTagSpecifier.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSTagSpecifier.h" 10 | 11 | #import "OSPMapCSSNamedSpecifier.h" 12 | #import "OSPMapCSSSizeSpecifier.h" 13 | #import "OSPMapCSSColourSpecifier.h" 14 | #import "OSPMapCSSURLSpecifier.h" 15 | 16 | #import "OSPMapCSSSize.h" 17 | 18 | @implementation OSPMapCSSTagSpecifier 19 | 20 | @synthesize tag; 21 | 22 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 23 | { 24 | self = [super initWithSyntaxTree:syntaxTree]; 25 | 26 | if (nil != self) 27 | { 28 | [self setTag:[syntaxTree children][0]]; 29 | } 30 | 31 | return self; 32 | } 33 | 34 | - (NSString *)description 35 | { 36 | return [NSString stringWithFormat:@"tag(\"%@\")", [[self tag] tag]]; 37 | } 38 | 39 | - (OSPMapCSSSpecifier *)specifierWithAPIObject:(OSPAPIObject *)object 40 | { 41 | id value = [object tags][[[self tag] tag]]; 42 | if ([value isKindOfClass:[NSString class]]) 43 | { 44 | return [[OSPMapCSSNamedSpecifier alloc] initWithName:value]; 45 | } 46 | else if ([value isKindOfClass:[NSNumber class]]) 47 | { 48 | return [[OSPMapCSSSizeSpecifier alloc] initWithSize:[[OSPMapCSSSize alloc] initWithValue:value units:OSPMapCSSUnitPt]]; 49 | } 50 | else if ([value isKindOfClass:[NSURL class]]) 51 | { 52 | return [[OSPMapCSSURLSpecifier alloc] initWithURL:[[OSPMapCSSUrl alloc] initWithURL:value]]; 53 | } 54 | #if TARGET_OS_IPHONE 55 | else if ([value isKindOfClass:[UIColor class]]) 56 | { 57 | return [[OSPMapCSSColourSpecifier alloc] initWithColour:value]; 58 | } 59 | #endif 60 | 61 | return nil; 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSPlaceholderSpecifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // PlaceholderSpecifier.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 01/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSPlaceholderSpecifier.h" 10 | 11 | #import "OSPMapCSSNamedSpecifier.h" 12 | #import "OSPMapCSSSizeSpecifier.h" 13 | #import "OSPMapCSSColourSpecifier.h" 14 | #import "OSPMapCSSURLSpecifier.h" 15 | #import "OSPMapCSSEvalSpecifier.h" 16 | #import "OSPMapCSSTagSpecifier.h" 17 | 18 | #import "OSPMapCSSNamed.h" 19 | #import "OSPMapCSSSize.h" 20 | #import "OSPMapCSSUrl.h" 21 | #import "OSPMapCSSEval.h" 22 | #import "OSPMapCSSTagSpec.h" 23 | 24 | @implementation OSPMapCSSPlaceholderSpecifier 25 | 26 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 27 | { 28 | id item = [syntaxTree children][0]; 29 | 30 | if ([item isKindOfClass:[OSPMapCSSNamed class]]) 31 | { 32 | return (id)[[OSPMapCSSNamedSpecifier alloc] initWithSyntaxTree:syntaxTree]; 33 | } 34 | else if ([item isKindOfClass:[OSPMapCSSSize class]]) 35 | { 36 | return (id)[[OSPMapCSSSizeSpecifier alloc] initWithSyntaxTree:syntaxTree]; 37 | } 38 | #if TARGET_OS_IPHONE 39 | else if ([item isKindOfClass:[UIColor class]]) 40 | { 41 | return (id)[[OSPMapCSSColourSpecifier alloc] initWithSyntaxTree:syntaxTree]; 42 | } 43 | #endif 44 | else if ([item isKindOfClass:[OSPMapCSSUrl class]]) 45 | { 46 | return (id)[[OSPMapCSSURLSpecifier alloc] initWithSyntaxTree:syntaxTree]; 47 | } 48 | else if ([item isKindOfClass:[OSPMapCSSEval class]]) 49 | { 50 | return (id)[[OSPMapCSSEvalSpecifier alloc] initWithSyntaxTree:syntaxTree]; 51 | } 52 | else 53 | { 54 | return (id)[[OSPMapCSSTagSpecifier alloc] initWithSyntaxTree:syntaxTree]; 55 | } 56 | } 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/ExtensionRegistry.m: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ExtensionRegistry.h" 16 | 17 | @interface PBExtensionRegistry() 18 | @property (retain) NSDictionary* classMap; 19 | @end 20 | 21 | @implementation PBExtensionRegistry 22 | 23 | @synthesize classMap; 24 | 25 | - (void) dealloc { 26 | self.classMap = nil; 27 | [super dealloc]; 28 | } 29 | 30 | static PBExtensionRegistry* emptyRegistry = nil; 31 | 32 | + (void) initialize { 33 | if (self == [PBExtensionRegistry class]) { 34 | emptyRegistry = [[PBExtensionRegistry alloc] initWithClassMap:[NSDictionary dictionary]]; 35 | } 36 | } 37 | 38 | 39 | - (id) initWithClassMap:(NSDictionary*) map_{ 40 | if ((self = [super init])) { 41 | self.classMap = map_; 42 | } 43 | 44 | return self; 45 | } 46 | 47 | 48 | - (id) keyForClass:(Class) clazz { 49 | return NSStringFromClass(clazz); 50 | } 51 | 52 | 53 | + (PBExtensionRegistry*) emptyRegistry { 54 | return emptyRegistry; 55 | } 56 | 57 | 58 | - (id) getExtension:(Class) clazz fieldNumber:(NSInteger) fieldNumber { 59 | NSDictionary* extensionMap = [classMap objectForKey:[self keyForClass:clazz]]; 60 | return [extensionMap objectForKey:[NSNumber numberWithInteger:fieldNumber]]; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPNonRectangularArea.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPNonRectangularArea.m 3 | // OpenStreetPad 4 | // 5 | // Created by Tom Davie on 04/09/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPNonRectangularArea.h" 10 | 11 | #import "OSPValue.h" 12 | 13 | @interface OSPNonRectangularArea () 14 | 15 | @property (readwrite,strong,nonatomic) NSMutableArray *rects; 16 | 17 | @end 18 | 19 | @implementation OSPNonRectangularArea 20 | 21 | @synthesize rects; 22 | 23 | + (id)emptyArea 24 | { 25 | return [[self alloc] init]; 26 | } 27 | 28 | - (id)init 29 | { 30 | return [self initWithRects:@[]]; 31 | } 32 | 33 | + (id)areaWithRects:(NSArray *)rects 34 | { 35 | return [[self alloc] initWithRects:rects]; 36 | } 37 | 38 | - (id)initWithRects:(NSArray *)initRects; 39 | { 40 | self = [super init]; 41 | 42 | if (nil != self) 43 | { 44 | [self setRects:[initRects mutableCopy]]; 45 | } 46 | 47 | return self; 48 | } 49 | 50 | - (NSArray *)allRects 51 | { 52 | return [self rects]; 53 | } 54 | 55 | - (void)addRect:(OSPCoordinateRect)rect 56 | { 57 | [[self rects] addObject:[OSPValue valueWithRect:rect]]; 58 | } 59 | 60 | - (OSPNonRectangularArea *)areaBySubtractingArea:(OSPNonRectangularArea *)other 61 | { 62 | NSArray *currentArea = [self rects]; 63 | 64 | for (OSPValue *subtractionRectValue in [other rects]) 65 | { 66 | OSPCoordinateRect subtractionRect = [subtractionRectValue rectValue]; 67 | NSMutableArray *newCurrentArea = [NSMutableArray array]; 68 | for (OSPValue *r in currentArea) 69 | { 70 | NSArray *subtractedRects = OSPCoordinateRectSubtract([r rectValue], subtractionRect); 71 | [newCurrentArea addObjectsFromArray:subtractedRects]; 72 | } 73 | currentArea = newCurrentArea; 74 | } 75 | 76 | return [OSPNonRectangularArea areaWithRects:currentArea]; 77 | } 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPValue.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPValue.m 3 | // OpenStreetPad 4 | // 5 | // Created by Tom Davie on 04/09/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPValue.h" 10 | 11 | @interface OSPRectValue : OSPValue 12 | 13 | - (id)initWithRect:(OSPCoordinateRect)rect; 14 | 15 | @end 16 | 17 | @interface OSPTileValue : OSPValue 18 | 19 | - (id)initWithTile:(OSPTile)tile; 20 | 21 | @end 22 | 23 | @implementation OSPValue 24 | 25 | + (id)valueWithRect:(OSPCoordinateRect)rect 26 | { 27 | return [[OSPRectValue alloc] initWithRect:rect]; 28 | } 29 | 30 | + (id)valueWithTile:(OSPTile)tile 31 | { 32 | return [[OSPTileValue alloc] initWithTile:tile]; 33 | } 34 | 35 | - (OSPCoordinateRect)rectValue 36 | { 37 | return OSPCoordinateRectZero; 38 | } 39 | 40 | - (OSPTile)tileValue 41 | { 42 | return (OSPTile){.x = NSNotFound, .y = NSNotFound, .zoom = 0}; 43 | } 44 | 45 | @end 46 | 47 | @interface OSPRectValue () 48 | 49 | @property (readwrite, assign) OSPCoordinateRect rect; 50 | 51 | @end 52 | 53 | @implementation OSPRectValue 54 | 55 | @synthesize rect; 56 | 57 | - (id)initWithRect:(OSPCoordinateRect)r 58 | { 59 | self = [super init]; 60 | 61 | if (nil != self) 62 | { 63 | [self setRect:r]; 64 | } 65 | 66 | return self; 67 | } 68 | 69 | - (OSPCoordinateRect)rectValue 70 | { 71 | return [self rect]; 72 | } 73 | 74 | @end 75 | 76 | @interface OSPTileValue () 77 | 78 | @property (readwrite, assign) OSPTile tile; 79 | 80 | @end 81 | 82 | @implementation OSPTileValue 83 | 84 | @synthesize tile; 85 | 86 | - (id)initWithTile:(OSPTile)t 87 | { 88 | self = [super init]; 89 | 90 | if (nil != self) 91 | { 92 | [self setTile:t]; 93 | } 94 | 95 | return self; 96 | } 97 | 98 | - (OSPTile)tileValue 99 | { 100 | return [self tile]; 101 | } 102 | 103 | @end -------------------------------------------------------------------------------- /OpenStreetPad/Model/API/OSPRelation.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPRelation.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPRelation.h" 10 | 11 | #import "OSPMember.h" 12 | 13 | #import "OSPMap.h" 14 | 15 | @implementation OSPRelation 16 | { 17 | __strong NSMutableArray *members; 18 | } 19 | 20 | - (NSArray *)members 21 | { 22 | @synchronized(self) 23 | { 24 | return members; 25 | } 26 | } 27 | 28 | - (void)setMembers:(NSArray *)newMembers 29 | { 30 | @synchronized(self) 31 | { 32 | members = [newMembers mutableCopy]; 33 | } 34 | } 35 | 36 | - (id)init 37 | { 38 | self = [super init]; 39 | 40 | if (nil != self) 41 | { 42 | [self setMembers:@[]]; 43 | } 44 | 45 | return self; 46 | } 47 | 48 | - (void)addMember:(OSPMember *)member 49 | { 50 | [member setRelation:self]; 51 | [members addObject:member]; 52 | } 53 | 54 | - (OSPCoordinateRect)bounds 55 | { 56 | if ([[self members] count] > 0) 57 | { 58 | 59 | OSPCoordinateRect ownRect = [(OSPMember *)[self members][0] bounds]; 60 | for (OSPMember *member in [self members]) 61 | { 62 | ownRect = OSPCoordinateRectUnion(ownRect, [member bounds]); 63 | } 64 | return ownRect; 65 | } 66 | else 67 | { 68 | return OSPCoordinateRectZero; 69 | } 70 | } 71 | 72 | - (OSPMemberType)memberType 73 | { 74 | return OSPMemberTypeRelation; 75 | } 76 | 77 | - (NSSet *)childObjects 78 | { 79 | NSMutableSet *childNodes = [NSMutableSet setWithCapacity:[[self members] count]]; 80 | for (OSPMember *child in [self members]) 81 | { 82 | id ch = [[self map] apiObjectOfType:[child referencedObjectType] withId:[child referencedObjectId]]; 83 | if (nil != ch) 84 | { 85 | [childNodes addObject:ch]; 86 | } 87 | } 88 | return childNodes; 89 | } 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/UnknownFieldSet_Builder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ForwardDeclarations.h" 16 | 17 | @interface PBUnknownFieldSet_Builder : NSObject { 18 | @private 19 | NSMutableDictionary* fields; 20 | 21 | // Optimization: We keep around a builder for the last field that was 22 | // modified so that we can efficiently add to it multiple times in a 23 | // row (important when parsing an unknown repeated field). 24 | int32_t lastFieldNumber; 25 | 26 | PBMutableField* lastField; 27 | } 28 | 29 | + (PBUnknownFieldSet_Builder*) newBuilder:(PBUnknownFieldSet*) unknownFields; 30 | 31 | - (PBUnknownFieldSet*) build; 32 | - (PBUnknownFieldSet_Builder*) mergeUnknownFields:(PBUnknownFieldSet*) other; 33 | 34 | - (PBUnknownFieldSet_Builder*) mergeFromCodedInputStream:(PBCodedInputStream*) input; 35 | - (PBUnknownFieldSet_Builder*) mergeFromData:(NSData*) data; 36 | - (PBUnknownFieldSet_Builder*) mergeFromInputStream:(NSInputStream*) input; 37 | 38 | - (PBUnknownFieldSet_Builder*) mergeVarintField:(int32_t) number value:(int32_t) value; 39 | 40 | - (BOOL) mergeFieldFrom:(int32_t) tag input:(PBCodedInputStream*) input; 41 | 42 | - (PBUnknownFieldSet_Builder*) addField:(PBField*) field forNumber:(int32_t) number; 43 | 44 | - (PBUnknownFieldSet_Builder*) clear; 45 | - (PBUnknownFieldSet_Builder*) mergeField:(PBField*) field forNumber:(int32_t) number; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/MutableExtensionRegistry.m: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "MutableExtensionRegistry.h" 16 | 17 | #import "ExtensionField.h" 18 | 19 | @interface PBMutableExtensionRegistry() 20 | @property (retain) NSMutableDictionary* mutableClassMap; 21 | @end 22 | 23 | @implementation PBMutableExtensionRegistry 24 | 25 | @synthesize mutableClassMap; 26 | 27 | - (void) dealloc { 28 | self.mutableClassMap = nil; 29 | [super dealloc]; 30 | } 31 | 32 | 33 | - (id) initWithClassMap:(NSMutableDictionary*) mutableClassMap_ { 34 | if ((self = [super initWithClassMap:mutableClassMap_])) { 35 | self.mutableClassMap = mutableClassMap_; 36 | } 37 | 38 | return self; 39 | } 40 | 41 | 42 | + (PBMutableExtensionRegistry*) registry { 43 | return [[[PBMutableExtensionRegistry alloc] initWithClassMap:[NSMutableDictionary dictionary]] autorelease]; 44 | } 45 | 46 | 47 | - (void) addExtension:(id) extension { 48 | if (extension == nil) { 49 | return; 50 | } 51 | 52 | Class extendedClass = [extension extendedClass]; 53 | id key = [self keyForClass:extendedClass]; 54 | 55 | NSMutableDictionary* extensionMap = [classMap objectForKey:key]; 56 | if (extensionMap == nil) { 57 | extensionMap = [NSMutableDictionary dictionary]; 58 | [mutableClassMap setObject:extensionMap forKey:key]; 59 | } 60 | 61 | [extensionMap setObject:extension 62 | forKey:[NSNumber numberWithInteger:[extension fieldNumber]]]; 63 | } 64 | 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/Utilities.m: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "Utilities.h" 16 | 17 | int64_t convertFloat64ToInt64(Float64 v) { 18 | union { Float64 f; int64_t i; } u; 19 | u.f = v; 20 | return u.i; 21 | } 22 | 23 | 24 | int32_t convertFloat32ToInt32(Float32 v) { 25 | union { Float32 f; int32_t i; } u; 26 | u.f = v; 27 | return u.i; 28 | } 29 | 30 | 31 | Float64 convertInt64ToFloat64(int64_t v) { 32 | union { Float64 f; int64_t i; } u; 33 | u.i = v; 34 | return u.f; 35 | } 36 | 37 | 38 | Float32 convertInt32ToFloat32(int32_t v) { 39 | union { Float32 f; int32_t i; } u; 40 | u.i = v; 41 | return u.f; 42 | } 43 | 44 | 45 | uint64_t convertInt64ToUInt64(int64_t v) { 46 | union { int64_t i; uint64_t u; } u; 47 | u.i = v; 48 | return u.u; 49 | } 50 | 51 | 52 | int64_t convertUInt64ToInt64(uint64_t v) { 53 | union { int64_t i; uint64_t u; } u; 54 | u.u = v; 55 | return u.i; 56 | } 57 | 58 | uint32_t convertInt32ToUInt32(int32_t v) { 59 | union { int32_t i; uint32_t u; } u; 60 | u.i = v; 61 | return u.u; 62 | } 63 | 64 | 65 | int64_t convertUInt32ToInt32(uint32_t v) { 66 | union { int32_t i; uint32_t u; } u; 67 | u.u = v; 68 | return u.i; 69 | } 70 | 71 | 72 | int32_t logicalRightShift32(int32_t value, int32_t spaces) { 73 | return convertUInt32ToInt32((convertInt32ToUInt32(value) >> spaces)); 74 | } 75 | 76 | 77 | int64_t logicalRightShift64(int64_t value, int32_t spaces) { 78 | return convertUInt64ToInt64((convertInt64ToUInt64(value) >> spaces)); 79 | } 80 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/ConcreteExtensionField.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ExtensionField.h" 16 | 17 | typedef enum { 18 | PBExtensionTypeBool, 19 | PBExtensionTypeFixed32, 20 | PBExtensionTypeSFixed32, 21 | PBExtensionTypeFloat, 22 | PBExtensionTypeFixed64, 23 | PBExtensionTypeSFixed64, 24 | PBExtensionTypeDouble, 25 | PBExtensionTypeInt32, 26 | PBExtensionTypeInt64, 27 | PBExtensionTypeSInt32, 28 | PBExtensionTypeSInt64, 29 | PBExtensionTypeUInt32, 30 | PBExtensionTypeUInt64, 31 | PBExtensionTypeBytes, 32 | PBExtensionTypeString, 33 | PBExtensionTypeMessage, 34 | PBExtensionTypeGroup, 35 | PBExtensionTypeEnum 36 | } PBExtensionType; 37 | 38 | @interface PBConcreteExtensionField : NSObject { 39 | @private 40 | PBExtensionType type; 41 | 42 | Class extendedClass; 43 | int32_t fieldNumber; 44 | id defaultValue; 45 | 46 | Class messageOrGroupClass; 47 | 48 | BOOL isRepeated; 49 | BOOL isPacked; 50 | BOOL isMessageSetWireFormat; 51 | } 52 | 53 | + (PBConcreteExtensionField*) extensionWithType:(PBExtensionType) type 54 | extendedClass:(Class) extendedClass 55 | fieldNumber:(int32_t) fieldNumber 56 | defaultValue:(id) defaultValue 57 | messageOrGroupClass:(Class) messageOrGroupClass 58 | isRepeated:(BOOL) isRepeated 59 | isPacked:(BOOL) isPacked 60 | isMessageSetWireFormat:(BOOL) isMessageSetWireFormat; 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSSize.m: -------------------------------------------------------------------------------- 1 | // 2 | // Size.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSSize.h" 10 | 11 | OSPMapCSSUnit OSPMapCSSUnitFromNSString(NSString *s) 12 | { 13 | if ([s isEqualToString:@"pt"]) 14 | { 15 | return OSPMapCSSUnitPt; 16 | } 17 | else if ([s isEqualToString:@"pt"]) 18 | { 19 | return OSPMapCSSUnitPx; 20 | } 21 | else 22 | { 23 | return OSPMapCSSUnitPercent; 24 | } 25 | } 26 | 27 | NSString *NSStringFromOSPMapCSSUnit(OSPMapCSSUnit u) 28 | { 29 | switch (u) 30 | { 31 | case OSPMapCSSUnitPt: 32 | return @"pt"; 33 | case OSPMapCSSUnitPx: 34 | return @"px"; 35 | case OSPMapCSSUnitPercent: 36 | return @"%"; 37 | case OSPMapCSSUnitNone: 38 | return @""; 39 | } 40 | } 41 | 42 | @implementation OSPMapCSSSize 43 | 44 | @synthesize value; 45 | @synthesize unit; 46 | 47 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 48 | { 49 | self = [super init]; 50 | 51 | if (nil != self) 52 | { 53 | [self setValue:[[[syntaxTree children][0] number] floatValue]]; 54 | if ([[[syntaxTree children][1] children] count] > 0) 55 | { 56 | [self setUnit:OSPMapCSSUnitFromNSString([[[syntaxTree children][1] children][0] keyword])]; 57 | } 58 | else 59 | { 60 | [self setUnit:OSPMapCSSUnitNone]; 61 | } 62 | } 63 | 64 | return self; 65 | } 66 | 67 | - (id)initWithValue:(NSNumber *)initValue units:(OSPMapCSSUnit)initUnit 68 | { 69 | self = [super init]; 70 | 71 | if (nil != self) 72 | { 73 | [self setValue:[initValue floatValue]]; 74 | [self setUnit:initUnit]; 75 | } 76 | 77 | return self; 78 | } 79 | 80 | - (id)copyWithZone:(NSZone *)zone 81 | { 82 | return [[OSPMapCSSSize allocWithZone:zone] initWithValue:@([self value]) units:[self unit]]; 83 | } 84 | 85 | - (NSString *)description 86 | { 87 | return [NSString stringWithFormat:@"%f %@", [self value], NSStringFromOSPMapCSSUnit([self unit])]; 88 | } 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSObject.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSObject.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSObject.h" 10 | 11 | NSString *NSStringFromOSPMapCSSObjectType(OSPMapCSSObjectType t) 12 | { 13 | switch (t) 14 | { 15 | case OSPMapCSSObjectTypeAll: 16 | return @"*"; 17 | case OSPMapCSSObjectTypeWay: 18 | return @"way"; 19 | case OSPMapCSSObjectTypeArea: 20 | return @"area"; 21 | case OSPMapCSSObjectTypeLine: 22 | return @"line"; 23 | case OSPMapCSSObjectTypeNode: 24 | return @"node"; 25 | case OSPMapCSSObjectTypeCanvas: 26 | return @"canvas"; 27 | case OSPMapCSSObjectTypeMeta: 28 | return @"meta"; 29 | case OSPMapCSSObjectTypeRelation: 30 | return @"relation"; 31 | } 32 | } 33 | 34 | OSPMapCSSObjectType OSPMapCSSObjectTypeFromNSString(NSString *s) 35 | { 36 | if ([s isEqualToString:@"*"]) 37 | { 38 | return OSPMapCSSObjectTypeAll; 39 | } 40 | else if ([s isEqualToString:@"way"]) 41 | { 42 | return OSPMapCSSObjectTypeWay; 43 | } 44 | else if ([s isEqualToString:@"area"]) 45 | { 46 | return OSPMapCSSObjectTypeArea; 47 | } 48 | else if ([s isEqualToString:@"line"]) 49 | { 50 | return OSPMapCSSObjectTypeLine; 51 | } 52 | else if ([s isEqualToString:@"node"]) 53 | { 54 | return OSPMapCSSObjectTypeNode; 55 | } 56 | else if ([s isEqualToString:@"canvas"]) 57 | { 58 | return OSPMapCSSObjectTypeCanvas; 59 | } 60 | else if ([s isEqualToString:@"meta"]) 61 | { 62 | return OSPMapCSSObjectTypeMeta; 63 | } 64 | else 65 | { 66 | return OSPMapCSSObjectTypeRelation; 67 | } 68 | } 69 | 70 | @implementation OSPMapCSSObject 71 | 72 | @synthesize objectType; 73 | 74 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 75 | { 76 | self = [super init]; 77 | 78 | if (nil != self) 79 | { 80 | [self setObjectType:OSPMapCSSObjectTypeFromNSString([[syntaxTree children][0] keyword])]; 81 | } 82 | 83 | return self; 84 | } 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/AbstractMessage.m: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "AbstractMessage.h" 16 | 17 | #import "CodedOutputStream.h" 18 | 19 | @implementation PBAbstractMessage 20 | 21 | - (id) init { 22 | if ((self = [super init])) { 23 | } 24 | 25 | return self; 26 | } 27 | 28 | 29 | - (NSData*) data { 30 | NSMutableData* data = [NSMutableData dataWithLength:self.serializedSize]; 31 | PBCodedOutputStream* stream = [PBCodedOutputStream streamWithData:data]; 32 | [self writeToCodedOutputStream:stream]; 33 | return data; 34 | } 35 | 36 | 37 | - (BOOL) isInitialized { 38 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 39 | } 40 | 41 | 42 | - (int32_t) serializedSize { 43 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 44 | } 45 | 46 | 47 | - (void) writeToCodedOutputStream:(PBCodedOutputStream*) output { 48 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 49 | } 50 | 51 | 52 | - (void) writeToOutputStream:(NSOutputStream*) output { 53 | PBCodedOutputStream* codedOutput = [PBCodedOutputStream streamWithOutputStream:output]; 54 | [self writeToCodedOutputStream:codedOutput]; 55 | [codedOutput flush]; 56 | } 57 | 58 | 59 | - (id) defaultInstance { 60 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 61 | } 62 | 63 | 64 | - (PBUnknownFieldSet*) unknownFields { 65 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 66 | } 67 | 68 | 69 | - (id) builder { 70 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 71 | } 72 | 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPCoordinateRect.h: -------------------------------------------------------------------------------- 1 | // 2 | // OSPCoordinateRect.h 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 13/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef struct 12 | { 13 | double x; 14 | double y; 15 | } OSPCoordinate2D; 16 | 17 | typedef struct 18 | { 19 | OSPCoordinate2D origin; 20 | OSPCoordinate2D size; 21 | } 22 | OSPCoordinateRect; 23 | 24 | typedef struct 25 | { 26 | NSUInteger x; 27 | NSUInteger y; 28 | uint8_t zoom; 29 | } OSPTile; 30 | 31 | OSPCoordinate2D OSPCoordinate2DMake(double x, double y); 32 | OSPCoordinate2D OSPCoordinate2DProjectLocation(CLLocationCoordinate2D l); 33 | CLLocationCoordinate2D OSPCoordinate2DUnproject(OSPCoordinate2D l); 34 | NSString *NSStringFromOSPCoordinate2D(OSPCoordinate2D l); 35 | 36 | extern const OSPCoordinateRect OSPCoordinateRectZero; 37 | 38 | OSPCoordinateRect OSPCoordinateRectMake(double x, double y, double w, double h); 39 | OSPCoordinateRect OSPCoordinateRectUnion(OSPCoordinateRect a, OSPCoordinateRect b); 40 | 41 | double OSPCoordinateRectGetMinLongitude(OSPCoordinateRect r); 42 | double OSPCoordinateRectGetMaxLongitude(OSPCoordinateRect r); 43 | double OSPCoordinateRectGetMinLatitude(OSPCoordinateRect r); 44 | double OSPCoordinateRectGetMaxLatitude(OSPCoordinateRect r); 45 | double OSPCoordinateRectGetWidth(OSPCoordinateRect r); 46 | double OSPCoordinateRectGetHeight(OSPCoordinateRect r); 47 | 48 | double OSPCoordinateRectArea(OSPCoordinateRect r); 49 | 50 | OSPCoordinate2D OSPCoordinateRectGetMinCoord(OSPCoordinateRect r); 51 | OSPCoordinate2D OSPCoordinateRectGetMaxCoord(OSPCoordinateRect r); 52 | 53 | BOOL OSPCoordinateRectContainsRect(OSPCoordinateRect a, OSPCoordinateRect b); 54 | BOOL OSPCoordinateRectIntersectsRect(OSPCoordinateRect a, OSPCoordinateRect b); 55 | 56 | OSPCoordinateRect OSPCoordinateRectOutset(OSPCoordinateRect r, double xOutset, double yOutset); 57 | 58 | NSArray *OSPCoordinateRectSubtract(OSPCoordinateRect a, OSPCoordinateRect b); 59 | 60 | NSArray *NSArrayOfTilesFromCoordinateRect(OSPCoordinateRect r, double maxOverspill); 61 | OSPCoordinateRect OSPCoordinateRectFromTile(OSPTile t); 62 | 63 | NSString *NSStringFromOSPCoordinateRect(OSPCoordinateRect r); 64 | 65 | BOOL OSPTileEqual(OSPTile a, OSPTile b); 66 | 67 | @protocol OSPBounded 68 | 69 | - (OSPCoordinateRect)bounds; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/Message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ForwardDeclarations.h" 16 | 17 | /** 18 | * Abstract interface implemented by Protocol Message objects. 19 | * 20 | * @author Cyrus Najmabadi 21 | */ 22 | @protocol PBMessage 23 | /** 24 | * Get an instance of the type with all fields set to their default values. 25 | * This may or may not be a singleton. This differs from the 26 | * {@code getDefaultInstance()} method of generated message classes in that 27 | * this method is an abstract method of the {@code Message} interface 28 | * whereas {@code getDefaultInstance()} is a static method of a specific 29 | * class. They return the same thing. 30 | */ 31 | - (id) defaultInstance; 32 | 33 | /** 34 | * Get the {@code UnknownFieldSet} 35 | */ 36 | - (PBUnknownFieldSet*) unknownFields; 37 | 38 | /** 39 | * Get the number of bytes required to encode this message. The result 40 | * is only computed on the first call and memoized after that. 41 | */ 42 | - (int32_t) serializedSize; 43 | 44 | /** 45 | * Returns true if all required fields in the message and all embedded 46 | * messages are set, false otherwise. 47 | */ 48 | - (BOOL) isInitialized; 49 | 50 | /** 51 | * Serializes the message and writes it to {@code output}. This does not 52 | * flush or close the stream. 53 | */ 54 | - (void) writeToCodedOutputStream:(PBCodedOutputStream*) output; 55 | - (void) writeToOutputStream:(NSOutputStream*) output; 56 | 57 | /** 58 | * Serializes the message to a {@code ByteString} and returns it. This is 59 | * just a trivial wrapper around 60 | * {@link #writeTo(CodedOutputStream)}. 61 | */ 62 | - (NSData*) data; 63 | 64 | /** 65 | * Constructs a new builder for a message of the same type as this message. 66 | */ 67 | - (id) builder; 68 | @end 69 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/ExtendableMessage.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "GeneratedMessage.h" 16 | 17 | /** 18 | * Generated message classes for message types that contain extension ranges 19 | * subclass this. 20 | * 21 | *

This class implements type-safe accessors for extensions. They 22 | * implement all the same operations that you can do with normal fields -- 23 | * e.g. "has", "get", and "getCount" -- but for extensions. The extensions 24 | * are identified using instances of the class {@link GeneratedExtension}; 25 | * the protocol compiler generates a static instance of this class for every 26 | * extension in its input. Through the magic of generics, all is made 27 | * type-safe. 28 | * 29 | *

For example, imagine you have the {@code .proto} file: 30 | * 31 | *

32 |  * option java_class = "MyProto";
33 |  *
34 |  * message Foo {
35 |  *   extensions 1000 to max;
36 |  * }
37 |  *
38 |  * extend Foo {
39 |  *   optional int32 bar;
40 |  * }
41 |  * 
42 | * 43 | *

Then you might write code like: 44 | * 45 | *

46 |  * MyProto.Foo foo = getFoo();
47 |  * int i = foo.getExtension(MyProto.bar);
48 |  * 
49 | * 50 | *

See also {@link ExtendableBuilder}. 51 | */ 52 | @interface PBExtendableMessage : PBGeneratedMessage { 53 | @private 54 | NSMutableDictionary* extensionMap; 55 | NSMutableDictionary* extensionRegistry; 56 | } 57 | 58 | @property (retain) NSMutableDictionary* extensionMap; 59 | @property (retain) NSMutableDictionary* extensionRegistry; 60 | 61 | - (BOOL) hasExtension:(id) extension; 62 | - (id) getExtension:(id) extension; 63 | 64 | //@protected 65 | - (BOOL) extensionsAreInitialized; 66 | - (int32_t) extensionsSerializedSize; 67 | - (void) writeExtensionsToCodedOutputStream:(PBCodedOutputStream*) output 68 | from:(int32_t) startInclusive 69 | to:(int32_t) endExclusive; 70 | 71 | 72 | 73 | /* @internal */ 74 | - (void) ensureExtensionIsRegistered:(id) extension; 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSStyleSheet.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSStyleSheet.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 05/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSStyleSheet.h" 10 | 11 | #import "OSPMapCSSStyledObject.h" 12 | 13 | #import 14 | 15 | static char styleRef; 16 | static char oldZoomRef; 17 | 18 | @implementation OSPMapCSSStyleSheet 19 | 20 | @synthesize ruleset; 21 | 22 | - (id)initWithRules:(OSPMapCSSRuleset *)initRuleset 23 | { 24 | self = [super init]; 25 | 26 | if (nil != self) 27 | { 28 | [self setRuleset:initRuleset]; 29 | } 30 | 31 | return self; 32 | } 33 | 34 | - (void)deleteMetaAndLoadImportsRelativeToURL:(NSURL *)baseURL 35 | { 36 | [[self ruleset] deleteMetaAndLoadImportsRelativeToURL:baseURL]; 37 | } 38 | 39 | - (NSArray *)styledObjects:(NSSet *)objects atZoom:(float)zoom 40 | { 41 | NSMutableArray *styledObjects = [NSMutableArray arrayWithCapacity:[objects count]]; 42 | dispatch_queue_t addQueue = dispatch_queue_create("styled object access queue", DISPATCH_QUEUE_SERIAL); 43 | [objects enumerateObjectsWithOptions:NSEnumerationConcurrent 44 | usingBlock:^ (OSPAPIObject *object, BOOL *stop) 45 | { 46 | NSNumber *cachedStyleZoom = objc_getAssociatedObject(object, &oldZoomRef); 47 | NSArray *newStyledObjects = nil; 48 | if ([cachedStyleZoom floatValue] == zoom) 49 | { 50 | newStyledObjects = objc_getAssociatedObject(object, &styleRef); 51 | } 52 | if (nil == newStyledObjects) 53 | { 54 | NSDictionary *layerStyles = [[self ruleset] applyToObject:object atZoom:zoom]; 55 | NSMutableArray *sos = [NSMutableArray arrayWithCapacity:[layerStyles count]]; 56 | for (NSString *layerStyle in layerStyles) 57 | { 58 | [sos addObject:[OSPMapCSSStyledObject object:object withStyle:layerStyles[layerStyle]]]; 59 | } 60 | newStyledObjects = [sos copy]; 61 | objc_setAssociatedObject(object, &styleRef, newStyledObjects, OBJC_ASSOCIATION_RETAIN); 62 | objc_setAssociatedObject(object, &oldZoomRef, @(zoom), OBJC_ASSOCIATION_RETAIN); 63 | } 64 | dispatch_sync(addQueue, ^() 65 | { 66 | [styledObjects addObjectsFromArray:newStyledObjects]; 67 | }); 68 | }]; 69 | dispatch_release(addQueue); 70 | return styledObjects; 71 | } 72 | 73 | - (NSDictionary *)styleForCanvasAtZoom:(float)zoom 74 | { 75 | return [[self ruleset] styleForCanvasAtZoom:zoom]; 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/API/OSPMember.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMember.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPMember.h" 10 | 11 | #import "OSPRelation.h" 12 | #import "OSPMap.h" 13 | 14 | @implementation OSPMember 15 | { 16 | OSPMemberType referencedObjectType; 17 | NSInteger referencedObjectId; 18 | __strong OSPAPIObject *referencedObject; 19 | } 20 | 21 | @synthesize role; 22 | @synthesize relation; 23 | 24 | 25 | - (OSPMemberType)referencedObjectType 26 | { 27 | @synchronized(self) 28 | { 29 | return referencedObjectType; 30 | } 31 | } 32 | 33 | - (void)setReferencedObjectType:(OSPMemberType)newReferencedObjectType 34 | { 35 | @synchronized(self) 36 | { 37 | referencedObjectType = newReferencedObjectType; 38 | // referencedObject = [[[self relation] map] apiObjectOfType:referencedObjectType withId:[self referencedObjectId]]; 39 | } 40 | } 41 | 42 | - (NSInteger)referencedObjectId 43 | { 44 | @synchronized(self) 45 | { 46 | return referencedObjectId; 47 | } 48 | } 49 | 50 | - (void)setReferencedObjectId:(NSInteger)newReferencedObjectId 51 | { 52 | @synchronized(self) 53 | { 54 | referencedObjectId = newReferencedObjectId; 55 | 56 | referencedObject = [[[self relation] map] apiObjectOfType:referencedObjectType withId:[self referencedObjectId]]; 57 | } 58 | } 59 | 60 | - (id)init 61 | { 62 | self = [super init]; 63 | 64 | if (nil != self) 65 | { 66 | [self setRole:@""]; 67 | } 68 | 69 | return self; 70 | } 71 | 72 | + (id)memberWithType:(OSPMemberType)memberType referencedObjectId:(NSInteger)referenceId role:(NSString *)role 73 | { 74 | return [[self alloc] initWithType:memberType referencedObjectId:referenceId role:role]; 75 | } 76 | 77 | - (id)initWithType:(OSPMemberType)memberType referencedObjectId:(NSInteger)referenceId role:(NSString *)initRole 78 | { 79 | self = [super init]; 80 | 81 | if (nil != self) 82 | { 83 | [self setReferencedObjectType:memberType]; 84 | [self setReferencedObjectId:referenceId]; 85 | [self setRole:initRole]; 86 | } 87 | 88 | return self; 89 | } 90 | 91 | - (OSPAPIObject *)referencedObject 92 | { 93 | if (nil == referencedObject) 94 | { 95 | referencedObject = [[[self relation] map] apiObjectOfType:referencedObjectType withId:referencedObjectId]; 96 | } 97 | return referencedObject; 98 | } 99 | 100 | - (OSPCoordinateRect)bounds 101 | { 102 | return [referencedObject bounds]; 103 | } 104 | 105 | @end 106 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/ExtendableMessage_Builder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "GeneratedMessage_Builder.h" 16 | 17 | /** 18 | * Generated message builders for message types that contain extension ranges 19 | * subclass this. 20 | * 21 | *

This class implements type-safe accessors for extensions. They 22 | * implement all the same operations that you can do with normal fields -- 23 | * e.g. "get", "set", and "add" -- but for extensions. The extensions are 24 | * identified using instances of the class {@link GeneratedExtension}; the 25 | * protocol compiler generates a static instance of this class for every 26 | * extension in its input. Through the magic of generics, all is made 27 | * type-safe. 28 | * 29 | *

For example, imagine you have the {@code .proto} file: 30 | * 31 | *

32 |  * option java_class = "MyProto";
33 |  *
34 |  * message Foo {
35 |  *   extensions 1000 to max;
36 |  * }
37 |  *
38 |  * extend Foo {
39 |  *   optional int32 bar;
40 |  * }
41 |  * 
42 | * 43 | *

Then you might write code like: 44 | * 45 | *

46 |  * MyProto.Foo foo =
47 |  *   MyProto.Foo.newBuilder()
48 |  *     .setExtension(MyProto.bar, 123)
49 |  *     .build();
50 |  * 
51 | * 52 | *

See also {@link ExtendableMessage}. 53 | */ 54 | @interface PBExtendableMessage_Builder : PBGeneratedMessage_Builder { 55 | } 56 | 57 | - (id) getExtension:(id) extension; 58 | - (BOOL) hasExtension:(id) extension; 59 | - (PBExtendableMessage_Builder*) setExtension:(id) extension 60 | value:(id) value; 61 | - (PBExtendableMessage_Builder*) addExtension:(id) extension 62 | value:(id) value; 63 | - (PBExtendableMessage_Builder*) setExtension:(id) extension 64 | index:(int32_t) index 65 | value:(id) value; 66 | - (PBExtendableMessage_Builder*) clearExtension:(id) extension; 67 | 68 | /* @protected */ 69 | - (void) mergeExtensionFields:(PBExtendableMessage*) other; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPOpenStreetMapPBFFile.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPOpenStreetMapPBFFile.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 21/04/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPOpenStreetMapPBFFile.h" 10 | 11 | #import "OSPOpenStreetMapPBFParser.h" 12 | 13 | #import "OSPMap.h" 14 | 15 | @interface OSPOpenStreetMapPBFFile () 16 | 17 | @property (readwrite, strong) id cache; 18 | @property (readwrite, strong) OSPOpenStreetMapPBFParser *parser; 19 | 20 | @end 21 | 22 | @implementation OSPOpenStreetMapPBFFile 23 | 24 | @synthesize path; 25 | 26 | @synthesize parser; 27 | @synthesize cache; 28 | 29 | + (id)osmFileWithPath:(NSString *)path 30 | { 31 | return [[OSPOpenStreetMapPBFFile alloc] initWithPath:path]; 32 | } 33 | 34 | - (id)initWithPath:(NSString *)initPath 35 | { 36 | self = [super init]; 37 | 38 | if (nil != self) 39 | { 40 | [self setPath:initPath]; 41 | [self setCache:[[OSPMap alloc] init]]; 42 | } 43 | 44 | return self; 45 | } 46 | 47 | - (NSSet *)objectsInBounds:(OSPCoordinateRect)bounds 48 | { 49 | return [[self cache] objectsInBounds:bounds]; 50 | } 51 | 52 | - (NSSet *)allObjects 53 | { 54 | return [[self cache] allObjects]; 55 | } 56 | 57 | - (void)loadObjectsInBounds:(OSPCoordinateRect)bounds withOutset:(double)outsetSize 58 | { 59 | static dispatch_once_t onceToken; 60 | dispatch_once(&onceToken, ^() 61 | { 62 | NSInputStream *stream = [NSInputStream inputStreamWithFileAtPath:[self path]]; 63 | [self setParser:[[OSPOpenStreetMapPBFParser alloc] initWithStream:stream]]; 64 | [[self parser] setDelegate:self]; 65 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^() 66 | { 67 | [[self parser] parse]; 68 | }); 69 | }); 70 | } 71 | 72 | - (void)parser:(OSPOpenStreetMapPBFParser *)parser didFindAPIObject:(OSPAPIObject *)object 73 | { 74 | if ([[self cache] isKindOfClass:[OSPMap class]]) 75 | { 76 | [object setMap:(OSPMap *)[self cache]]; 77 | } 78 | [[self cache] addObject:object]; 79 | } 80 | 81 | - (void)parser:(OSPOpenStreetMapPBFParser *)parser didFailWithError:(NSError *)error 82 | { 83 | } 84 | 85 | - (void)parserDidEndDocument:(OSPOpenStreetMapPBFParser *)parser 86 | { 87 | [[self delegate] dataSource:self didLoadObjectsInArea:OSPCoordinateRectMake(0.0, 0.0, 1.0, 1.0)]; 88 | } 89 | 90 | - (void)addObject:(id)apiObject 91 | { 92 | [[self cache] addObject:apiObject]; 93 | } 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /OpenStreetPad/OSPAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // OpenStreetPadAppDelegate.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPAppDelegate.h" 10 | 11 | #import "OSPMainViewController.h" 12 | 13 | #import "OSPMapCSSParser.h" 14 | 15 | @implementation OSPAppDelegate 16 | 17 | @synthesize window; 18 | @synthesize viewController; 19 | 20 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 21 | { 22 | [self setWindow:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]]; 23 | // Override point for customization after application launch. 24 | [self setViewController:[[OSPMainViewController alloc] initWithNibName:@"OSPMainViewController" bundle:nil]]; 25 | [[self window] setRootViewController:[self viewController]]; 26 | [[self window] makeKeyAndVisible]; 27 | 28 | return YES; 29 | } 30 | 31 | - (void)applicationWillResignActive:(UIApplication *)application 32 | { 33 | /* 34 | Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 35 | Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 36 | */ 37 | } 38 | 39 | - (void)applicationDidEnterBackground:(UIApplication *)application 40 | { 41 | /* 42 | Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 43 | If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 44 | */ 45 | } 46 | 47 | - (void)applicationWillEnterForeground:(UIApplication *)application 48 | { 49 | /* 50 | Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 51 | */ 52 | } 53 | 54 | - (void)applicationDidBecomeActive:(UIApplication *)application 55 | { 56 | /* 57 | Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 58 | */ 59 | } 60 | 61 | - (void)applicationWillTerminate:(UIApplication *)application 62 | { 63 | /* 64 | Called when the application is about to terminate. 65 | Save data if appropriate. 66 | See also applicationDidEnterBackground:. 67 | */ 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /OpenStreetPad/osm.mcs: -------------------------------------------------------------------------------- 1 | meta 2 | { 3 | title: "A quick and dirty rip off of OSM.org's mapnik style"; 4 | } 5 | 6 | node 7 | { 8 | exit; 9 | } 10 | 11 | canvas 12 | { 13 | fill-color: cornsilk; 14 | } 15 | 16 | way 17 | { 18 | linecap: round; 19 | linejoin: round; 20 | casing-linecap: round; 21 | casing-linejoin: round; 22 | } 23 | 24 | area|z16-20["building"] 25 | { 26 | z-index: 20; 27 | width: 1 pt; 28 | color: rgb(0.74, 0.68, 0.68); 29 | // fill-color: blue; 30 | fill-color: rgba(0.84, 0.68, 0.68, 0.68); 31 | text: tag('name'); 32 | font-family: Helvetica; 33 | font-size: 14pt; 34 | text-color: black; 35 | text-halo-radius: 2pt; 36 | text-halo-color: white; 37 | } 38 | 39 | area[building] 40 | { 41 | exit; 42 | } 43 | 44 | @import url("highways.mcs") highways 45 | @import url("landuse.mcs") landuse 46 | 47 | way["railway"="rail"] 48 | { 49 | width: 2pt; 50 | casing-width: 1pt; 51 | casing-color: grey; 52 | color: white; 53 | linecap: none; 54 | linejoin: round; 55 | dashes: 8, 8; 56 | casing-dashes: off; 57 | exit; 58 | } 59 | 60 | way[boundary="administrative"] 61 | { 62 | width: 2pt; 63 | color: rgba(0.5, 0.15, 0.7, 0.5); 64 | dashes: 8, 6; 65 | casing-color: rgba(0.5, 0.15, 0.7, 0.3); 66 | casing-width: 4pt; 67 | exit; 68 | } 69 | 70 | area[amenity] 71 | { 72 | z-index: -3; 73 | 74 | area[amenity="parking"] 75 | { 76 | fill-color: rgb(0.97, 0.93, 0.71); 77 | icon-image: url("icons/parking.png"); 78 | } 79 | 80 | area[amenity="school"], 81 | area[amenity="college"] 82 | { 83 | width:1 pt; 84 | color: rgb(0.82, 0.67, 0.64); 85 | fill-color: rgb(0.94, 0.94, 0.85); 86 | 87 | text: tag('name'); 88 | font-family: Helvetica; 89 | font-size: 14pt; 90 | text-color: black; 91 | text-halo-radius: 2pt; 92 | text-halo-color: white; 93 | } 94 | } 95 | 96 | area[leisure] 97 | { 98 | z-index: -4; 99 | } 100 | 101 | area[leisure="common"] 102 | { 103 | fill-color: rgb(0.82, 0.92, 0.65); 104 | } 105 | 106 | area[leisure="park"] 107 | { 108 | fill-color: rgb(0.82, 0.96, 0.79); 109 | } 110 | 111 | way[barrier] 112 | { 113 | width: 0.5pt; 114 | color: black; 115 | } 116 | 117 | way[barrier="hedge"] 118 | { 119 | width: 3pt; 120 | color: rgb(0.69, 0.81, 0.62); 121 | } 122 | 123 | area[power="sub_station"] 124 | { 125 | width: 1pt; 126 | color: rgb(0.54, 0.54, 0.54); 127 | fill-color: rgb(0.74, 0.74, 0.74); 128 | } 129 | 130 | way[waterway] 131 | { 132 | color: rgb(0.72, 0.82, 0.82); 133 | width: 1pt; 134 | } 135 | 136 | way[waterway="river"], 137 | way[waterway="canal"] 138 | { 139 | width: 3pt; 140 | } 141 | 142 | area[waterway="riverbank"] 143 | { 144 | fill-color: rgb(0.72, 0.82, 0.82); 145 | } 146 | 147 | way[natural="coastline"] 148 | { 149 | width: 3pt; 150 | color: rgb(0.72, 0.82, 0.82); 151 | // fill-color: rgb(0.72, 0.82, 0.82); 152 | } 153 | 154 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/GeneratedMessage_Builder.m: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "GeneratedMessage_Builder.h" 16 | 17 | #import "GeneratedMessage.h" 18 | #import "Message.h" 19 | #import "Message_Builder.h" 20 | #import "UnknownFieldSet.h" 21 | #import "UnknownFieldSet_Builder.h" 22 | 23 | 24 | @interface PBGeneratedMessage () 25 | @property (retain) PBUnknownFieldSet* unknownFields; 26 | @end 27 | 28 | 29 | @implementation PBGeneratedMessage_Builder 30 | 31 | /** 32 | * Get the message being built. We don't just pass this to the 33 | * constructor because it becomes null when build() is called. 34 | */ 35 | - (PBGeneratedMessage*) internalGetResult { 36 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 37 | } 38 | 39 | 40 | - (void) checkInitialized { 41 | PBGeneratedMessage* result = self.internalGetResult; 42 | if (result != nil && !result.isInitialized) { 43 | @throw [NSException exceptionWithName:@"UninitializedMessage" reason:@"" userInfo:nil]; 44 | } 45 | } 46 | 47 | 48 | - (PBUnknownFieldSet*) unknownFields { 49 | return self.internalGetResult.unknownFields; 50 | } 51 | 52 | 53 | - (id) setUnknownFields:(PBUnknownFieldSet*) unknownFields { 54 | self.internalGetResult.unknownFields = unknownFields; 55 | return self; 56 | } 57 | 58 | 59 | - (id) mergeUnknownFields:(PBUnknownFieldSet*) unknownFields { 60 | PBGeneratedMessage* result = self.internalGetResult; 61 | result.unknownFields = 62 | [[[PBUnknownFieldSet builderWithUnknownFields:result.unknownFields] 63 | mergeUnknownFields:unknownFields] build]; 64 | return self; 65 | } 66 | 67 | 68 | - (BOOL) isInitialized { 69 | return self.internalGetResult.isInitialized; 70 | } 71 | 72 | 73 | /** 74 | * Called by subclasses to parse an unknown field. 75 | * @return {@code YES} unless the tag is an end-group tag. 76 | */ 77 | - (BOOL) parseUnknownField:(PBCodedInputStream*) input 78 | unknownFields:(PBUnknownFieldSet_Builder*) unknownFields 79 | extensionRegistry:(PBExtensionRegistry*) extensionRegistry 80 | tag:(int32_t) tag { 81 | return [unknownFields mergeFieldFrom:tag input:input]; 82 | } 83 | 84 | 85 | - (void) checkInitializedParsed { 86 | PBGeneratedMessage* result = self.internalGetResult; 87 | if (result != nil && !result.isInitialized) { 88 | @throw [NSException exceptionWithName:@"InvalidProtocolBuffer" reason:@"" userInfo:nil]; 89 | } 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/OSPOpenStreetMapXMLFile.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPOpenStreetMapXMLFile.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 28/02/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPOpenStreetMapXMLFile.h" 10 | 11 | #import "OSPOpenStreetMapXMLParser.h" 12 | #import "OSPOpenStreetMapXMLWriter.h" 13 | 14 | #import "OSPMap.h" 15 | 16 | @interface OSPOpenStreetMapXMLFile () 17 | 18 | @property (readwrite, strong) id cache; 19 | @property (readwrite, strong) OSPOpenStreetMapXMLParser *parser; 20 | 21 | @end 22 | 23 | @implementation OSPOpenStreetMapXMLFile 24 | 25 | @synthesize path; 26 | 27 | @synthesize parser; 28 | @synthesize cache; 29 | 30 | + (id)osmFileWithPath:(NSString *)path 31 | { 32 | return [[OSPOpenStreetMapXMLFile alloc] initWithPath:path]; 33 | } 34 | 35 | - (id)initWithPath:(NSString *)initPath 36 | { 37 | self = [super init]; 38 | 39 | if (nil != self) 40 | { 41 | [self setPath:initPath]; 42 | [self setCache:[[OSPMap alloc] init]]; 43 | } 44 | 45 | return self; 46 | } 47 | 48 | - (NSSet *)objectsInBounds:(OSPCoordinateRect)bounds 49 | { 50 | return [[self cache] objectsInBounds:bounds]; 51 | } 52 | 53 | - (NSSet *)allObjects 54 | { 55 | return [[self cache] allObjects]; 56 | } 57 | 58 | - (void)loadObjectsInBounds:(OSPCoordinateRect)bounds withOutset:(double)outsetSize 59 | { 60 | static dispatch_once_t onceToken; 61 | dispatch_once(&onceToken, ^() 62 | { 63 | NSInputStream *stream = [NSInputStream inputStreamWithFileAtPath:[self path]]; 64 | [self setParser:[[OSPOpenStreetMapXMLParser alloc] initWithStream:stream]]; 65 | [[self parser] setDelegate:self]; 66 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^() 67 | { 68 | [[self parser] parse]; 69 | }); 70 | }); 71 | } 72 | 73 | - (void)parser:(OSPOpenStreetMapXMLParser *)parser didFindAPIObject:(OSPAPIObject *)object 74 | { 75 | if ([[self cache] isKindOfClass:[OSPMap class]]) 76 | { 77 | [object setMap:(OSPMap *)[self cache]]; 78 | } 79 | [[self cache] addObject:object]; 80 | } 81 | 82 | - (void)parser:(OSPOpenStreetMapXMLParser *)parser didFailWithError:(NSError *)error 83 | { 84 | } 85 | 86 | - (void)parserDidEndDocument:(OSPOpenStreetMapXMLParser *)parser 87 | { 88 | [[self delegate] dataSource:self didLoadObjectsInArea:OSPCoordinateRectMake(0.0, 0.0, 1.0, 1.0)]; 89 | } 90 | 91 | - (void)addObject:(id)apiObject 92 | { 93 | [[self cache] addObject:apiObject]; 94 | } 95 | 96 | - (void)save 97 | { 98 | [[NSFileManager defaultManager] createFileAtPath:[self path] contents:[NSData data] attributes:nil]; 99 | NSOutputStream *oStream = [NSOutputStream outputStreamToFileAtPath:[self path] append:NO]; 100 | [oStream open]; 101 | OSPOpenStreetMapXMLWriter *writer = [[OSPOpenStreetMapXMLWriter alloc] initWithStream:oStream]; 102 | [writer writeDataProvider:[self cache]]; 103 | [oStream close]; 104 | } 105 | 106 | @end 107 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/API/OSPAPIObject.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPApiObject.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPAPIObject.h" 10 | 11 | #import "OSPMap.h" 12 | 13 | @implementation OSPAPIObject 14 | { 15 | __strong NSMutableDictionary *tags; 16 | __strong NSMutableSet *parents; 17 | } 18 | 19 | @synthesize identity; 20 | @synthesize version; 21 | @synthesize changesetId; 22 | @synthesize user; 23 | @synthesize userId; 24 | @synthesize visible; 25 | @synthesize timestamp; 26 | 27 | @synthesize map; 28 | 29 | - (NSDictionary *)tags 30 | { 31 | return tags; 32 | } 33 | 34 | - (void)setTags:(NSDictionary *)newTags 35 | { 36 | tags = [newTags mutableCopy]; 37 | } 38 | 39 | - (NSSet *)parents 40 | { 41 | return parents; 42 | } 43 | 44 | - (void)setParents:(NSSet *)newParents 45 | { 46 | parents = [newParents mutableCopy]; 47 | } 48 | 49 | - (id)initUnsafely 50 | { 51 | return [super init]; 52 | } 53 | 54 | - (id)init 55 | { 56 | self = [super init]; 57 | 58 | if (nil != self) 59 | { 60 | [self setUser:@""]; 61 | [self setTimestamp:[NSDate date]]; 62 | [self setTags:@{}]; 63 | [self setParents:[NSSet set]]; 64 | } 65 | 66 | return self; 67 | } 68 | 69 | - (OSPMemberType)memberType 70 | { 71 | [NSException raise:@"Abstract method exception" format:@"-memberType is an abstract method, you must call it on one of the subclasses of OSPAPIObject"]; 72 | return OSPMemberTypeNone; 73 | } 74 | 75 | - (OSPCoordinateRect)bounds 76 | { 77 | [NSException raise:@"Abstract method exception" format:@"-bounds is an abstract method, you must call it on one of the subclasses of OSPMapObject or OSPAPIObject"]; 78 | return OSPCoordinateRectZero; 79 | } 80 | 81 | - (BOOL)isEqual:(id)object 82 | { 83 | if ([object isKindOfClass:[OSPAPIObject class]]) 84 | { 85 | OSPAPIObject *o = (OSPAPIObject *)object; 86 | return identity == [o identity] && [o memberType] == [self memberType]; 87 | } 88 | 89 | return NO; 90 | } 91 | 92 | - (BOOL)isEqualToAPIObject:(OSPAPIObject *)object 93 | { 94 | return identity == [object identity] && [object memberType] == [self memberType]; 95 | } 96 | 97 | - (NSUInteger)hash 98 | { 99 | return [self identity] << 2 + [self memberType]; 100 | } 101 | 102 | - (NSSet *)childObjects 103 | { 104 | return [NSSet set]; 105 | } 106 | 107 | - (void)addParent:(OSPAPIObjectReference *)newParent 108 | { 109 | [parents addObject:newParent]; 110 | } 111 | 112 | - (id)valueForTag:(NSString *)tagName 113 | { 114 | if ([tagName isEqualToString:@":tagged"]) 115 | { 116 | return [tags count] > 0 ? @"yes" : @"no"; 117 | } 118 | return tags[tagName]; 119 | } 120 | 121 | @end 122 | 123 | NSString *NSStringFromOSPMemberType(OSPMemberType t) 124 | { 125 | switch (t) 126 | { 127 | case OSPMemberTypeNode: return @"node"; 128 | case OSPMemberTypeWay: return @"way"; 129 | case OSPMemberTypeRelation: return @"relation"; 130 | case OSPMemberTypeNone: return @""; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSSelector.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSSelector.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 01/04/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSSelector.h" 10 | 11 | #import "OSPMapCSSSubselector.h" 12 | 13 | #import "OSPAPIObjectReference.h" 14 | 15 | BOOL subSelectorsMatchObjectAtZoom(NSArray *subSelectors, NSInteger lastIndex, OSPAPIObject *object, float zoom); 16 | 17 | BOOL subSelectorsMatchObjectAtZoom(NSArray *subSelectors, NSInteger lastIndex, OSPAPIObject *object, float zoom) 18 | { 19 | if (lastIndex == 0) 20 | { 21 | return [subSelectors[0] matchesObject:object atZoom:zoom]; 22 | } 23 | 24 | if (![subSelectors[lastIndex] matchesObject:object atZoom:zoom]) 25 | { 26 | return NO; 27 | } 28 | 29 | OSPMap *m = [object map]; 30 | for (OSPAPIObjectReference *parent in [object parents]) 31 | { 32 | if (subSelectorsMatchObjectAtZoom(subSelectors, lastIndex - 1, [m apiObjectOfType:[parent memberType] withId:[parent identity]], zoom)) 33 | { 34 | return YES; 35 | } 36 | } 37 | 38 | return NO; 39 | } 40 | 41 | @implementation OSPMapCSSSelector 42 | 43 | @synthesize subselectors; 44 | @synthesize layerIdentifier; 45 | 46 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 47 | { 48 | self = [super init]; 49 | 50 | if (nil != self) 51 | { 52 | NSArray *subSelectors = [syntaxTree children][0]; 53 | NSMutableArray *realSubselectors = [NSMutableArray arrayWithCapacity:[subSelectors count]]; 54 | for (NSArray *a in subSelectors) 55 | { 56 | [realSubselectors addObject:a[0]]; 57 | } 58 | [self setSubselectors:realSubselectors]; 59 | NSArray *maybeLayerIdentifier = [syntaxTree children][1]; 60 | if ([maybeLayerIdentifier count] > 0) 61 | { 62 | id identifier = [maybeLayerIdentifier[0] children][1]; 63 | [self setLayerIdentifier:[identifier isKindOfClass:[CPKeywordToken class]] ? @"*": [identifier identifier]]; 64 | } 65 | else 66 | { 67 | [self setLayerIdentifier:@"default"]; 68 | } 69 | } 70 | 71 | return self; 72 | } 73 | 74 | - (BOOL)matchesObject:(OSPAPIObject *)object atZoom:(float)zoom 75 | { 76 | return subSelectorsMatchObjectAtZoom(subselectors, [subselectors count] - 1, object, zoom); 77 | } 78 | 79 | - (NSString *)description 80 | { 81 | NSMutableString *desc = [NSMutableString string]; 82 | 83 | NSUInteger subSelectorNumber = 0; 84 | for (OSPMapCSSSubselector *subSelector in [self subselectors]) 85 | { 86 | if (subSelectorNumber < [[self subselectors] count] - 1) 87 | { 88 | [desc appendFormat:@"%@ ", subSelector]; 89 | } 90 | else 91 | { 92 | [desc appendString:[subSelector description]]; 93 | } 94 | subSelectorNumber++; 95 | } 96 | 97 | if (nil != [self layerIdentifier]) 98 | { 99 | [desc appendFormat:@"::%@", [self layerIdentifier]]; 100 | } 101 | 102 | return desc; 103 | } 104 | 105 | @end 106 | -------------------------------------------------------------------------------- /OpenStreetPad/Cocoa Extensions/NSData+ZipCompression.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+ZipCompression.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 21/04/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "NSData+ZipCompression.h" 10 | 11 | #import 12 | 13 | @implementation NSData (ZipCompression) 14 | 15 | - (NSData *)dataByDecompressingZip 16 | { 17 | if ([self length] == 0) 18 | { 19 | return self; 20 | } 21 | 22 | NSUInteger fullLength = [self length]; 23 | NSUInteger halfLength = fullLength / 2; 24 | 25 | NSMutableData *decompressed = [NSMutableData dataWithLength:fullLength + halfLength]; 26 | BOOL done = NO; 27 | int status; 28 | 29 | z_stream stream; 30 | stream.next_in = (Bytef *)[self bytes]; 31 | stream.avail_in = (uint)[self length]; 32 | stream.total_out = 0; 33 | stream.zalloc = Z_NULL; 34 | stream.zfree = Z_NULL; 35 | 36 | if (inflateInit(&stream) != Z_OK) 37 | { 38 | return nil; 39 | } 40 | 41 | while (!done) 42 | { 43 | // Make sure we have enough room and reset the lengths. 44 | if (stream.total_out >= [decompressed length]) 45 | { 46 | [decompressed increaseLengthBy:halfLength]; 47 | } 48 | stream.next_out = [decompressed mutableBytes] + stream.total_out; 49 | stream.avail_out = (uint)([decompressed length] - stream.total_out); 50 | 51 | // Inflate another chunk. 52 | status = inflate(&stream, Z_SYNC_FLUSH); 53 | if (status == Z_STREAM_END) 54 | { 55 | done = YES; 56 | } 57 | else if (status != Z_OK) 58 | { 59 | break; 60 | } 61 | } 62 | if (inflateEnd(&stream) != Z_OK) 63 | { 64 | return nil; 65 | } 66 | 67 | // Set real length. 68 | if (done) 69 | { 70 | [decompressed setLength:stream.total_out]; 71 | return [NSData dataWithData:decompressed]; 72 | } 73 | else 74 | { 75 | return nil; 76 | } 77 | } 78 | 79 | - (NSData *)dataByCompressingZip 80 | { 81 | if ([self length] == 0) 82 | { 83 | return self; 84 | } 85 | 86 | z_stream stream; 87 | 88 | stream.zalloc = Z_NULL; 89 | stream.zfree = Z_NULL; 90 | stream.opaque = Z_NULL; 91 | stream.total_out = 0; 92 | stream.next_in = (Bytef *)[self bytes]; 93 | stream.avail_in = (uint)[self length]; 94 | 95 | // Compresssion Levels: 96 | // Z_NO_COMPRESSION 97 | // Z_BEST_SPEED 98 | // Z_BEST_COMPRESSION 99 | // Z_DEFAULT_COMPRESSION 100 | 101 | if (deflateInit(&stream, Z_DEFAULT_COMPRESSION) != Z_OK) 102 | { 103 | return nil; 104 | } 105 | 106 | NSMutableData *compressed = [NSMutableData dataWithLength:16384]; // 16K chuncks for expansion 107 | do 108 | { 109 | if (stream.total_out >= [compressed length]) 110 | { 111 | [compressed increaseLengthBy:16384]; 112 | } 113 | 114 | stream.next_out = [compressed mutableBytes] + stream.total_out; 115 | stream.avail_out = (uint)([compressed length] - stream.total_out); 116 | 117 | deflate(&stream, Z_FINISH); 118 | } 119 | while (stream.avail_out == 0); 120 | 121 | deflateEnd(&stream); 122 | 123 | [compressed setLength:stream.total_out]; 124 | return [NSData dataWithData:compressed]; 125 | } 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /OSPParserGenerator/OSPParserGenerator.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 05/11/2011 \" DATE 7 | .Dt OSPParserGenerator 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm OSPParserGenerator, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/ExtensionRegistry.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ForwardDeclarations.h" 16 | 17 | /** 18 | * A table of known extensions, searchable by name or field number. When 19 | * parsing a protocol message that might have extensions, you must provide 20 | * an {@code ExtensionRegistry} in which you have registered any extensions 21 | * that you want to be able to parse. Otherwise, those extensions will just 22 | * be treated like unknown fields. 23 | * 24 | *

For example, if you had the {@code .proto} file: 25 | * 26 | *

27 |  * option java_class = "MyProto";
28 |  *
29 |  * message Foo {
30 |  *   extensions 1000 to max;
31 |  * }
32 |  *
33 |  * extend Foo {
34 |  *   optional int32 bar;
35 |  * }
36 |  * 
37 | * 38 | * Then you might write code like: 39 | * 40 | *
41 |  * ExtensionRegistry registry = ExtensionRegistry.newInstance();
42 |  * registry.add(MyProto.bar);
43 |  * MyProto.Foo message = MyProto.Foo.parseFrom(input, registry);
44 |  * 
45 | * 46 | *

Background: 47 | * 48 | *

You might wonder why this is necessary. Two alternatives might come to 49 | * mind. First, you might imagine a system where generated extensions are 50 | * automatically registered when their containing classes are loaded. This 51 | * is a popular technique, but is bad design; among other things, it creates a 52 | * situation where behavior can change depending on what classes happen to be 53 | * loaded. It also introduces a security vulnerability, because an 54 | * unprivileged class could cause its code to be called unexpectedly from a 55 | * privileged class by registering itself as an extension of the right type. 56 | * 57 | *

Another option you might consider is lazy parsing: do not parse an 58 | * extension until it is first requested, at which point the caller must 59 | * provide a type to use. This introduces a different set of problems. First, 60 | * it would require a mutex lock any time an extension was accessed, which 61 | * would be slow. Second, corrupt data would not be detected until first 62 | * access, at which point it would be much harder to deal with it. Third, it 63 | * could violate the expectation that message objects are immutable, since the 64 | * type provided could be any arbitrary message class. An unpriviledged user 65 | * could take advantage of this to inject a mutable object into a message 66 | * belonging to priviledged code and create mischief. 67 | * 68 | * @author Cyrus Najmabadi 69 | */ 70 | @interface PBExtensionRegistry : NSObject { 71 | @protected 72 | NSDictionary* classMap; 73 | } 74 | 75 | + (PBExtensionRegistry*) emptyRegistry; 76 | - (id) getExtension:(Class) clazz fieldNumber:(NSInteger) fieldNumber; 77 | 78 | /* @protected */ 79 | - (id) initWithClassMap:(NSDictionary*) classMap; 80 | - (id) keyForClass:(Class) clazz; 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/ExtendableMessage.m: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "ExtendableMessage.h" 16 | 17 | #import "ExtensionField.h" 18 | 19 | @implementation PBExtendableMessage 20 | 21 | @synthesize extensionMap; 22 | @synthesize extensionRegistry; 23 | 24 | - (void) dealloc { 25 | self.extensionMap = nil; 26 | self.extensionRegistry = nil; 27 | [super dealloc]; 28 | } 29 | 30 | 31 | - (BOOL) isInitialized:(id) object { 32 | if ([object isKindOfClass:[NSArray class]]) { 33 | for (id child in object) { 34 | if (![self isInitialized:child]) { 35 | return NO; 36 | } 37 | } 38 | } else if ([object conformsToProtocol:@protocol(PBMessage)]) { 39 | return [object isInitialized]; 40 | } 41 | 42 | return YES; 43 | } 44 | 45 | 46 | - (BOOL) extensionsAreInitialized { 47 | return [self isInitialized:extensionMap.allValues]; 48 | } 49 | 50 | 51 | - (id) getExtension:(id) extension { 52 | [self ensureExtensionIsRegistered:extension]; 53 | id value = [extensionMap objectForKey:[NSNumber numberWithInt:[extension fieldNumber]]]; 54 | if (value != nil) { 55 | return value; 56 | } 57 | 58 | return [extension defaultValue]; 59 | } 60 | 61 | 62 | - (void) ensureExtensionIsRegistered:(id) extension { 63 | if ([extension extendedClass] != [self class]) { 64 | @throw [NSException exceptionWithName:@"IllegalArgument" reason:@"Trying to use an extension for another type" userInfo:nil]; 65 | } 66 | 67 | if (extensionRegistry == nil) { 68 | self.extensionRegistry = [NSMutableDictionary dictionary]; 69 | } 70 | [extensionRegistry setObject:extension 71 | forKey:[NSNumber numberWithInt:[extension fieldNumber]]]; 72 | } 73 | 74 | 75 | - (BOOL) hasExtension:(id) extension { 76 | return nil != [extensionMap objectForKey:[NSNumber numberWithInt:[extension fieldNumber]]]; 77 | } 78 | 79 | 80 | - (void) writeExtensionsToCodedOutputStream:(PBCodedOutputStream*) output 81 | from:(int32_t) startInclusive 82 | to:(int32_t) endExclusive { 83 | // man, i really wish Cocoa had a Sorted/TreeMap 84 | NSArray* sortedKeys = [extensionMap.allKeys sortedArrayUsingSelector:@selector(compare:)]; 85 | for (NSNumber* number in sortedKeys) { 86 | int32_t fieldNumber = [number intValue]; 87 | if (fieldNumber >= startInclusive && fieldNumber < endExclusive) { 88 | id extension = [extensionRegistry objectForKey:number]; 89 | id value = [extensionMap objectForKey:number]; 90 | [extension writeValue:value includingTagToCodedOutputStream:output]; 91 | } 92 | } 93 | } 94 | 95 | 96 | - (int32_t) extensionsSerializedSize { 97 | int32_t size = 0; 98 | for (NSNumber* number in extensionMap) { 99 | id extension = [extensionRegistry objectForKey:number]; 100 | id value = [extensionMap objectForKey:number]; 101 | size += [extension computeSerializedSizeIncludingTag:value]; 102 | } 103 | 104 | return size; 105 | } 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /OpenStreetPad/OSPMapCSSHashColourRecogniser.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMapCSSHashColourRecogniser.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 20/11/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSHashColourRecogniser.h" 10 | 11 | #import "OSPMapCSSHashColourToken.h" 12 | 13 | @interface OSPMapCSSHashColourRecogniser () 14 | 15 | - (BOOL)interpretHex:(NSString *)hex into:(uint8_t *)c; 16 | - (BOOL)interpetHexChar:(char)h into:(uint8_t *)v; 17 | 18 | @end 19 | 20 | @implementation OSPMapCSSHashColourRecogniser 21 | 22 | + (id)hashColourRecogniser 23 | { 24 | return [[self alloc] init]; 25 | } 26 | 27 | - (id)initWithCoder:(NSCoder *)aDecoder 28 | { 29 | return [self init]; 30 | } 31 | 32 | - (void)encodeWithCoder:(NSCoder *)aCoder 33 | { 34 | 35 | } 36 | 37 | - (CPToken *)recogniseTokenInString:(NSString *)tokenString currentTokenPosition:(NSUInteger *)tokenPosition 38 | { 39 | NSUInteger remainingChars = [tokenString length] - *tokenPosition; 40 | if ([[tokenString substringWithRange:NSMakeRange(*tokenPosition, 1)] isEqualToString:@"#"]) 41 | { 42 | uint8_t red; 43 | uint8_t green; 44 | uint8_t blue; 45 | 46 | if (remainingChars >= 7) 47 | { 48 | NSString *redChars = [tokenString substringWithRange:NSMakeRange(*tokenPosition + 1, 2)]; 49 | NSString *greenChars = [tokenString substringWithRange:NSMakeRange(*tokenPosition + 3, 2)]; 50 | NSString *blueChars = [tokenString substringWithRange:NSMakeRange(*tokenPosition + 5, 2)]; 51 | BOOL isValid = [self interpretHex:redChars into:&red]; 52 | isValid &= [self interpretHex:greenChars into:&green]; 53 | isValid &= [self interpretHex:blueChars into:&blue]; 54 | if (isValid) 55 | { 56 | *tokenPosition += 7; 57 | return [OSPMapCSSHashColourToken tokenWithRed:red green:green blue:blue]; 58 | } 59 | } 60 | 61 | if (remainingChars >= 4) 62 | { 63 | const char redChar = [[tokenString substringWithRange:NSMakeRange(*tokenPosition + 1, 1)] cStringUsingEncoding:NSASCIIStringEncoding][0]; 64 | const char greenChar = [[tokenString substringWithRange:NSMakeRange(*tokenPosition + 2, 1)] cStringUsingEncoding:NSASCIIStringEncoding][0]; 65 | const char blueChar = [[tokenString substringWithRange:NSMakeRange(*tokenPosition + 3, 1)] cStringUsingEncoding:NSASCIIStringEncoding][0]; 66 | BOOL isValid = [self interpetHexChar:redChar into:&red]; 67 | isValid &= [self interpetHexChar:greenChar into:&red]; 68 | isValid &= [self interpetHexChar:blueChar into:&blue]; 69 | if (isValid) 70 | { 71 | *tokenPosition += 4; 72 | return [OSPMapCSSHashColourToken tokenWithRed:red * 16 green:green * 16 blue:blue * 16]; 73 | } 74 | } 75 | } 76 | 77 | return nil; 78 | } 79 | 80 | - (BOOL)interpretHex:(NSString *)hex into:(uint8_t *)c 81 | { 82 | uint8_t f = 0; 83 | uint8_t s = 0; 84 | const char *cs = [hex cStringUsingEncoding:NSASCIIStringEncoding]; 85 | BOOL isValid = [self interpetHexChar:cs[0] into:&f]; 86 | isValid &= [self interpetHexChar:cs[1] into:&s]; 87 | if (isValid) 88 | { 89 | *c = f * 16 + s; 90 | } 91 | return isValid; 92 | } 93 | 94 | - (BOOL)interpetHexChar:(char)h into:(uint8_t *)v 95 | { 96 | if (h >= '0' && h <= '9') 97 | { 98 | *v = (h - '0'); 99 | } 100 | else if (h >= 'a' && h <= 'f') 101 | { 102 | *v = (h - 'a' + 10); 103 | } 104 | else if (h >= 'A' && h <= 'F') 105 | { 106 | *v += (h - 'A' + 10); 107 | } 108 | else 109 | { 110 | return NO; 111 | } 112 | return YES; 113 | } 114 | 115 | @end 116 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/NSString+XMLEscaping.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+XMLEscaping.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 04/03/2012. 6 | // Copyright (c) 2012 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "NSString+XMLEscaping.h" 10 | 11 | @implementation NSString (XMLEscaping) 12 | 13 | - (id)stringByAddingXMLEscaping 14 | { 15 | NSUInteger len = [self length]; 16 | NSMutableString *newString = [NSMutableString stringWithCapacity:len]; 17 | unichar chars[255]; 18 | NSUInteger consumedLength = 0; 19 | NSUInteger characterIndexAfterLastEscapedChar = 0; 20 | NSUInteger numberOfUnescapedChars = 0; 21 | 22 | do 23 | { 24 | char charsToConsume = len < consumedLength + 255 ? len - consumedLength : 255; 25 | [self getCharacters:chars range:NSMakeRange(consumedLength, charsToConsume)]; 26 | 27 | for (char charNum = 0; charNum < charsToConsume; charNum++) 28 | { 29 | unichar c = chars[charNum]; 30 | if (c <= 0xd7ff) 31 | { 32 | if (c >= 0x20 || c == '\n' || c == '\r' || c == '\t') 33 | { 34 | switch (c) 35 | { 36 | case '"': 37 | [newString appendString:[self substringWithRange:NSMakeRange(characterIndexAfterLastEscapedChar, numberOfUnescapedChars)]]; 38 | [newString appendString:@"""]; 39 | characterIndexAfterLastEscapedChar = consumedLength + charNum + 1; 40 | numberOfUnescapedChars = 0; 41 | break; 42 | case '<': 43 | [newString appendString:[self substringWithRange:NSMakeRange(characterIndexAfterLastEscapedChar, numberOfUnescapedChars)]]; 44 | [newString appendString:@"<"]; 45 | characterIndexAfterLastEscapedChar = consumedLength + charNum + 1; 46 | numberOfUnescapedChars = 0; 47 | break; 48 | case '>': 49 | [newString appendString:[self substringWithRange:NSMakeRange(characterIndexAfterLastEscapedChar, numberOfUnescapedChars)]]; 50 | [newString appendString:@">"]; 51 | characterIndexAfterLastEscapedChar = consumedLength + charNum + 1; 52 | numberOfUnescapedChars = 0; 53 | break; 54 | case '&': 55 | [newString appendString:[self substringWithRange:NSMakeRange(characterIndexAfterLastEscapedChar, numberOfUnescapedChars)]]; 56 | [newString appendString:@"&"]; 57 | characterIndexAfterLastEscapedChar = consumedLength + charNum + 1; 58 | numberOfUnescapedChars = 0; 59 | break; 60 | default: 61 | numberOfUnescapedChars++; 62 | break; 63 | } 64 | } 65 | } 66 | else if (c < 0xe000 || c > 0xfffd) 67 | { 68 | [newString appendString:[self substringWithRange:NSMakeRange(characterIndexAfterLastEscapedChar, numberOfUnescapedChars)]]; 69 | characterIndexAfterLastEscapedChar = consumedLength + charNum + 1; 70 | numberOfUnescapedChars = 0; 71 | } 72 | else 73 | { 74 | numberOfUnescapedChars++; 75 | } 76 | } 77 | consumedLength += charsToConsume; 78 | } 79 | while (consumedLength < len); 80 | 81 | [newString appendString:[self substringWithRange:NSMakeRange(characterIndexAfterLastEscapedChar, numberOfUnescapedChars)]]; 82 | 83 | return [newString copy]; 84 | } 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/OSPMap.m: -------------------------------------------------------------------------------- 1 | // 2 | // OSPMap.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 06/08/2011. 6 | // Copyright 2011 Thomas Davie All rights reserved. 7 | // 8 | 9 | #import "OSPMap.h" 10 | 11 | #import "OSPAPIObjectReference.h" 12 | 13 | #import "OSPQuadTree.h" 14 | 15 | @interface OSPMap () 16 | 17 | @property (readwrite, strong) CFMutableSetRef __attribute__((NSObject)) contents; 18 | @property (readwrite, strong) OSPQuadTree *tree; 19 | @property (readwrite, strong) NSRecursiveLock *readLock; 20 | 21 | - (OSPAPIObject *)apiObjectMatchingReference:(OSPAPIObjectReference *)ref; 22 | 23 | @end 24 | 25 | Boolean APIObjectEqual (const void *value1, const void *value2); 26 | 27 | Boolean APIObjectEqual (const void *value1, const void *value2) 28 | { 29 | return [(__bridge OSPAPIObject *)value1 isEqualToAPIObject:(__bridge OSPAPIObject *)value2]; 30 | } 31 | 32 | @implementation OSPMap 33 | 34 | @synthesize contents; 35 | @synthesize tree; 36 | @synthesize readLock; 37 | 38 | - (id)init 39 | { 40 | self = [super init]; 41 | 42 | if (nil != self) 43 | { 44 | CFSetCallBacks callbacks = kCFTypeSetCallBacks; 45 | callbacks.equal = APIObjectEqual; 46 | CFMutableSetRef s = CFSetCreateMutable(NULL, 0, &callbacks); 47 | [self setContents:s]; 48 | CFRelease(s); 49 | 50 | [self setReadLock:[[NSRecursiveLock alloc] init]]; 51 | 52 | [self setTree:[[OSPQuadTree alloc] initWithBounds:OSPCoordinateRectMake(0.0, 0.0, 1.0, 1.0)]]; 53 | } 54 | 55 | return self; 56 | } 57 | 58 | - (void)addObject:(OSPAPIObject *)apiObject 59 | { 60 | [[self readLock] lock]; 61 | CFSetAddValue([self contents], (__bridge const void *)apiObject); 62 | [[self readLock] unlock]; 63 | 64 | [[self tree] addObject:apiObject]; 65 | } 66 | 67 | - (NSSet *)objectsInBounds:(OSPCoordinateRect)searchBounds 68 | { 69 | return [[self tree] objectsInBounds:searchBounds]; 70 | } 71 | 72 | - (OSPNode *)nodeWithId:(NSInteger)nodeId 73 | { 74 | return (OSPNode *)[self apiObjectOfType:OSPMemberTypeNode withId:nodeId]; 75 | } 76 | 77 | - (OSPWay *)wayWithId:(NSInteger)wayId 78 | { 79 | return (OSPWay *)[self apiObjectOfType:OSPMemberTypeWay withId:wayId]; 80 | } 81 | 82 | - (OSPRelation *)relationWithId:(NSInteger)relationId 83 | { 84 | return (OSPRelation *)[self apiObjectOfType:OSPMemberTypeRelation withId:relationId]; 85 | } 86 | 87 | - (OSPAPIObject *)apiObjectOfType:(OSPMemberType)type withId:(NSInteger)objectId 88 | { 89 | return [self apiObjectMatchingReference:[OSPAPIObjectReference apiObjectReferenceWithType:type identity:objectId]]; 90 | } 91 | 92 | - (OSPAPIObject *)apiObjectMatchingReference:(OSPAPIObjectReference *)ref 93 | { 94 | [[self readLock] lock]; 95 | OSPAPIObject *o = (__bridge OSPAPIObject *)CFSetGetValue([self contents], (__bridge const void *)ref); 96 | [[self readLock] unlock]; 97 | return o; 98 | } 99 | 100 | - (NSSet *)allObjects 101 | { 102 | return [(__bridge NSSet *)[self contents] copy]; 103 | } 104 | 105 | - (OSPCoordinateRect)bounds 106 | { 107 | CFSetRef c = [self contents]; 108 | if (CFSetGetCount(c) > 0) 109 | { 110 | OSPCoordinateRect b; 111 | for (OSPAPIObject *obj in (__bridge NSSet *)c) 112 | { 113 | if ([obj memberType] == OSPMemberTypeNode) 114 | { 115 | CLLocationCoordinate2D l = [(OSPNode *)obj location]; 116 | b = OSPCoordinateRectMake(l.longitude, l.latitude, 0.0, 0.0); 117 | break; 118 | } 119 | } 120 | for (OSPAPIObject *obj in (__bridge NSSet *)c) 121 | { 122 | if ([obj memberType] == OSPMemberTypeNode) 123 | { 124 | CLLocationCoordinate2D l = [(OSPNode *)obj location]; 125 | b = OSPCoordinateRectUnion(b, OSPCoordinateRectMake(l.longitude, l.latitude, 0.0, 0.0)); 126 | } 127 | } 128 | return b; 129 | } 130 | 131 | return OSPCoordinateRectMake(0.0, 0.0, 0.0, 0.0); 132 | } 133 | 134 | @end 135 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/MutableField.m: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "MutableField.h" 16 | 17 | #import "Field.h" 18 | 19 | @interface PBField () 20 | @property (retain) NSMutableArray* mutableVarintList; 21 | @property (retain) NSMutableArray* mutableFixed32List; 22 | @property (retain) NSMutableArray* mutableFixed64List; 23 | @property (retain) NSMutableArray* mutableLengthDelimitedList; 24 | @property (retain) NSMutableArray* mutableGroupList; 25 | @end 26 | 27 | 28 | @implementation PBMutableField 29 | 30 | - (void) dealloc { 31 | [super dealloc]; 32 | } 33 | 34 | 35 | + (PBMutableField*) field { 36 | return [[[PBMutableField alloc] init] autorelease]; 37 | } 38 | 39 | 40 | - (id) init { 41 | if ((self = [super init])) { 42 | } 43 | 44 | return self; 45 | } 46 | 47 | 48 | - (PBMutableField*) clear { 49 | self.mutableVarintList = nil; 50 | self.mutableFixed32List = nil; 51 | self.mutableFixed64List = nil; 52 | self.mutableLengthDelimitedList = nil; 53 | self.mutableGroupList = nil; 54 | return self; 55 | } 56 | 57 | 58 | - (PBMutableField*) mergeFromField:(PBField*) other { 59 | if (other.varintList.count > 0) { 60 | if (mutableVarintList == nil) { 61 | self.mutableVarintList = [NSMutableArray array]; 62 | } 63 | [mutableVarintList addObjectsFromArray:other.varintList]; 64 | } 65 | 66 | if (other.fixed32List.count > 0) { 67 | if (mutableFixed32List == nil) { 68 | self.mutableFixed32List = [NSMutableArray array]; 69 | } 70 | [mutableFixed32List addObjectsFromArray:other.fixed32List]; 71 | } 72 | 73 | if (other.fixed64List.count > 0) { 74 | if (mutableFixed64List == nil) { 75 | self.mutableFixed64List = [NSMutableArray array]; 76 | } 77 | [mutableFixed64List addObjectsFromArray:other.fixed64List]; 78 | } 79 | 80 | if (other.lengthDelimitedList.count > 0) { 81 | if (mutableLengthDelimitedList == nil) { 82 | self.mutableLengthDelimitedList = [NSMutableArray array]; 83 | } 84 | [mutableLengthDelimitedList addObjectsFromArray:other.lengthDelimitedList]; 85 | } 86 | 87 | if (other.groupList.count > 0) { 88 | if (mutableGroupList == nil) { 89 | self.mutableGroupList = [NSMutableArray array]; 90 | } 91 | [mutableGroupList addObjectsFromArray:other.groupList]; 92 | } 93 | 94 | return self; 95 | } 96 | 97 | 98 | - (PBMutableField*) addVarint:(int64_t) value { 99 | if (mutableVarintList == nil) { 100 | self.mutableVarintList = [NSMutableArray array]; 101 | } 102 | [mutableVarintList addObject:[NSNumber numberWithLongLong:value]]; 103 | return self; 104 | } 105 | 106 | 107 | - (PBMutableField*) addFixed32:(int32_t) value { 108 | if (mutableFixed32List == nil) { 109 | self.mutableFixed32List = [NSMutableArray array]; 110 | } 111 | [mutableFixed32List addObject:[NSNumber numberWithInt:value]]; 112 | return self; 113 | } 114 | 115 | 116 | - (PBMutableField*) addFixed64:(int64_t) value { 117 | if (mutableFixed64List == nil) { 118 | self.mutableFixed64List = [NSMutableArray array]; 119 | } 120 | [mutableFixed64List addObject:[NSNumber numberWithLongLong:value]]; 121 | return self; 122 | } 123 | 124 | 125 | - (PBMutableField*) addLengthDelimited:(NSData*) value { 126 | if (mutableLengthDelimitedList == nil) { 127 | self.mutableLengthDelimitedList = [NSMutableArray array]; 128 | } 129 | [mutableLengthDelimitedList addObject:value]; 130 | return self; 131 | } 132 | 133 | 134 | - (PBMutableField*) addGroup:(PBUnknownFieldSet*) value { 135 | if (mutableGroupList == nil) { 136 | self.mutableGroupList = [NSMutableArray array]; 137 | } 138 | [mutableGroupList addObject:value]; 139 | return self; 140 | } 141 | 142 | @end 143 | -------------------------------------------------------------------------------- /OpenStreetPad/DataSources/Protocol Buffers/AbstractMessage_Builder.m: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Cyrus Najmabadi 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #import "AbstractMessage_Builder.h" 16 | 17 | #import "CodedInputStream.h" 18 | #import "ExtensionRegistry.h" 19 | #import "UnknownFieldSet.h" 20 | #import "UnknownFieldSet_Builder.h" 21 | 22 | 23 | @implementation PBAbstractMessage_Builder 24 | 25 | - (id) clone { 26 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 27 | } 28 | 29 | 30 | - (id) clear { 31 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 32 | } 33 | 34 | 35 | - (id) mergeFromCodedInputStream:(PBCodedInputStream*) input { 36 | return [self mergeFromCodedInputStream:input extensionRegistry:[PBExtensionRegistry emptyRegistry]]; 37 | } 38 | 39 | 40 | - (id) mergeFromCodedInputStream:(PBCodedInputStream*) input 41 | extensionRegistry:(PBExtensionRegistry*) extensionRegistry { 42 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 43 | } 44 | 45 | 46 | - (id) mergeUnknownFields:(PBUnknownFieldSet*) unknownFields { 47 | PBUnknownFieldSet* merged = 48 | [[[PBUnknownFieldSet builderWithUnknownFields:self.unknownFields] 49 | mergeUnknownFields:unknownFields] build]; 50 | 51 | [self setUnknownFields:merged]; 52 | return self; 53 | } 54 | 55 | 56 | - (id) mergeFromData:(NSData*) data { 57 | PBCodedInputStream* input = [PBCodedInputStream streamWithData:data]; 58 | [self mergeFromCodedInputStream:input]; 59 | [input checkLastTagWas:0]; 60 | return self; 61 | } 62 | 63 | 64 | - (id) mergeFromData:(NSData*) data 65 | extensionRegistry:(PBExtensionRegistry*) extensionRegistry { 66 | PBCodedInputStream* input = [PBCodedInputStream streamWithData:data]; 67 | [self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry]; 68 | [input checkLastTagWas:0]; 69 | return self; 70 | } 71 | 72 | 73 | - (id) mergeFromInputStream:(NSInputStream*) input { 74 | PBCodedInputStream* codedInput = [PBCodedInputStream streamWithInputStream:input]; 75 | [self mergeFromCodedInputStream:codedInput]; 76 | [codedInput checkLastTagWas:0]; 77 | return self; 78 | } 79 | 80 | 81 | - (id) mergeFromInputStream:(NSInputStream*) input 82 | extensionRegistry:(PBExtensionRegistry*) extensionRegistry { 83 | PBCodedInputStream* codedInput = [PBCodedInputStream streamWithInputStream:input]; 84 | [self mergeFromCodedInputStream:codedInput extensionRegistry:extensionRegistry]; 85 | [codedInput checkLastTagWas:0]; 86 | return self; 87 | } 88 | 89 | 90 | - (id) build { 91 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 92 | } 93 | 94 | 95 | - (id) buildPartial { 96 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 97 | } 98 | 99 | 100 | - (BOOL) isInitialized { 101 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 102 | } 103 | 104 | 105 | - (id) defaultInstance { 106 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 107 | } 108 | 109 | 110 | - (PBUnknownFieldSet*) unknownFields { 111 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 112 | } 113 | 114 | 115 | - (id) setUnknownFields:(PBUnknownFieldSet*) unknownFields { 116 | @throw [NSException exceptionWithName:@"ImproperSubclassing" reason:@"" userInfo:nil]; 117 | } 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /OpenStreetPad/Model/MapCSS/OSPMapCSSBinaryTest.m: -------------------------------------------------------------------------------- 1 | // 2 | // BinaryTest.m 3 | // OpenStreetPad 4 | // 5 | // Created by Thomas Davie on 31/10/2011. 6 | // Copyright (c) 2011 Thomas Davie. All rights reserved. 7 | // 8 | 9 | #import "OSPMapCSSBinaryTest.h" 10 | 11 | OSPMapCSSBinaryOperator OSPMapCSSBinaryOperatorFromNSString(NSString *s) 12 | { 13 | if ([s isEqualToString:@"="]) 14 | { 15 | return OSPMapCSSBinaryOperatorEquals; 16 | } 17 | else if ([s isEqualToString:@"=~"]) 18 | { 19 | return OSPMapCSSBinaryOperatorMatches; 20 | } 21 | else if ([s isEqualToString:@"!="]) 22 | { 23 | return OSPMapCSSBinaryOperatorNotEquals; 24 | } 25 | else if ([s isEqualToString:@"<"]) 26 | { 27 | return OSPMapCSSBinaryOperatorLessThan; 28 | } 29 | else if ([s isEqualToString:@">"]) 30 | { 31 | return OSPMapCSSBinaryOperatorGreaterThan; 32 | } 33 | else if ([s isEqualToString:@"<="]) 34 | { 35 | return OSPMapCSSBinaryOperatorLessThanOrEqual; 36 | } 37 | else 38 | { 39 | return OSPMapCSSBinaryOperatorGreaterThanOrEqual; 40 | } 41 | } 42 | 43 | NSString *NSStringFromOSPMapCSSBinaryOperator(OSPMapCSSBinaryOperator o) 44 | { 45 | switch (o) { 46 | case OSPMapCSSBinaryOperatorEquals: 47 | return @"="; 48 | case OSPMapCSSBinaryOperatorMatches: 49 | return @"=~"; 50 | case OSPMapCSSBinaryOperatorLessThan: 51 | return @"<"; 52 | case OSPMapCSSBinaryOperatorNotEquals: 53 | return @"!="; 54 | case OSPMapCSSBinaryOperatorGreaterThan: 55 | return @">"; 56 | case OSPMapCSSBinaryOperatorLessThanOrEqual: 57 | return @"<="; 58 | case OSPMapCSSBinaryOperatorGreaterThanOrEqual: 59 | return @">="; 60 | } 61 | } 62 | 63 | @implementation OSPMapCSSBinaryTest 64 | 65 | @synthesize tagName; 66 | @synthesize operator; 67 | @synthesize value; 68 | 69 | - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree 70 | { 71 | self = [super initWithSyntaxTree:syntaxTree]; 72 | 73 | if (nil != self) 74 | { 75 | [self setTagName:[[syntaxTree children][0] description]]; 76 | [self setOperator:OSPMapCSSBinaryOperatorFromNSString([[[syntaxTree children][1] children][0] keyword])]; 77 | CPToken *t = [[syntaxTree children][2] children][0]; 78 | if ([t isKindOfClass:[CPIdentifierToken class]]) 79 | { 80 | [self setValue:[(CPIdentifierToken *)t identifier]]; 81 | } 82 | else if ([t isKindOfClass:[CPNumberToken class]]) 83 | { 84 | [self setValue:[NSString stringWithFormat:@"%@", [(CPNumberToken *)t number]]]; 85 | } 86 | else 87 | { 88 | [self setValue:[(CPQuotedToken *)t content]]; 89 | } 90 | } 91 | 92 | return self; 93 | } 94 | 95 | - (NSString *)description 96 | { 97 | return [NSString stringWithFormat:@"[%@ %@ \"%@\"]", [self tagName], NSStringFromOSPMapCSSBinaryOperator([self operator]), [self value]]; 98 | } 99 | 100 | - (BOOL)matchesObject:(OSPAPIObject *)object 101 | { 102 | NSString *objectValue = [object valueForTag:tagName]; 103 | switch ([self operator]) 104 | { 105 | case OSPMapCSSBinaryOperatorEquals: 106 | return [objectValue isEqualToString:value]; 107 | case OSPMapCSSBinaryOperatorNotEquals: 108 | return ![objectValue isEqualToString:value]; 109 | case OSPMapCSSBinaryOperatorMatches: 110 | { 111 | NSError *err = nil; 112 | NSRegularExpression *e = [NSRegularExpression regularExpressionWithPattern:value options:0 error:&err]; 113 | return [e numberOfMatchesInString:objectValue options:NSMatchingAnchored range:NSMakeRange(0, [objectValue length])] > 0; 114 | } 115 | case OSPMapCSSBinaryOperatorLessThan: 116 | return [objectValue floatValue] < [value floatValue]; 117 | case OSPMapCSSBinaryOperatorGreaterThan: 118 | return [objectValue floatValue] > [value floatValue]; 119 | case OSPMapCSSBinaryOperatorLessThanOrEqual: 120 | return [objectValue floatValue] <= [value floatValue]; 121 | case OSPMapCSSBinaryOperatorGreaterThanOrEqual: 122 | return [objectValue floatValue] >= [value floatValue]; 123 | } 124 | } 125 | 126 | @end 127 | --------------------------------------------------------------------------------