Oolite
Loading...
Searching...
No Matches
OOPListSchemaVerifier.m File Reference
import "OOPListSchemaVerifier.h"
import "OOCollectionExtractors.h"
import "OOLoggingExtended.h"
import "OOMaths.h"
#include <limits.h>
Include dependency graph for OOPListSchemaVerifier.m:

Go to the source code of this file.

Classes

struct  BackLinkChain
category  OOPListSchemaVerifier(OOPrivate)
category  NSString(OOPListSchemaVerifierHelpers)

Macros

#define PLIST_VERIFIER_DEBUG_DUMP_ENABLED   1
#define DebugDumpIndent()
#define DebugDumpOutdent()
#define DebugDumpPushIndent()
#define DebugDumpPopIndent()
#define DebugDump(...)
#define VERIFY_PROTO(T)
#define VERIFY_CASE(T)
#define REQUIRE_TYPE(CLASSNAME, NAMESTRING)

Typedefs

typedef struct BackLinkChain BackLinkChain

Enumerations

enum  { kMaximumLengthForStringInErrorMessage = 100 }
enum  { kStartOfPrivateErrorCodes = kPListErrorLastErrorCode , kPListErrorFailedAndErrorHasBeenReported }
enum  SchemaType {
  kTypeUnknown , kTypeString , kTypeArray , kTypeDictionary ,
  kTypeInteger , kTypePositiveInteger , kTypeFloat , kTypePositiveFloat ,
  kTypeOneOf , kTypeEnumeration , kTypeBoolean , kTypeFuzzyBoolean ,
  kTypeVector , kTypeQuaternion , kTypeDelegatedType
}

Functions

OOINLINE BackLinkChain BackLink (BackLinkChain *link, id element)
OOINLINE BackLinkChain BackLinkIndex (BackLinkChain *link, NSUInteger index)
OOINLINE BackLinkChain BackLinkRoot (void)
static SchemaType StringToSchemaType (NSString *string, NSError **outError)
static NSString * ApplyStringFilter (NSString *string, id filterSpec, BackLinkChain keyPath, NSError **outError)
static BOOL ApplyStringTest (NSString *string, id test, SEL testSelector, NSString *testDescription, BackLinkChain keyPath, NSError **outError)
static NSArray * KeyPathToArray (BackLinkChain keyPath)
static NSString * KeyPathToString (BackLinkChain keyPath)
static NSString * StringForErrorReport (NSString *string)
static NSString * ArrayForErrorReport (NSArray *array)
static NSString * SetForErrorReport (NSSet *set)
static NSString * StringOrArrayForErrorReport (id value, NSString *arrayPrefix)
static NSError * Error (OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSString *format,...)
static NSError * ErrorWithProperty (OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSString *propKey, id propValue, NSString *format,...)
static NSError * ErrorWithDictionary (OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSDictionary *dict, NSString *format,...)
static NSError * ErrorWithDictionaryAndArguments (OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSDictionary *dict, NSString *format, va_list arguments)
static NSError * ErrorTypeMismatch (Class expectedClass, NSString *expectedClassName, id actualObject, BackLinkChain keyPath)
static NSError * ErrorFailureAlreadyReported (void)
static BOOL IsFailureAlreadyReportedError (NSError *error)
 VERIFY_PROTO (String)
 VERIFY_PROTO (Array)
 VERIFY_PROTO (Dictionary)
 VERIFY_PROTO (Integer)
 VERIFY_PROTO (PositiveInteger)
 VERIFY_PROTO (Float)
 VERIFY_PROTO (PositiveFloat)
 VERIFY_PROTO (OneOf)
 VERIFY_PROTO (Enumeration)
 VERIFY_PROTO (Boolean)
 VERIFY_PROTO (FuzzyBoolean)
 VERIFY_PROTO (Vector)
 VERIFY_PROTO (Quaternion)
 VERIFY_PROTO (DelegatedType)
static NSError * Verify_String (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_Array (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_Dictionary (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_Integer (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_PositiveInteger (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_Float (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_PositiveFloat (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_OneOf (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_Enumeration (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_Boolean (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_FuzzyBoolean (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_Vector (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_Quaternion (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)
static NSError * Verify_DelegatedType (OOPListSchemaVerifier *verifier, id value, NSDictionary *params, id rootPList, NSString *name, BackLinkChain keyPath, BOOL tentative, BOOL *outStop)

Variables

static BOOL sDebugDump = NO
NSString *const kOOPListSchemaVerifierErrorDomain = @"org.aegidian.oolite.OOPListSchemaVerifier.ErrorDomain"
NSString *const kPListKeyPathErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier plist key path"
NSString *const kSchemaKeyPathErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier schema key path"
NSString *const kExpectedClassErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier expected class"
NSString *const kExpectedClassNameErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier expected class name"
NSString *const kUnknownKeyErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier unknown key"
NSString *const kMissingRequiredKeysErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier missing required keys"
NSString *const kMissingSubStringErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier missing substring"
NSString *const kUnnownFilterErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier unknown filter"
NSString *const kErrorsByOptionErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier errors by option"
NSString *const kUnknownTypeErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier unknown type"
NSString *const kUndefinedMacroErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier undefined macro"

Macro Definition Documentation

◆ DebugDump

#define DebugDump ( ...)
Value:
do { \
if (sDebugDump) \
OOLog(@"verifyOXP.verbose.plistDebugDump", __VA_ARGS__); \
} while (0)
static BOOL sDebugDump

Definition at line 74 of file OOPListSchemaVerifier.m.

74#define DebugDump(...) \
75 do { \
76 if (sDebugDump) \
77 OOLog(@"verifyOXP.verbose.plistDebugDump", __VA_ARGS__); \
78 } while (0)

Referenced by Verify_Array(), Verify_Boolean(), Verify_DelegatedType(), Verify_Dictionary(), Verify_Enumeration(), Verify_Float(), Verify_FuzzyBoolean(), Verify_Integer(), Verify_OneOf(), Verify_PositiveFloat(), Verify_PositiveInteger(), Verify_Quaternion(), Verify_String(), and Verify_Vector().

◆ DebugDumpIndent

#define DebugDumpIndent ( )
Value:
do { \
if (sDebugDump) \
OOLogIndent(); \
} while (0)

Definition at line 54 of file OOPListSchemaVerifier.m.

54#define DebugDumpIndent() \
55 do { \
56 if (sDebugDump) \
57 OOLogIndent(); \
58 } while (0)

Referenced by Verify_Dictionary(), and OOPListSchemaVerifier(OOPrivate)::verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:.

◆ DebugDumpOutdent

#define DebugDumpOutdent ( )
Value:
do { \
if (sDebugDump) \
OOLogOutdent(); \
} while (0)

Definition at line 59 of file OOPListSchemaVerifier.m.

59#define DebugDumpOutdent() \
60 do { \
61 if (sDebugDump) \
62 OOLogOutdent(); \
63 } while (0)

Referenced by Verify_Dictionary().

◆ DebugDumpPopIndent

#define DebugDumpPopIndent ( )
Value:
do { \
if (sDebugDump) \
OOLogPopIndent(); \
} while (0)

Definition at line 69 of file OOPListSchemaVerifier.m.

69#define DebugDumpPopIndent() \
70 do { \
71 if (sDebugDump) \
72 OOLogPopIndent(); \
73 } while (0)

Referenced by OOPListSchemaVerifier(OOPrivate)::verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:.

◆ DebugDumpPushIndent

#define DebugDumpPushIndent ( )
Value:
do { \
if (sDebugDump) \
OOLogPushIndent(); \
} while (0)

Definition at line 64 of file OOPListSchemaVerifier.m.

64#define DebugDumpPushIndent() \
65 do { \
66 if (sDebugDump) \
67 OOLogPushIndent(); \
68 } while (0)

Referenced by OOPListSchemaVerifier(OOPrivate)::verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:.

◆ PLIST_VERIFIER_DEBUG_DUMP_ENABLED

#define PLIST_VERIFIER_DEBUG_DUMP_ENABLED   1

Definition at line 37 of file OOPListSchemaVerifier.m.

◆ REQUIRE_TYPE

#define REQUIRE_TYPE ( CLASSNAME,
NAMESTRING )
Value:
do { \
if (![value isKindOfClass:[CLASSNAME class]]) { \
return ErrorTypeMismatch([CLASSNAME class], NAMESTRING, value, keyPath); \
} \
} while (0)
static NSError * ErrorTypeMismatch(Class expectedClass, NSString *expectedClassName, id actualObject, BackLinkChain keyPath)

Definition at line 757 of file OOPListSchemaVerifier.m.

757#define REQUIRE_TYPE(CLASSNAME, NAMESTRING) \
758 do { \
759 if (![value isKindOfClass:[CLASSNAME class]]) { \
760 return ErrorTypeMismatch([CLASSNAME class], NAMESTRING, value, keyPath); \
761 } \
762 } while (0)

Referenced by Verify_Array(), Verify_Dictionary(), Verify_Enumeration(), and Verify_String().

◆ VERIFY_CASE

#define VERIFY_CASE ( T)
Value:
case kType##T: \
error = Verify_##T(self, subProperty, resolvedSpecifier, rootPList, name, keyPath, tentative, outStop); \
break;

Referenced by OOPListSchemaVerifier(OOPrivate)::verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:.

◆ VERIFY_PROTO

#define VERIFY_PROTO ( T)
Value:
static NSError* Verify_##T(OOPListSchemaVerifier* verifier, id value, NSDictionary* params, id rootPList, NSString* name, BackLinkChain keyPath, BOOL tentative, BOOL* outStop)

Definition at line 211 of file OOPListSchemaVerifier.m.

Typedef Documentation

◆ BackLinkChain

typedef struct BackLinkChain BackLinkChain

Definition at line 131 of file OOPListSchemaVerifier.m.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kStartOfPrivateErrorCodes 
kPListErrorFailedAndErrorHasBeenReported 

Definition at line 45 of file OOPListSchemaVerifier.m.

◆ anonymous enum

anonymous enum
Enumerator
kMaximumLengthForStringInErrorMessage 

Definition at line 39 of file OOPListSchemaVerifier.m.

39 {
40 // Largest allowable number of characters for string included in error message.
42};
@ kMaximumLengthForStringInErrorMessage

◆ SchemaType

enum SchemaType
Enumerator
kTypeUnknown 
kTypeString 
kTypeArray 
kTypeDictionary 
kTypeInteger 
kTypePositiveInteger 
kTypeFloat 
kTypePositiveFloat 
kTypeOneOf 
kTypeEnumeration 
kTypeBoolean 
kTypeFuzzyBoolean 
kTypeVector 
kTypeQuaternion 
kTypeDelegatedType 

Definition at line 113 of file OOPListSchemaVerifier.m.

Function Documentation

◆ ApplyStringFilter()

NSString * ApplyStringFilter ( NSString * string,
id filterSpec,
BackLinkChain keyPath,
NSError ** outError )
static

Definition at line 562 of file OOPListSchemaVerifier.m.

563{
564 NSEnumerator* filterEnum = nil;
565 id filter = nil;
566 NSRange range;
567
568 assert(outError != NULL);
569
570 if (filterSpec == nil)
571 return string;
572
573 if ([filterSpec isKindOfClass:[NSString class]]) {
574 filterSpec = [NSArray arrayWithObject:filterSpec];
575 }
576 if ([filterSpec isKindOfClass:[NSArray class]]) {
577 for (filterEnum = [filterSpec objectEnumerator]; (filter = [filterEnum nextObject]);) {
578 if ([filter isKindOfClass:[NSString class]]) {
579 if ([filter isEqual:@"lowerCase"])
580 string = [string lowercaseString];
581 else if ([filter isEqual:@"upperCase"])
582 string = [string uppercaseString];
583 else if ([filter isEqual:@"capitalized"])
584 string = [string capitalizedString];
585 else if ([filter hasPrefix:@"truncFront:"]) {
586 string = [string substringToIndex:[[filter substringFromIndex:11] intValue]];
587 } else if ([filter hasPrefix:@"truncBack:"]) {
588 string = [string substringToIndex:[[filter substringFromIndex:10] intValue]];
589 } else if ([filter hasPrefix:@"subStringTo:"]) {
590 range = [string rangeOfString:[filter substringFromIndex:12]];
591 if (range.location != NSNotFound) {
592 string = [string substringToIndex:range.location];
593 }
594 } else if ([filter hasPrefix:@"subStringFrom:"]) {
595 range = [string rangeOfString:[filter substringFromIndex:14]];
596 if (range.location != NSNotFound) {
597 string = [string substringFromIndex:range.location + range.length];
598 }
599 } else if ([filter hasPrefix:@"subStringToInclusive:"]) {
600 range = [string rangeOfString:[filter substringFromIndex:21]];
601 if (range.location != NSNotFound) {
602 string = [string substringToIndex:range.location + range.length];
603 }
604 } else if ([filter hasPrefix:@"subStringFromInclusive:"]) {
605 range = [string rangeOfString:[filter substringFromIndex:23]];
606 if (range.location != NSNotFound) {
607 string = [string substringFromIndex:range.location];
608 }
609 } else {
610 *outError = ErrorWithProperty(kPListErrorSchemaUnknownFilter, &keyPath, kUnnownFilterErrorKey, filter, @"Bad schema: unknown string filter specifier \"%@\".", filter);
611 }
612 } else {
613 *outError = Error(kPListErrorSchemaUnknownFilter, &keyPath, @"Bad schema: filter specifier is not a string.");
614 }
615 }
616 } else {
617 *outError = Error(kPListErrorSchemaUnknownFilter, &keyPath, @"Bad schema: \"filter\" must be a string or an array.");
618 }
619
620 return string;
621}
@ kPListErrorSchemaUnknownFilter
NSString *const kUnnownFilterErrorKey
static NSError * Error(OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSString *format,...)
static NSError * ErrorWithProperty(OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSString *propKey, id propValue, NSString *format,...)
return nil

References Error(), ErrorWithProperty(), kPListErrorSchemaUnknownFilter, kUnnownFilterErrorKey, and nil.

Referenced by Verify_Enumeration(), and Verify_String().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ApplyStringTest()

BOOL ApplyStringTest ( NSString * string,
id test,
SEL testSelector,
NSString * testDescription,
BackLinkChain keyPath,
NSError ** outError )
static

Definition at line 623 of file OOPListSchemaVerifier.m.

624{
625 BOOL (*testIMP)(id, SEL, NSString*);
626 NSEnumerator* testEnum = nil;
627 id subTest = nil;
628
629 assert(outError != NULL);
630
631 if (test == nil)
632 return YES;
633
634 testIMP = (BOOL (*)(id, SEL, NSString*))[string methodForSelector:testSelector];
635 if (testIMP == NULL) {
636 *outError = Error(kPListErrorInternal, &keyPath, @"OOPListSchemaVerifier internal error: NSString does not respond to test selector %@.", NSStringFromSelector(testSelector));
637 return NO;
638 }
639
640 if ([test isKindOfClass:[NSString class]]) {
641 test = [NSArray arrayWithObject:test];
642 }
643
644 if ([test isKindOfClass:[NSArray class]]) {
645 for (testEnum = [test objectEnumerator]; (subTest = [testEnum nextObject]);) {
646 if ([subTest isKindOfClass:[NSString class]]) {
647 if (testIMP(string, testSelector, subTest))
648 return YES;
649 } else {
650 *outError = Error(kPListErrorSchemaBadComparator, &keyPath, @"Bad schema: required %@ is not a string.", testDescription);
651 return NO;
652 }
653 }
654 } else {
655 *outError = Error(kPListErrorSchemaBadComparator, &keyPath, @"Bad schema: %@ requirement specification is not a string or array.", testDescription);
656 }
657 return NO;
658}
@ kPListErrorInternal
@ kPListErrorSchemaBadComparator

References Error(), kPListErrorInternal, kPListErrorSchemaBadComparator, and nil.

Referenced by Verify_String().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ArrayForErrorReport()

NSString * ArrayForErrorReport ( NSArray * array)
static

Definition at line 700 of file OOPListSchemaVerifier.m.

701{
702 NSString* result = nil;
703 NSString* string = nil;
704 NSUInteger i, count;
705 NSAutoreleasePool* pool = nil;
706
707 count = [array count];
708 if (count == 0)
709 return @"( )";
710
711 pool = [[NSAutoreleasePool alloc] init];
712
713 result = [NSString stringWithFormat:@"(%@", [array objectAtIndex:0]];
714
715 for (i = 1; i != count; ++i) {
716 string = [result stringByAppendingFormat:@", %@", [array objectAtIndex:i]];
717 if (kMaximumLengthForStringInErrorMessage < [string length]) {
718 result = [result stringByAppendingString:@", ..."];
719 break;
720 }
721 result = string;
722 }
723
724 result = [result stringByAppendingString:@")"];
725
726 [result retain];
727 [pool release];
728 return [result autorelease];
729}
unsigned count

References count, kMaximumLengthForStringInErrorMessage, and nil.

Referenced by SetForErrorReport(), and Verify_Enumeration().

Here is the caller graph for this function:

◆ BackLink()

OOINLINE BackLinkChain BackLink ( BackLinkChain * link,
id element )

Definition at line 137 of file OOPListSchemaVerifier.m.

138{
139 BackLinkChain result = { link, element };
140 return result;
141}

References OOINLINE.

Referenced by Verify_Dictionary().

Here is the caller graph for this function:

◆ BackLinkIndex()

OOINLINE BackLinkChain BackLinkIndex ( BackLinkChain * link,
NSUInteger index )

Definition at line 143 of file OOPListSchemaVerifier.m.

144{
145 BackLinkChain result = { link, [NSNumber numberWithInteger:index] };
146 return result;
147}

References OOINLINE.

Referenced by Verify_Array().

Here is the caller graph for this function:

◆ BackLinkRoot()

OOINLINE BackLinkChain BackLinkRoot ( void )

Definition at line 149 of file OOPListSchemaVerifier.m.

150{
151 BackLinkChain result = { NULL, NULL };
152 return result;
153}

References OOINLINE.

◆ Error()

NSError * Error ( OOPListSchemaVerifierErrorCode errorCode,
BackLinkChain * keyPath,
NSString * format,
... )
static

Definition at line 1292 of file OOPListSchemaVerifier.m.

1293{
1294 NSError* result = nil;
1295 va_list args;
1296
1297 va_start(args, format);
1298 result = ErrorWithDictionaryAndArguments(errorCode, keyPath, nil, format, args);
1299 va_end(args);
1300
1301 return result;
1302}
static NSError * ErrorWithDictionaryAndArguments(OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSDictionary *dict, NSString *format, va_list arguments)

References ErrorWithDictionaryAndArguments(), and nil.

Referenced by ApplyStringFilter(), ApplyStringTest(), OOPListSchemaVerifier(OOPrivate)::resolveSchemaType:atPath:error:, Verify_Array(), Verify_Dictionary(), Verify_Enumeration(), Verify_Float(), Verify_Integer(), Verify_OneOf(), Verify_PositiveFloat(), Verify_PositiveInteger(), Verify_String(), and OOPListSchemaVerifier(OOPrivate)::verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ErrorFailureAlreadyReported()

NSError * ErrorFailureAlreadyReported ( void )
static

Definition at line 1383 of file OOPListSchemaVerifier.m.

1384{
1385 return [NSError errorWithDomain:kOOPListSchemaVerifierErrorDomain code:kPListErrorFailedAndErrorHasBeenReported userInfo:nil];
1386}

Referenced by Verify_Array(), and Verify_Dictionary().

Here is the caller graph for this function:

◆ ErrorTypeMismatch()

NSError * ErrorTypeMismatch ( Class expectedClass,
NSString * expectedClassName,
id actualObject,
BackLinkChain keyPath )
static

Definition at line 1350 of file OOPListSchemaVerifier.m.

1351{
1352 NSDictionary* dict = nil;
1353 NSString* className = nil;
1354
1355 if (expectedClassName == nil)
1356 expectedClassName = [expectedClass description];
1357
1358 dict = [NSDictionary dictionaryWithObjectsAndKeys:
1359 expectedClassName, kExpectedClassNameErrorKey,
1360 expectedClass, kExpectedClassErrorKey,
1361 nil];
1362
1363 if (actualObject == nil)
1364 className = @"nothing";
1365 else if ([actualObject isKindOfClass:[NSString class]])
1366 className = @"string";
1367 else if ([actualObject isKindOfClass:[NSNumber class]])
1368 className = @"number";
1369 else if ([actualObject isKindOfClass:[NSArray class]])
1370 className = @"array";
1371 else if ([actualObject isKindOfClass:[NSDictionary class]])
1372 className = @"dictionary";
1373 else if ([actualObject isKindOfClass:[NSData class]])
1374 className = @"data";
1375 else if ([actualObject isKindOfClass:[NSDate class]])
1376 className = @"date";
1377 else
1378 className = [[actualObject class] description];
1379
1380 return ErrorWithDictionary(kPListErrorTypeMismatch, &keyPath, dict, @"Expected %@, found %@.", expectedClassName, className);
1381}
@ kPListErrorTypeMismatch
static NSError * ErrorWithDictionary(OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSDictionary *dict, NSString *format,...)

References ErrorWithDictionary(), kPListErrorTypeMismatch, and nil.

Referenced by Verify_Boolean(), Verify_Float(), Verify_FuzzyBoolean(), Verify_Integer(), Verify_PositiveFloat(), Verify_PositiveInteger(), Verify_Quaternion(), and Verify_Vector().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ErrorWithDictionary()

NSError * ErrorWithDictionary ( OOPListSchemaVerifierErrorCode errorCode,
BackLinkChain * keyPath,
NSDictionary * dict,
NSString * format,
... )
static

Definition at line 1320 of file OOPListSchemaVerifier.m.

1321{
1322 NSError* result = nil;
1323 va_list args;
1324
1325 va_start(args, format);
1326 result = ErrorWithDictionaryAndArguments(errorCode, keyPath, dict, format, args);
1327 va_end(args);
1328
1329 return result;
1330}

References ErrorWithDictionaryAndArguments(), and nil.

Referenced by ErrorTypeMismatch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ErrorWithDictionaryAndArguments()

NSError * ErrorWithDictionaryAndArguments ( OOPListSchemaVerifierErrorCode errorCode,
BackLinkChain * keyPath,
NSDictionary * dict,
NSString * format,
va_list arguments )
static

Definition at line 1332 of file OOPListSchemaVerifier.m.

1333{
1334 NSString* message = nil;
1335 NSMutableDictionary* userInfo = nil;
1336
1337 message = [[NSString alloc] initWithFormat:format arguments:arguments];
1338
1339 userInfo = [NSMutableDictionary dictionaryWithDictionary:dict];
1340 [userInfo setObject:message forKey:NSLocalizedFailureReasonErrorKey];
1341 if (keyPath != NULL) {
1342 [userInfo setObject:KeyPathToArray(*keyPath) forKey:kPListKeyPathErrorKey];
1343 }
1344
1345 [message release];
1346
1347 return [NSError errorWithDomain:kOOPListSchemaVerifierErrorDomain code:errorCode userInfo:userInfo];
1348}

References nil.

Referenced by Error(), ErrorWithDictionary(), and ErrorWithProperty().

Here is the caller graph for this function:

◆ ErrorWithProperty()

NSError * ErrorWithProperty ( OOPListSchemaVerifierErrorCode errorCode,
BackLinkChain * keyPath,
NSString * propKey,
id propValue,
NSString * format,
... )
static

Definition at line 1304 of file OOPListSchemaVerifier.m.

1305{
1306 NSError* result = nil;
1307 va_list args;
1308 NSDictionary* dict = nil;
1309
1310 if (propKey != nil && propValue != nil) {
1311 dict = [NSDictionary dictionaryWithObject:propValue forKey:propKey];
1312 }
1313 va_start(args, format);
1314 result = ErrorWithDictionaryAndArguments(errorCode, keyPath, dict, format, args);
1315 va_end(args);
1316
1317 return result;
1318}

References ErrorWithDictionaryAndArguments(), and nil.

Referenced by ApplyStringFilter(), OOPListSchemaVerifier(OOPrivate)::delegateVerifierWithPropertyList:named:testProperty:atPath:againstType:error:, OOPListSchemaVerifier(OOPrivate)::resolveSchemaType:atPath:error:, StringToSchemaType(), Verify_Dictionary(), Verify_OneOf(), and Verify_String().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsFailureAlreadyReportedError()

BOOL IsFailureAlreadyReportedError ( NSError * error)
static

Definition at line 1388 of file OOPListSchemaVerifier.m.

1389{
1390 return [[error domain] isEqualToString:kOOPListSchemaVerifierErrorDomain] && [error code] == kPListErrorFailedAndErrorHasBeenReported;
1391}

References kPListErrorFailedAndErrorHasBeenReported.

Referenced by OOPListSchemaVerifier(OOPrivate)::verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:.

Here is the caller graph for this function:

◆ KeyPathToArray()

NSArray * KeyPathToArray ( BackLinkChain keyPath)
static

Definition at line 660 of file OOPListSchemaVerifier.m.

661{
662 NSMutableArray* result = nil;
663 BackLinkChain* curr = NULL;
664
665 result = [NSMutableArray array];
666 for (curr = &keyPath; curr != NULL; curr = curr->link) {
667 if (curr->element != nil)
668 [result insertObject:curr->element atIndex:0];
669 }
670
671 return result;
672}
BackLinkChain * link

References BackLinkChain::element, BackLinkChain::link, and nil.

◆ KeyPathToString()

NSString * KeyPathToString ( BackLinkChain keyPath)
static

Definition at line 674 of file OOPListSchemaVerifier.m.

675{
676 return [OOPListSchemaVerifier descriptionForKeyPath:KeyPathToArray(keyPath)];
677}
NSString * descriptionForKeyPath:(NSArray *keyPath)

References OOPListSchemaVerifier::descriptionForKeyPath:.

Referenced by OOPListSchemaVerifier(OOPrivate)::delegateVerifierWithPropertyList:named:testProperty:atPath:againstType:error:, OOPListSchemaVerifier(OOPrivate)::resolveSchemaType:atPath:error:, and OOPListSchemaVerifier(OOPrivate)::verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetForErrorReport()

NSString * SetForErrorReport ( NSSet * set)
static

Definition at line 731 of file OOPListSchemaVerifier.m.

732{
733 return ArrayForErrorReport([[set allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]);
734}
static NSString * ArrayForErrorReport(NSArray *array)

References ArrayForErrorReport().

Referenced by Verify_Dictionary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StringForErrorReport()

NSString * StringForErrorReport ( NSString * string)
static

Definition at line 679 of file OOPListSchemaVerifier.m.

680{
681 id result = nil;
682
683 if (kMaximumLengthForStringInErrorMessage < [string length]) {
684 string = [string substringToIndex:kMaximumLengthForStringInErrorMessage];
685 }
686 result = [NSMutableString stringWithString:string];
687 [result replaceOccurrencesOfString:@"\t" withString:@" " options:0 range:NSMakeRange(0, [string length])];
688 [result replaceOccurrencesOfString:@"\r\n" withString:@" \\ " options:0 range:NSMakeRange(0, [string length])];
689 [result replaceOccurrencesOfString:@"\n" withString:@" \\ " options:0 range:NSMakeRange(0, [string length])];
690 [result replaceOccurrencesOfString:@"\r" withString:@" \\ " options:0 range:NSMakeRange(0, [string length])];
691
692 if (kMaximumLengthForStringInErrorMessage < [result length]) {
693 result = [result substringToIndex:kMaximumLengthForStringInErrorMessage - 3];
694 result = [result stringByAppendingString:@"..."];
695 }
696
697 return result;
698}

References kMaximumLengthForStringInErrorMessage, and nil.

Referenced by OOPListSchemaVerifier(OOPrivate)::resolveSchemaType:atPath:error:, Verify_Dictionary(), Verify_Enumeration(), and Verify_String().

Here is the caller graph for this function:

◆ StringOrArrayForErrorReport()

NSString * StringOrArrayForErrorReport ( id value,
NSString * arrayPrefix )
static

Definition at line 736 of file OOPListSchemaVerifier.m.

737{
738 if ([value isKindOfClass:[NSString class]]) {
739 return [NSString stringWithFormat:@"\"%@\"", StringForErrorReport(value)];
740 }
741
742 if (arrayPrefix == nil)
743 arrayPrefix = @"";
744 if ([value isKindOfClass:[NSArray class]]) {
745 return [arrayPrefix stringByAppendingString:ArrayForErrorReport(value)];
746 }
747 if ([value isKindOfClass:[NSSet class]]) {
748 return [arrayPrefix stringByAppendingString:SetForErrorReport(value)];
749 }
750 if (value == nil)
751 return @"(null)";
752 return @"<?>";
753}

References nil.

Referenced by Verify_String().

Here is the caller graph for this function:

◆ StringToSchemaType()

SchemaType StringToSchemaType ( NSString * string,
NSError ** outError )
static

Definition at line 525 of file OOPListSchemaVerifier.m.

526{
527 static NSDictionary* typeMap = nil;
528 SchemaType result;
529
530 if (typeMap == nil) {
531 typeMap =
532 [[NSDictionary dictionaryWithObjectsAndKeys:
533 [NSNumber numberWithUnsignedInt:kTypeString], @"string",
534 [NSNumber numberWithUnsignedInt:kTypeArray], @"array",
535 [NSNumber numberWithUnsignedInt:kTypeDictionary], @"dictionary",
536 [NSNumber numberWithUnsignedInt:kTypeInteger], @"integer",
537 [NSNumber numberWithUnsignedInt:kTypePositiveInteger], @"positiveInteger",
538 [NSNumber numberWithUnsignedInt:kTypeFloat], @"float",
539 [NSNumber numberWithUnsignedInt:kTypePositiveFloat], @"positiveFloat",
540 [NSNumber numberWithUnsignedInt:kTypeOneOf], @"oneOf",
541 [NSNumber numberWithUnsignedInt:kTypeEnumeration], @"enumeration",
542 [NSNumber numberWithUnsignedInt:kTypeBoolean], @"boolean",
543 [NSNumber numberWithUnsignedInt:kTypeFuzzyBoolean], @"fuzzyBoolean",
544 [NSNumber numberWithUnsignedInt:kTypeVector], @"vector",
545 [NSNumber numberWithUnsignedInt:kTypeQuaternion], @"quaternion",
546 [NSNumber numberWithUnsignedInt:kTypeDelegatedType], @"delegatedType",
547 nil] retain];
548 }
549
550 result = [[typeMap objectForKey:string] unsignedIntValue];
551 if (result == kTypeUnknown && outError != NULL) {
552 if ([string hasPrefix:@"$"]) {
553 *outError = ErrorWithProperty(kPListErrorSchemaUnknownType, NULL, kUnknownTypeErrorKey, string, @"Bad schema: unresolved macro reference \"%@\".", string);
554 } else {
555 *outError = ErrorWithProperty(kPListErrorSchemaUnknownType, NULL, kUnknownTypeErrorKey, string, @"Bad schema: unknown type \"%@\".", string);
556 }
557 }
558
559 return result;
560}
@ kPListErrorSchemaUnknownType
NSString *const kUnknownTypeErrorKey

References ErrorWithProperty(), kPListErrorSchemaUnknownType, kTypeUnknown, kUnknownTypeErrorKey, and nil.

Referenced by OOPListSchemaVerifier(OOPrivate)::verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Verify_Array()

NSError * Verify_Array ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 825 of file OOPListSchemaVerifier.m.

826{
827 id valueType = nil;
828 BOOL OK = YES, stop = NO;
829 NSUInteger i, count;
830 id subProperty = nil;
831 NSUInteger constraint;
832
833 REQUIRE_TYPE(NSArray, @"array");
834
835 DebugDump(@"%@", @"* array");
836
837 // Apply count bounds.
838 count = [value count];
839 constraint = [params oo_unsignedIntegerForKey:@"minCount" defaultValue:0];
840 if (count < constraint) {
841 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Array has too few members (%u, minimum is %u).", count, constraint);
842 }
843
844 constraint = [params oo_unsignedIntegerForKey:@"maxCount" defaultValue:NSUIntegerMax];
845 if (constraint < count) {
846 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Array has too many members (%u, maximum is %u).", count, constraint);
847 }
848
849 // Test member objects.
850 valueType = [params objectForKey:@"valueType"];
851 if (valueType != nil) {
852 for (i = 0; i != count; ++i) {
853 subProperty = [value objectAtIndex:i];
854
855 if (![verifier verifyPList:rootPList
856 named:name
857 subProperty:subProperty
858 againstSchemaType:valueType
859 atPath:BackLinkIndex(&keyPath, i)
860 tentative:tentative
861 error:NULL
862 stop:&stop]) {
863 OK = NO;
864 }
865
866 if ((stop && !tentative) || (tentative && !OK))
867 break;
868 }
869 }
870
871 *outStop = stop && !tentative;
872
873 if (!OK)
875 else
876 return nil;
877}
@ kPListErrorMaximumConstraintNotMet
@ kPListErrorMinimumConstraintNotMet
static NSError * ErrorFailureAlreadyReported(void)
#define DebugDump(...)
OOINLINE BackLinkChain BackLinkIndex(BackLinkChain *link, NSUInteger index)
#define REQUIRE_TYPE(CLASSNAME, NAMESTRING)

References BackLinkIndex(), count, DebugDump, Error(), ErrorFailureAlreadyReported(), kPListErrorMaximumConstraintNotMet, kPListErrorMinimumConstraintNotMet, nil, and REQUIRE_TYPE.

Here is the call graph for this function:

◆ Verify_Boolean()

NSError * Verify_Boolean ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 1171 of file OOPListSchemaVerifier.m.

1172{
1173 DebugDump(@"* boolean: %@", value);
1174
1175 // Check basic parseability. If there's inequality here, the default value is being returned.
1176 if (OOBooleanFromObject(value, 0) == OOBooleanFromObject(value, 1))
1177 return nil;
1178 else
1179 return ErrorTypeMismatch([NSNumber class], @"boolean", value, keyPath);
1180}
BOOL OOBooleanFromObject(id object, BOOL defaultValue)

References DebugDump, ErrorTypeMismatch(), nil, and OOBooleanFromObject().

Here is the call graph for this function:

◆ Verify_DelegatedType()

NSError * Verify_DelegatedType ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 1217 of file OOPListSchemaVerifier.m.

1218{
1219 id baseType = nil;
1220 NSString* key = nil;
1221 BOOL stop = NO;
1222 NSError* error = nil;
1223
1224 DebugDump(@"* delegated type: %@", [params objectForKey:@"key"]);
1225
1226 baseType = [params objectForKey:@"baseType"];
1227 if (baseType != nil) {
1228 if (![verifier verifyPList:rootPList
1229 named:name
1230 subProperty:value
1231 againstSchemaType:baseType
1232 atPath:keyPath
1233 tentative:tentative
1234 error:NULL
1235 stop:&stop]) {
1236 *outStop = stop;
1237 return nil;
1238 }
1239 }
1240
1241 key = [params objectForKey:@"key"];
1242 *outStop = ![verifier delegateVerifierWithPropertyList:rootPList
1243 named:name
1244 testProperty:value
1245 atPath:keyPath
1246 againstType:key
1247 error:&error];
1248 return error;
1249}

References DebugDump, OOPListSchemaVerifier::delegateVerifierWithPropertyList:named:testProperty:atPath:againstType:error:, and nil.

Here is the call graph for this function:

◆ Verify_Dictionary()

NSError * Verify_Dictionary ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 879 of file OOPListSchemaVerifier.m.

880{
881 NSDictionary* schema = nil;
882 id valueType = nil,
883 typeSpec = nil;
884 NSEnumerator* keyEnum = nil;
885 NSString* key = nil;
886 id subProperty = nil;
887 BOOL OK = YES, stop = NO, prematureExit = NO;
888 BOOL allowOthers;
889 NSMutableSet* requiredKeys = nil;
890 NSArray* requiredKeyList = nil;
891 NSUInteger count, constraint;
892
893 REQUIRE_TYPE(NSDictionary, @"dictionary");
894
895 DebugDump(@"%@", @"* dictionary");
896
897 // Apply count bounds.
898 count = [value count];
899 constraint = [params oo_unsignedIntegerForKey:@"minCount" defaultValue:0];
900 if (count < constraint) {
901 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Dictionary has too few pairs (%u, minimum is %u).", count, constraint);
902 }
903 constraint = [params oo_unsignedIntegerForKey:@"maxCount" defaultValue:NSUIntegerMax];
904 if (constraint < count) {
905 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Dictionary has too manu pairs (%u, maximum is %u).", count, constraint);
906 }
907
908 // Get schema.
909 schema = [params oo_dictionaryForKey:@"schema"];
910 valueType = [params objectForKey:@"valueType"];
911 allowOthers = [params oo_boolForKey:@"allowOthers" defaultValue:YES];
912 requiredKeyList = [params oo_arrayForKey:@"requiredKeys"];
913
914 // If these conditions are met, all members must pass:
915 if (schema == nil && valueType == nil && requiredKeyList == nil && allowOthers)
916 return nil;
917
918 if (requiredKeyList != nil) {
919 requiredKeys = [NSMutableSet setWithArray:requiredKeyList];
920 }
921
923
924 // Test member objects.
925 for (keyEnum = [value keyEnumerator]; (key = [keyEnum nextObject]) && !stop;) {
926 subProperty = [(NSDictionary*)value objectForKey:key];
927 typeSpec = [schema objectForKey:key];
928 if (typeSpec == nil)
929 typeSpec = valueType;
930
931 DebugDump(@"- \"%@\"", key);
933
934 if (typeSpec != nil) {
935 if (![verifier verifyPList:rootPList
936 named:name
937 subProperty:subProperty
938 againstSchemaType:typeSpec
939 atPath:BackLink(&keyPath, key)
940 tentative:tentative
941 error:NULL
942 stop:&stop]) {
943 OK = NO;
944 }
945 } else if (!allowOthers && ![requiredKeys containsObject:key] && [schema objectForKey:key] == nil) {
946 // Report error now rather than returning it, since there may be several unknown keys.
947 if (!tentative) {
948 NSError* error = ErrorWithProperty(kPListErrorDictionaryUnknownKey, &keyPath, kUnknownKeyErrorKey, key, @"Unpermitted key \"%@\" in dictionary.", StringForErrorReport(key));
949 stop = ![verifier delegateVerifierWithPropertyList:rootPList
950 named:name
951 failedForProperty:value
952 withError:error
953 expectedType:params];
954 }
955 OK = NO;
956 }
957
959
960 [requiredKeys removeObject:key];
961
962 if ((stop && !tentative) || (tentative && !OK)) {
963 prematureExit = YES;
964 break;
965 }
966 }
967
969
970 // Check that all required keys were present.
971 if (!prematureExit && [requiredKeys count] != 0) {
972 return ErrorWithProperty(kPListErrorDictionaryMissingRequiredKeys, &keyPath, kMissingRequiredKeysErrorKey, requiredKeys, @"Required keys %@ missing from dictionary.", SetForErrorReport(requiredKeys));
973 }
974
975 *outStop = stop && !tentative;
976
977 if (!OK)
979 else
980 return nil;
981}
NSString *const kMissingRequiredKeysErrorKey
@ kPListErrorDictionaryMissingRequiredKeys
@ kPListErrorDictionaryUnknownKey
NSString *const kUnknownKeyErrorKey
static NSString * SetForErrorReport(NSSet *set)
static NSString * StringForErrorReport(NSString *string)
OOINLINE BackLinkChain BackLink(BackLinkChain *link, id element)
#define DebugDumpIndent()
#define DebugDumpOutdent()

References BackLink(), count, DebugDump, DebugDumpIndent, DebugDumpOutdent, OOPListSchemaVerifier::delegateVerifierWithPropertyList:named:failedForProperty:withError:expectedType:, Error(), ErrorFailureAlreadyReported(), ErrorWithProperty(), kMissingRequiredKeysErrorKey, kPListErrorDictionaryMissingRequiredKeys, kPListErrorDictionaryUnknownKey, kPListErrorMaximumConstraintNotMet, kPListErrorMinimumConstraintNotMet, kUnknownKeyErrorKey, nil, REQUIRE_TYPE, SetForErrorReport(), and StringForErrorReport().

Here is the call graph for this function:

◆ Verify_Enumeration()

NSError * Verify_Enumeration ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 1143 of file OOPListSchemaVerifier.m.

1144{
1145 NSArray* values = nil;
1146 NSString* filteredString = nil;
1147 NSError* error = nil;
1148
1149 DebugDump(@"%@", @"* enumeration");
1150
1151 REQUIRE_TYPE(NSString, @"string");
1152
1153 values = [params oo_arrayForKey:@"values"];
1154 DebugDump(@" - \"%@\" in %@", StringForErrorReport(value), ArrayForErrorReport(values));
1155
1156 if (values == nil) {
1157 *outStop = YES;
1158 return Error(kPListErrorSchemaNoEnumerationValues, &keyPath, @"Bad schema: no options specified for oneOf type.");
1159 }
1160
1161 filteredString = ApplyStringFilter(value, [params objectForKey:@"filter"], keyPath, &error);
1162 if (filteredString == nil)
1163 return error;
1164
1165 if ([values containsObject:filteredString])
1166 return nil;
1167
1168 return Error(kPListErrorEnumerationBadValue, &keyPath, @"Value \"%@\" not recognized, should be one of %@.", StringForErrorReport(value), ArrayForErrorReport(values));
1169}
@ kPListErrorSchemaNoEnumerationValues
@ kPListErrorEnumerationBadValue
static NSString * ApplyStringFilter(NSString *string, id filterSpec, BackLinkChain keyPath, NSError **outError)

References ApplyStringFilter(), ArrayForErrorReport(), DebugDump, Error(), kPListErrorEnumerationBadValue, kPListErrorSchemaNoEnumerationValues, nil, REQUIRE_TYPE, and StringForErrorReport().

Here is the call graph for this function:

◆ Verify_Float()

NSError * Verify_Float ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 1039 of file OOPListSchemaVerifier.m.

1040{
1041 double numericValue;
1042 double constraint;
1043
1044 numericValue = OODoubleFromObject(value, 0);
1045
1046 DebugDump(@"* float: %g", numericValue);
1047
1048 // Check basic parseability. If there's inequality here, the default value is being returned.
1049 if (numericValue != OODoubleFromObject(value, 1)) {
1050 return ErrorTypeMismatch([NSNumber class], @"number", value, keyPath);
1051 }
1052
1053 // Check constraints.
1054 constraint = [params oo_doubleForKey:@"minimum" defaultValue:-INFINITY];
1055 if (numericValue < constraint) {
1056 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Number is too small (%g, minimum is %g).", numericValue, constraint);
1057 }
1058
1059 constraint = [params oo_doubleForKey:@"maximum" defaultValue:INFINITY];
1060 if (constraint < numericValue) {
1061 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Number is too large (%g, maximum is %g).", numericValue, constraint);
1062 }
1063
1064 return nil;
1065}
double OODoubleFromObject(id object, double defaultValue)

References DebugDump, Error(), ErrorTypeMismatch(), kPListErrorMaximumConstraintNotMet, kPListErrorMinimumConstraintNotMet, nil, and OODoubleFromObject().

Here is the call graph for this function:

◆ Verify_FuzzyBoolean()

NSError * Verify_FuzzyBoolean ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 1182 of file OOPListSchemaVerifier.m.

1183{
1184 DebugDump(@"* fuzzy boolean: %@", value);
1185
1186 // Check basic parseability. If there's inequality here, the default value is being returned.
1187 if (OODoubleFromObject(value, 0) == OODoubleFromObject(value, 1))
1188 return nil;
1189 else if (OOBooleanFromObject(value, 0) == OOBooleanFromObject(value, 1))
1190 return nil;
1191 else
1192 return ErrorTypeMismatch([NSNumber class], @"fuzzy boolean", value, keyPath);
1193}

References DebugDump, ErrorTypeMismatch(), nil, OOBooleanFromObject(), and OODoubleFromObject().

Here is the call graph for this function:

◆ Verify_Integer()

NSError * Verify_Integer ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 983 of file OOPListSchemaVerifier.m.

984{
985 long long numericValue;
986 long long constraint;
987
988 numericValue = OOLongLongFromObject(value, 0);
989
990 DebugDump(@"* integer: %lli", numericValue);
991
992 // Check basic parseability. If there's inequality here, the default value is being returned.
993 if (numericValue != OOLongLongFromObject(value, 1)) {
994 return ErrorTypeMismatch([NSNumber class], @"integer", value, keyPath);
995 }
996
997 // Check constraints.
998 constraint = [params oo_longLongForKey:@"minimum" defaultValue:LLONG_MIN];
999 if (numericValue < constraint) {
1000 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Number is too small (%lli, minimum is %lli).", numericValue, constraint);
1001 }
1002
1003 constraint = [params oo_longLongForKey:@"maximum" defaultValue:LLONG_MAX];
1004 if (constraint < numericValue) {
1005 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Number is too large (%lli, maximum is %lli).", numericValue, constraint);
1006 }
1007
1008 return nil;
1009}
long long OOLongLongFromObject(id object, long long defaultValue)

References DebugDump, Error(), ErrorTypeMismatch(), kPListErrorMaximumConstraintNotMet, kPListErrorMinimumConstraintNotMet, nil, and OOLongLongFromObject().

Here is the call graph for this function:

◆ Verify_OneOf()

NSError * Verify_OneOf ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 1099 of file OOPListSchemaVerifier.m.

1100{
1101 NSArray* options = nil;
1102 BOOL OK = NO, stop = NO;
1103 id option = nil;
1104 NSError* error;
1105 NSMutableDictionary* errors = nil;
1106
1107 DebugDump(@"%@", @"* oneOf");
1108
1109 options = [params oo_arrayForKey:@"options"];
1110 if (options == nil) {
1111 *outStop = YES;
1112 return Error(kPListErrorSchemaNoOneOfOptions, &keyPath, @"Bad schema: no options specified for oneOf type.");
1113 }
1114
1115 errors = [[NSMutableDictionary alloc] initWithCapacity:[options count]];
1116
1117 foreach (option, options) {
1118 if ([verifier verifyPList:rootPList
1119 named:name
1120 subProperty:value
1121 againstSchemaType:option
1122 atPath:keyPath
1123 tentative:YES
1124 error:&error
1125 stop:&stop]) {
1126 DebugDump(@"%@", @"> Match.");
1127 OK = YES;
1128 break;
1129 }
1130 [errors setObject:error forKey:option];
1131 }
1132
1133 if (!OK) {
1134 DebugDump(@"%@", @"! No match.");
1135 return ErrorWithProperty(kPListErrorOneOfNoMatch, &keyPath, kErrorsByOptionErrorKey, [errors autorelease], @"No matching type rule could be found.");
1136 }
1137
1138 // Ignore stop in tentatives.
1139 [errors release];
1140 return nil;
1141}
NSString *const kErrorsByOptionErrorKey
@ kPListErrorSchemaNoOneOfOptions
@ kPListErrorOneOfNoMatch

References DebugDump, Error(), ErrorWithProperty(), kErrorsByOptionErrorKey, kPListErrorOneOfNoMatch, kPListErrorSchemaNoOneOfOptions, and nil.

Here is the call graph for this function:

◆ Verify_PositiveFloat()

NSError * Verify_PositiveFloat ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 1067 of file OOPListSchemaVerifier.m.

1068{
1069 double numericValue;
1070 double constraint;
1071
1072 numericValue = OODoubleFromObject(value, 0);
1073
1074 DebugDump(@"* positive float: %g", numericValue);
1075
1076 // Check basic parseability. If there's inequality here, the default value is being returned.
1077 if (numericValue != OODoubleFromObject(value, 1)) {
1078 return ErrorTypeMismatch([NSNumber class], @"positive number", value, keyPath);
1079 }
1080
1081 if (numericValue < 0) {
1082 return Error(kPListErrorNumberIsNegative, &keyPath, @"Expected non-negative number, found %g.", numericValue);
1083 }
1084
1085 // Check constraints.
1086 constraint = [params oo_doubleForKey:@"minimum" defaultValue:0];
1087 if (numericValue < constraint) {
1088 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Number is too small (%g, minimum is %g).", numericValue, constraint);
1089 }
1090
1091 constraint = [params oo_doubleForKey:@"maximum" defaultValue:INFINITY];
1092 if (constraint < numericValue) {
1093 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Number is too large (%g, maximum is %g).", numericValue, constraint);
1094 }
1095
1096 return nil;
1097}
@ kPListErrorNumberIsNegative

References DebugDump, Error(), ErrorTypeMismatch(), kPListErrorMaximumConstraintNotMet, kPListErrorMinimumConstraintNotMet, kPListErrorNumberIsNegative, nil, and OODoubleFromObject().

Here is the call graph for this function:

◆ Verify_PositiveInteger()

NSError * Verify_PositiveInteger ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 1011 of file OOPListSchemaVerifier.m.

1012{
1013 unsigned long long numericValue;
1014 unsigned long long constraint;
1015
1016 numericValue = OOUnsignedLongLongFromObject(value, 0);
1017
1018 DebugDump(@"* positive integer: %llu", numericValue);
1019
1020 // Check basic parseability. If there's inequality here, the default value is being returned.
1021 if (numericValue != OOUnsignedLongLongFromObject(value, 1)) {
1022 return ErrorTypeMismatch([NSNumber class], @"positive integer", value, keyPath);
1023 }
1024
1025 // Check constraints.
1026 constraint = [params oo_unsignedLongLongForKey:@"minimum" defaultValue:0];
1027 if (numericValue < constraint) {
1028 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Number is too small (%zu, minimum is %zu).", numericValue, constraint);
1029 }
1030
1031 constraint = [params oo_unsignedLongLongForKey:@"maximum" defaultValue:ULLONG_MAX];
1032 if (constraint < numericValue) {
1033 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Number is too large (%zu, maximum is %zu).", numericValue, constraint);
1034 }
1035
1036 return nil;
1037}
unsigned long long OOUnsignedLongLongFromObject(id object, unsigned long long defaultValue)

References DebugDump, Error(), ErrorTypeMismatch(), kPListErrorMaximumConstraintNotMet, kPListErrorMinimumConstraintNotMet, nil, and OOUnsignedLongLongFromObject().

Here is the call graph for this function:

◆ VERIFY_PROTO() [1/14]

VERIFY_PROTO ( Array )

◆ VERIFY_PROTO() [2/14]

VERIFY_PROTO ( Boolean )

◆ VERIFY_PROTO() [3/14]

VERIFY_PROTO ( DelegatedType )

◆ VERIFY_PROTO() [4/14]

VERIFY_PROTO ( Dictionary )

◆ VERIFY_PROTO() [5/14]

VERIFY_PROTO ( Enumeration )

◆ VERIFY_PROTO() [6/14]

VERIFY_PROTO ( Float )

◆ VERIFY_PROTO() [7/14]

VERIFY_PROTO ( FuzzyBoolean )

◆ VERIFY_PROTO() [8/14]

VERIFY_PROTO ( Integer )

◆ VERIFY_PROTO() [9/14]

VERIFY_PROTO ( OneOf )

◆ VERIFY_PROTO() [10/14]

VERIFY_PROTO ( PositiveFloat )

◆ VERIFY_PROTO() [11/14]

VERIFY_PROTO ( PositiveInteger )

◆ VERIFY_PROTO() [12/14]

VERIFY_PROTO ( Quaternion )

◆ VERIFY_PROTO() [13/14]

VERIFY_PROTO ( String )

◆ VERIFY_PROTO() [14/14]

VERIFY_PROTO ( Vector )

◆ Verify_Quaternion()

NSError * Verify_Quaternion ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 1206 of file OOPListSchemaVerifier.m.

1207{
1208 DebugDump(@"* quaternion: %@", value);
1209
1210 // Check basic parseability. If there's inequality here, the default value is being returned.
1212 return nil;
1213 else
1214 return ErrorTypeMismatch(Nil, @"quaternion", value, keyPath);
1215}
Quaternion OOQuaternionFromObject(id object, Quaternion defaultValue)
OOINLINE bool quaternion_equal(Quaternion a, Quaternion b) INLINE_CONST_FUNC
const Quaternion kIdentityQuaternion
const Quaternion kZeroQuaternion

References DebugDump, ErrorTypeMismatch(), kIdentityQuaternion, kZeroQuaternion, nil, OOQuaternionFromObject(), and quaternion_equal().

Here is the call graph for this function:

◆ Verify_String()

NSError * Verify_String ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 764 of file OOPListSchemaVerifier.m.

765{
766 NSString* filteredString = nil;
767 id testValue = nil;
768 NSUInteger length;
769 NSUInteger lengthConstraint;
770 NSError* error = nil;
771
772 REQUIRE_TYPE(NSString, @"string");
773
774 DebugDump(@"* string: \"%@\"", StringForErrorReport(value));
775
776 // Apply filters
777 filteredString = ApplyStringFilter(value, [params objectForKey:@"filter"], keyPath, &error);
778 if (filteredString == nil)
779 return error;
780
781 // Apply substring requirements
782 testValue = [params objectForKey:@"requiredPrefix"];
783 if (testValue != nil) {
784 if (!ApplyStringTest(filteredString, testValue, @selector(hasPrefix:), @"prefix", keyPath, &error)) {
785 if (error == nil)
786 error = ErrorWithProperty(kPListErrorStringPrefixMissing, &keyPath, kMissingSubStringErrorKey, testValue, @"String \"%@\" does not have required %@ %@.", StringForErrorReport(value), @"prefix", StringOrArrayForErrorReport(testValue, @"in "));
787 return error;
788 }
789 }
790
791 testValue = [params objectForKey:@"requiredSuffix"];
792 if (testValue != nil) {
793 if (!ApplyStringTest(filteredString, testValue, @selector(hasSuffix:), @"suffix", keyPath, &error)) {
794 if (error == nil)
795 error = ErrorWithProperty(kPListErrorStringSuffixMissing, &keyPath, kMissingSubStringErrorKey, testValue, @"String \"%@\" does not have required %@ %@.", StringForErrorReport(value), @"suffix", StringOrArrayForErrorReport(testValue, @"in "));
796 return error;
797 }
798 }
799
800 testValue = [params objectForKey:@"requiredSubString"];
801 if (testValue != nil) {
802 if (!ApplyStringTest(filteredString, testValue, @selector(ooPListVerifierHasSubString:), @"substring", keyPath, &error)) {
803 if (error == nil)
804 error = ErrorWithProperty(kPListErrorStringSubstringMissing, &keyPath, kMissingSubStringErrorKey, testValue, @"String \"%@\" does not have required %@ %@.", StringForErrorReport(value), @"substring", StringOrArrayForErrorReport(testValue, @"in "));
805 return error;
806 }
807 }
808
809 // Apply length bounds.
810 length = [filteredString length];
811 lengthConstraint = [params oo_unsignedIntegerForKey:@"minLength"];
812 if (length < lengthConstraint) {
813 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"String \"%@\" is too short (%u bytes, minimum is %u).", StringForErrorReport(filteredString), length, lengthConstraint);
814 }
815
816 lengthConstraint = [params oo_unsignedIntegerForKey:@"maxLength" defaultValue:NSUIntegerMax];
817 if (lengthConstraint < length) {
818 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"String \"%@\" is too long (%u bytes, maximum is %u).", StringForErrorReport(filteredString), length, lengthConstraint);
819 }
820
821 // All tests passed.
822 return nil;
823}
@ kPListErrorStringSubstringMissing
@ kPListErrorStringSuffixMissing
@ kPListErrorStringPrefixMissing
NSString *const kMissingSubStringErrorKey
static BOOL ApplyStringTest(NSString *string, id test, SEL testSelector, NSString *testDescription, BackLinkChain keyPath, NSError **outError)
static NSString * StringOrArrayForErrorReport(id value, NSString *arrayPrefix)

References ApplyStringFilter(), ApplyStringTest(), DebugDump, Error(), ErrorWithProperty(), kMissingSubStringErrorKey, kPListErrorMaximumConstraintNotMet, kPListErrorMinimumConstraintNotMet, kPListErrorStringPrefixMissing, kPListErrorStringSubstringMissing, kPListErrorStringSuffixMissing, nil, REQUIRE_TYPE, StringForErrorReport(), and StringOrArrayForErrorReport().

Here is the call graph for this function:

◆ Verify_Vector()

NSError * Verify_Vector ( OOPListSchemaVerifier * verifier,
id value,
NSDictionary * params,
id rootPList,
NSString * name,
BackLinkChain keyPath,
BOOL tentative,
BOOL * outStop )
static

Definition at line 1195 of file OOPListSchemaVerifier.m.

1196{
1197 DebugDump(@"* vector: %@", value);
1198
1199 // Check basic parseability. If there's inequality here, the default value is being returned.
1201 return nil;
1202 else
1203 return ErrorTypeMismatch(Nil, @"vector", value, keyPath);
1204}
Vector OOVectorFromObject(id object, Vector defaultValue)
const Vector kZeroVector
Definition OOVector.m:27
OOINLINE bool vector_equal(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:232
const Vector kBasisXVector
Definition OOVector.h:45

References DebugDump, ErrorTypeMismatch(), kBasisXVector, kZeroVector, nil, OOVectorFromObject(), and vector_equal().

Here is the call graph for this function:

Variable Documentation

◆ kErrorsByOptionErrorKey

NSString* const kErrorsByOptionErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier errors by option"

◆ kExpectedClassErrorKey

NSString* const kExpectedClassErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier expected class"

◆ kExpectedClassNameErrorKey

NSString* const kExpectedClassNameErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier expected class name"

◆ kMissingRequiredKeysErrorKey

NSString* const kMissingRequiredKeysErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier missing required keys"

◆ kMissingSubStringErrorKey

NSString* const kMissingSubStringErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier missing substring"

◆ kOOPListSchemaVerifierErrorDomain

NSString* const kOOPListSchemaVerifierErrorDomain = @"org.aegidian.oolite.OOPListSchemaVerifier.ErrorDomain"

◆ kPListKeyPathErrorKey

NSString* const kPListKeyPathErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier plist key path"

◆ kSchemaKeyPathErrorKey

NSString* const kSchemaKeyPathErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier schema key path"

◆ kUndefinedMacroErrorKey

NSString* const kUndefinedMacroErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier undefined macro"

◆ kUnknownKeyErrorKey

NSString* const kUnknownKeyErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier unknown key"

◆ kUnknownTypeErrorKey

NSString* const kUnknownTypeErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier unknown type"

◆ kUnnownFilterErrorKey

NSString* const kUnnownFilterErrorKey = @"org.aegidian.oolite.OOPListSchemaVerifier unknown filter"

◆ sDebugDump

BOOL sDebugDump = NO
static

Definition at line 52 of file OOPListSchemaVerifier.m.

Referenced by OOPListSchemaVerifier::initWithSchema:.