Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOPListSchemaVerifier.m File Reference
import "OOPListSchemaVerifier.h"
import "OOLoggingExtended.h"
import "OOCollectionExtractors.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)
#define OOLog(class, format,...)
Definition OOLogging.h:88
static BOOL sDebugDump

Definition at line 64 of file OOPListSchemaVerifier.m.

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)
void OOLogIndent(void)
Definition OOLogging.m:366

Definition at line 60 of file OOPListSchemaVerifier.m.

Referenced by Verify_Dictionary().

◆ DebugDumpOutdent

#define DebugDumpOutdent ( )
Value:
do { if (sDebugDump) OOLogOutdent(); } while (0)
void OOLogOutdent(void)
Definition OOLogging.m:376

Definition at line 61 of file OOPListSchemaVerifier.m.

Referenced by Verify_Dictionary().

◆ DebugDumpPopIndent

#define DebugDumpPopIndent ( )
Value:
do { if (sDebugDump) OOLogPopIndent(); } while (0)
void OOLogPopIndent(void)
Definition OOLogging.m:340

Definition at line 63 of file OOPListSchemaVerifier.m.

◆ DebugDumpPushIndent

#define DebugDumpPushIndent ( )
Value:
do { if (sDebugDump) OOLogPushIndent(); } while (0)
void OOLogPushIndent(void)
Definition OOLogging.m:316

Definition at line 62 of file OOPListSchemaVerifier.m.

◆ PLIST_VERIFIER_DEBUG_DUMP_ENABLED

#define PLIST_VERIFIER_DEBUG_DUMP_ENABLED   1

Definition at line 38 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 831 of file OOPListSchemaVerifier.m.

831#define REQUIRE_TYPE(CLASSNAME, NAMESTRING) do { \
832 if (![value isKindOfClass:[CLASSNAME class]]) \
833 { \
834 return ErrorTypeMismatch([CLASSNAME class], NAMESTRING, value, keyPath); \
835 } \
836 } 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;

◆ 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 196 of file OOPListSchemaVerifier.m.

Typedef Documentation

◆ BackLinkChain

typedef struct BackLinkChain BackLinkChain

Definition at line 111 of file OOPListSchemaVerifier.m.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kMaximumLengthForStringInErrorMessage 

Definition at line 41 of file OOPListSchemaVerifier.m.

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

◆ anonymous enum

anonymous enum
Enumerator
kStartOfPrivateErrorCodes 
kPListErrorFailedAndErrorHasBeenReported 

Definition at line 49 of file OOPListSchemaVerifier.m.

◆ SchemaType

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

Definition at line 91 of file OOPListSchemaVerifier.m.

Function Documentation

◆ ApplyStringFilter()

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

Definition at line 596 of file OOPListSchemaVerifier.m.

597{
598 NSEnumerator *filterEnum = nil;
599 id filter = nil;
600 NSRange range;
601
602 assert(outError != NULL);
603
604 if (filterSpec == nil) return string;
605
606 if ([filterSpec isKindOfClass:[NSString class]])
607 {
608 filterSpec = [NSArray arrayWithObject:filterSpec];
609 }
610 if ([filterSpec isKindOfClass:[NSArray class]])
611 {
612 for (filterEnum = [filterSpec objectEnumerator]; (filter = [filterEnum nextObject]); )
613 {
614 if ([filter isKindOfClass:[NSString class]])
615 {
616 if ([filter isEqual:@"lowerCase"]) string = [string lowercaseString];
617 else if ([filter isEqual:@"upperCase"]) string = [string uppercaseString];
618 else if ([filter isEqual:@"capitalized"]) string = [string capitalizedString];
619 else if ([filter hasPrefix:@"truncFront:"])
620 {
621 string = [string substringToIndex:[[filter substringFromIndex:11] intValue]];
622 }
623 else if ([filter hasPrefix:@"truncBack:"])
624 {
625 string = [string substringToIndex:[[filter substringFromIndex:10] intValue]];
626 }
627 else if ([filter hasPrefix:@"subStringTo:"])
628 {
629 range = [string rangeOfString:[filter substringFromIndex:12]];
630 if (range.location != NSNotFound)
631 {
632 string = [string substringToIndex:range.location];
633 }
634 }
635 else if ([filter hasPrefix:@"subStringFrom:"])
636 {
637 range = [string rangeOfString:[filter substringFromIndex:14]];
638 if (range.location != NSNotFound)
639 {
640 string = [string substringFromIndex:range.location + range.length];
641 }
642 }
643 else if ([filter hasPrefix:@"subStringToInclusive:"])
644 {
645 range = [string rangeOfString:[filter substringFromIndex:21]];
646 if (range.location != NSNotFound)
647 {
648 string = [string substringToIndex:range.location + range.length];
649 }
650 }
651 else if ([filter hasPrefix:@"subStringFromInclusive:"])
652 {
653 range = [string rangeOfString:[filter substringFromIndex:23]];
654 if (range.location != NSNotFound)
655 {
656 string = [string substringFromIndex:range.location];
657 }
658 }
659 else
660 {
661 *outError = ErrorWithProperty(kPListErrorSchemaUnknownFilter, &keyPath, kUnnownFilterErrorKey, filter, @"Bad schema: unknown string filter specifier \"%@\".", filter);
662 }
663 }
664 else
665 {
666 *outError = Error(kPListErrorSchemaUnknownFilter, &keyPath, @"Bad schema: filter specifier is not a string.");
667 }
668 }
669 }
670 else
671 {
672 *outError = Error(kPListErrorSchemaUnknownFilter, &keyPath, @"Bad schema: \"filter\" must be a string or an array.");
673 }
674
675 return string;
676}
@ kPListErrorSchemaUnknownFilter
static NSError * Error(OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSString *format,...)
NSString *const kUnnownFilterErrorKey
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()

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

Definition at line 679 of file OOPListSchemaVerifier.m.

680{
681 BOOL (*testIMP)(id, SEL, NSString *);
682 NSEnumerator *testEnum = nil;
683 id subTest = nil;
684
685 assert(outError != NULL);
686
687 if (test == nil) return YES;
688
689 testIMP = (BOOL(*)(id, SEL, NSString *))[string methodForSelector:testSelector];
690 if (testIMP == NULL)
691 {
692 *outError = Error(kPListErrorInternal, &keyPath, @"OOPListSchemaVerifier internal error: NSString does not respond to test selector %@.", NSStringFromSelector(testSelector));
693 return NO;
694 }
695
696 if ([test isKindOfClass:[NSString class]])
697 {
698 test = [NSArray arrayWithObject:test];
699 }
700
701 if ([test isKindOfClass:[NSArray class]])
702 {
703 for (testEnum = [test objectEnumerator]; (subTest = [testEnum nextObject]); )
704 {
705 if ([subTest isKindOfClass:[NSString class]])
706 {
707 if (testIMP(string, testSelector, subTest)) return YES;
708 }
709 else
710 {
711 *outError = Error(kPListErrorSchemaBadComparator, &keyPath, @"Bad schema: required %@ is not a string.", testDescription);
712 return NO;
713 }
714 }
715 }
716 else
717 {
718 *outError = Error(kPListErrorSchemaBadComparator, &keyPath, @"Bad schema: %@ requirement specification is not a string or array.", testDescription);
719 }
720 return NO;
721}
@ 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()

static NSString * ArrayForErrorReport ( NSArray * array)
static

Definition at line 769 of file OOPListSchemaVerifier.m.

770{
771 NSString *result = nil;
772 NSString *string = nil;
773 NSUInteger i, count;
774 NSAutoreleasePool *pool = nil;
775
776 count = [array count];
777 if (count == 0) return @"( )";
778
779 pool = [[NSAutoreleasePool alloc] init];
780
781 result = [NSString stringWithFormat:@"(%@", [array objectAtIndex:0]];
782
783 for (i = 1; i != count; ++i)
784 {
785 string = [result stringByAppendingFormat:@", %@", [array objectAtIndex:i]];
786 if (kMaximumLengthForStringInErrorMessage < [string length])
787 {
788 result = [result stringByAppendingString:@", ..."];
789 break;
790 }
791 result = string;
792 }
793
794 result = [result stringByAppendingString:@")"];
795
796 [result retain];
797 [pool release];
798 return [result autorelease];
799}
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 118 of file OOPListSchemaVerifier.m.

119{
120 BackLinkChain result = { link, element };
121 return result;
122}

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

Referenced by Verify_Dictionary().

+ Here is the caller graph for this function:

◆ BackLinkIndex()

OOINLINE BackLinkChain BackLinkIndex ( BackLinkChain * link,
NSUInteger index )

Definition at line 124 of file OOPListSchemaVerifier.m.

125{
126 BackLinkChain result = { link, [NSNumber numberWithInteger:index] };
127 return result;
128}

References BackLinkChain::link.

Referenced by Verify_Array().

+ Here is the caller graph for this function:

◆ BackLinkRoot()

OOINLINE BackLinkChain BackLinkRoot ( void )

Definition at line 130 of file OOPListSchemaVerifier.m.

131{
132 BackLinkChain result = { NULL, NULL };
133 return result;
134}

◆ Error()

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

Definition at line 1408 of file OOPListSchemaVerifier.m.

1409{
1410 NSError *result = nil;
1411 va_list args;
1412
1413 va_start(args, format);
1414 result = ErrorWithDictionaryAndArguments(errorCode, keyPath, nil, format, args);
1415 va_end(args);
1416
1417 return result;
1418}
static NSError * ErrorWithDictionaryAndArguments(OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSDictionary *dict, NSString *format, va_list arguments)

References ErrorWithDictionaryAndArguments(), and nil.

Referenced by ApplyStringFilter(), ApplyStringTest(), Verify_Array(), Verify_Dictionary(), Verify_Enumeration(), Verify_Float(), Verify_Integer(), Verify_OneOf(), Verify_PositiveFloat(), Verify_PositiveInteger(), and Verify_String().

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

◆ ErrorFailureAlreadyReported()

static NSError * ErrorFailureAlreadyReported ( void )
static

Definition at line 1497 of file OOPListSchemaVerifier.m.

1498{
1499 return [NSError errorWithDomain:kOOPListSchemaVerifierErrorDomain code:kPListErrorFailedAndErrorHasBeenReported userInfo:nil];
1500}

Referenced by Verify_Array(), and Verify_Dictionary().

+ Here is the caller graph for this function:

◆ ErrorTypeMismatch()

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

Definition at line 1472 of file OOPListSchemaVerifier.m.

1473{
1474 NSDictionary *dict = nil;
1475 NSString *className = nil;
1476
1477 if (expectedClassName == nil) expectedClassName = [expectedClass description];
1478
1479 dict = [NSDictionary dictionaryWithObjectsAndKeys:
1480 expectedClassName, kExpectedClassNameErrorKey,
1481 expectedClass, kExpectedClassErrorKey,
1482 nil];
1483
1484 if (actualObject == nil) className = @"nothing";
1485 else if ([actualObject isKindOfClass:[NSString class]]) className = @"string";
1486 else if ([actualObject isKindOfClass:[NSNumber class]]) className = @"number";
1487 else if ([actualObject isKindOfClass:[NSArray class]]) className = @"array";
1488 else if ([actualObject isKindOfClass:[NSDictionary class]]) className = @"dictionary";
1489 else if ([actualObject isKindOfClass:[NSData class]]) className = @"data";
1490 else if ([actualObject isKindOfClass:[NSDate class]]) className = @"date";
1491 else className = [[actualObject class] description];
1492
1493 return ErrorWithDictionary(kPListErrorTypeMismatch, &keyPath, dict, @"Expected %@, found %@.", expectedClassName, className);
1494}
@ 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()

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

Definition at line 1439 of file OOPListSchemaVerifier.m.

1440{
1441 NSError *result = nil;
1442 va_list args;
1443
1444 va_start(args, format);
1445 result = ErrorWithDictionaryAndArguments(errorCode, keyPath, dict, format, args);
1446 va_end(args);
1447
1448 return result;
1449}

References ErrorWithDictionaryAndArguments(), and nil.

Referenced by ErrorTypeMismatch().

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

◆ ErrorWithDictionaryAndArguments()

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

Definition at line 1452 of file OOPListSchemaVerifier.m.

1453{
1454 NSString *message = nil;
1455 NSMutableDictionary *userInfo = nil;
1456
1457 message = [[NSString alloc] initWithFormat:format arguments:arguments];
1458
1459 userInfo = [NSMutableDictionary dictionaryWithDictionary:dict];
1460 [userInfo setObject:message forKey:NSLocalizedFailureReasonErrorKey];
1461 if (keyPath != NULL)
1462 {
1463 [userInfo setObject:KeyPathToArray(*keyPath) forKey:kPListKeyPathErrorKey];
1464 }
1465
1466 [message release];
1467
1468 return [NSError errorWithDomain:kOOPListSchemaVerifierErrorDomain code:errorCode userInfo:userInfo];
1469}

References nil.

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

+ Here is the caller graph for this function:

◆ ErrorWithProperty()

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

Definition at line 1421 of file OOPListSchemaVerifier.m.

1422{
1423 NSError *result = nil;
1424 va_list args;
1425 NSDictionary *dict = nil;
1426
1427 if (propKey != nil && propValue != nil)
1428 {
1429 dict = [NSDictionary dictionaryWithObject:propValue forKey:propKey];
1430 }
1431 va_start(args, format);
1432 result = ErrorWithDictionaryAndArguments(errorCode, keyPath, dict, format, args);
1433 va_end(args);
1434
1435 return result;
1436}

References ErrorWithDictionaryAndArguments(), and nil.

Referenced by ApplyStringFilter(), 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()

static BOOL IsFailureAlreadyReportedError ( NSError * error)
static

Definition at line 1503 of file OOPListSchemaVerifier.m.

1504{
1505 return [[error domain] isEqualToString:kOOPListSchemaVerifierErrorDomain] && [error code] == kPListErrorFailedAndErrorHasBeenReported;
1506}

References kPListErrorFailedAndErrorHasBeenReported.

◆ KeyPathToArray()

static NSArray * KeyPathToArray ( BackLinkChain keyPath)
static

Definition at line 724 of file OOPListSchemaVerifier.m.

725{
726 NSMutableArray *result = nil;
727 BackLinkChain *curr = NULL;
728
729 result = [NSMutableArray array];
730 for (curr = &keyPath; curr != NULL; curr = curr->link)
731 {
732 if (curr->element != nil) [result insertObject:curr->element atIndex:0];
733 }
734
735 return result;
736}
BackLinkChain * link

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

◆ KeyPathToString()

static NSString * KeyPathToString ( BackLinkChain keyPath)
static

Definition at line 739 of file OOPListSchemaVerifier.m.

740{
741 return [OOPListSchemaVerifier descriptionForKeyPath:KeyPathToArray(keyPath)];
742}
NSString * descriptionForKeyPath:(NSArray *keyPath)

References OOPListSchemaVerifier::descriptionForKeyPath:.

+ Here is the call graph for this function:

◆ SetForErrorReport()

static NSString * SetForErrorReport ( NSSet * set)
static

Definition at line 802 of file OOPListSchemaVerifier.m.

803{
804 return ArrayForErrorReport([[set allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]);
805}
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()

static NSString * StringForErrorReport ( NSString * string)
static

Definition at line 745 of file OOPListSchemaVerifier.m.

746{
747 id result = nil;
748
749 if (kMaximumLengthForStringInErrorMessage < [string length])
750 {
751 string = [string substringToIndex:kMaximumLengthForStringInErrorMessage];
752 }
753 result = [NSMutableString stringWithString:string];
754 [result replaceOccurrencesOfString:@"\t" withString:@" " options:0 range:NSMakeRange(0, [string length])];
755 [result replaceOccurrencesOfString:@"\r\n" withString:@" \\ " options:0 range:NSMakeRange(0, [string length])];
756 [result replaceOccurrencesOfString:@"\n" withString:@" \\ " options:0 range:NSMakeRange(0, [string length])];
757 [result replaceOccurrencesOfString:@"\r" withString:@" \\ " options:0 range:NSMakeRange(0, [string length])];
758
759 if (kMaximumLengthForStringInErrorMessage < [result length])
760 {
761 result = [result substringToIndex:kMaximumLengthForStringInErrorMessage - 3];
762 result = [result stringByAppendingString:@"..."];
763 }
764
765 return result;
766}

References kMaximumLengthForStringInErrorMessage, and nil.

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

+ Here is the caller graph for this function:

◆ StringOrArrayForErrorReport()

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

Definition at line 808 of file OOPListSchemaVerifier.m.

809{
810 if ([value isKindOfClass:[NSString class]])
811 {
812 return [NSString stringWithFormat:@"\"%@\"", StringForErrorReport(value)];
813 }
814
815 if (arrayPrefix == nil) arrayPrefix = @"";
816 if ([value isKindOfClass:[NSArray class]])
817 {
818 return [arrayPrefix stringByAppendingString:ArrayForErrorReport(value)];
819 }
820 if ([value isKindOfClass:[NSSet class]])
821 {
822 return [arrayPrefix stringByAppendingString:SetForErrorReport(value)];
823 }
824 if (value == nil) return @"(null)";
825 return @"<?>";
826}

References nil.

Referenced by Verify_String().

+ Here is the caller graph for this function:

◆ StringToSchemaType()

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

Definition at line 552 of file OOPListSchemaVerifier.m.

553{
554 static NSDictionary *typeMap = nil;
555 SchemaType result;
556
557 if (typeMap == nil)
558 {
559 typeMap =
560 [[NSDictionary dictionaryWithObjectsAndKeys:
561 [NSNumber numberWithUnsignedInt:kTypeString], @"string",
562 [NSNumber numberWithUnsignedInt:kTypeArray], @"array",
563 [NSNumber numberWithUnsignedInt:kTypeDictionary], @"dictionary",
564 [NSNumber numberWithUnsignedInt:kTypeInteger], @"integer",
565 [NSNumber numberWithUnsignedInt:kTypePositiveInteger], @"positiveInteger",
566 [NSNumber numberWithUnsignedInt:kTypeFloat], @"float",
567 [NSNumber numberWithUnsignedInt:kTypePositiveFloat], @"positiveFloat",
568 [NSNumber numberWithUnsignedInt:kTypeOneOf], @"oneOf",
569 [NSNumber numberWithUnsignedInt:kTypeEnumeration], @"enumeration",
570 [NSNumber numberWithUnsignedInt:kTypeBoolean], @"boolean",
571 [NSNumber numberWithUnsignedInt:kTypeFuzzyBoolean], @"fuzzyBoolean",
572 [NSNumber numberWithUnsignedInt:kTypeVector], @"vector",
573 [NSNumber numberWithUnsignedInt:kTypeQuaternion], @"quaternion",
574 [NSNumber numberWithUnsignedInt:kTypeDelegatedType], @"delegatedType",
575 nil
576 ] retain];
577 }
578
579 result = [[typeMap objectForKey:string] unsignedIntValue];
580 if (result == kTypeUnknown && outError != NULL)
581 {
582 if ([string hasPrefix:@"$"])
583 {
584 *outError = ErrorWithProperty(kPListErrorSchemaUnknownType, NULL, kUnknownTypeErrorKey, string, @"Bad schema: unresolved macro reference \"%@\".", string);
585 }
586 else
587 {
588 *outError = ErrorWithProperty(kPListErrorSchemaUnknownType, NULL, kUnknownTypeErrorKey, string, @"Bad schema: unknown type \"%@\".", string);
589 }
590 }
591
592 return result;
593}
@ kPListErrorSchemaUnknownType
NSString *const kUnknownTypeErrorKey

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

+ Here is the call graph for this function:

◆ Verify_Array()

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

Definition at line 904 of file OOPListSchemaVerifier.m.

905{
906 id valueType = nil;
907 BOOL OK = YES, stop = NO;
908 NSUInteger i, count;
909 id subProperty = nil;
910 NSUInteger constraint;
911
912 REQUIRE_TYPE(NSArray, @"array");
913
914 DebugDump(@"%@", @"* array");
915
916 // Apply count bounds.
917 count = [value count];
918 constraint = [params oo_unsignedIntegerForKey:@"minCount" defaultValue:0];
919 if (count < constraint)
920 {
921 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Array has too few members (%u, minimum is %u).", count, constraint);
922 }
923
924 constraint = [params oo_unsignedIntegerForKey:@"maxCount" defaultValue:NSUIntegerMax];
925 if (constraint < count)
926 {
927 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Array has too many members (%u, maximum is %u).", count, constraint);
928 }
929
930 // Test member objects.
931 valueType = [params objectForKey:@"valueType"];
932 if (valueType != nil)
933 {
934 for (i = 0; i != count; ++i)
935 {
936 subProperty = [value objectAtIndex:i];
937
938 if (![verifier verifyPList:rootPList
939 named:name
940 subProperty:subProperty
941 againstSchemaType:valueType
942 atPath:BackLinkIndex(&keyPath, i)
943 tentative:tentative
944 error:NULL
945 stop:&stop])
946 {
947 OK = NO;
948 }
949
950 if ((stop && !tentative) || (tentative && !OK)) break;
951 }
952 }
953
954 *outStop = stop && !tentative;
955
956 if (!OK) return ErrorFailureAlreadyReported();
957 else return nil;
958}
@ 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()

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

Definition at line 1284 of file OOPListSchemaVerifier.m.

1285{
1286 DebugDump(@"* boolean: %@", value);
1287
1288 // Check basic parseability. If there's inequality here, the default value is being returned.
1289 if (OOBooleanFromObject(value, 0) == OOBooleanFromObject(value, 1)) return nil;
1290 else return ErrorTypeMismatch([NSNumber class], @"boolean", value, keyPath);
1291}
BOOL OOBooleanFromObject(id object, BOOL defaultValue)

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

+ Here is the call graph for this function:

◆ Verify_DelegatedType()

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

Definition at line 1325 of file OOPListSchemaVerifier.m.

1326{
1327 id baseType = nil;
1328 NSString *key = nil;
1329 BOOL stop = NO;
1330 NSError *error = nil;
1331
1332 DebugDump(@"* delegated type: %@", [params objectForKey:@"key"]);
1333
1334 baseType = [params objectForKey:@"baseType"];
1335 if (baseType != nil)
1336 {
1337 if (![verifier verifyPList:rootPList
1338 named:name
1339 subProperty:value
1340 againstSchemaType:baseType
1341 atPath:keyPath
1342 tentative:tentative
1343 error:NULL
1344 stop:&stop])
1345 {
1346 *outStop = stop;
1347 return nil;
1348 }
1349 }
1350
1351 key = [params objectForKey:@"key"];
1352 *outStop = ![verifier delegateVerifierWithPropertyList:rootPList
1353 named:name
1354 testProperty:value
1355 atPath:keyPath
1356 againstType:key
1357 error:&error];
1358 return error;
1359}

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

+ Here is the call graph for this function:

◆ Verify_Dictionary()

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

Definition at line 961 of file OOPListSchemaVerifier.m.

962{
963 NSDictionary *schema = nil;
964 id valueType = nil,
965 typeSpec = nil;
966 NSEnumerator *keyEnum = nil;
967 NSString *key = nil;
968 id subProperty = nil;
969 BOOL OK = YES, stop = NO, prematureExit = NO;
970 BOOL allowOthers;
971 NSMutableSet *requiredKeys = nil;
972 NSArray *requiredKeyList = nil;
973 NSUInteger count, constraint;
974
975 REQUIRE_TYPE(NSDictionary, @"dictionary");
976
977 DebugDump(@"%@", @"* dictionary");
978
979 // Apply count bounds.
980 count = [value count];
981 constraint = [params oo_unsignedIntegerForKey:@"minCount" defaultValue:0];
982 if (count < constraint)
983 {
984 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Dictionary has too few pairs (%u, minimum is %u).", count, constraint);
985 }
986 constraint = [params oo_unsignedIntegerForKey:@"maxCount" defaultValue:NSUIntegerMax];
987 if (constraint < count)
988 {
989 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Dictionary has too manu pairs (%u, maximum is %u).", count, constraint);
990 }
991
992 // Get schema.
993 schema = [params oo_dictionaryForKey:@"schema"];
994 valueType = [params objectForKey:@"valueType"];
995 allowOthers = [params oo_boolForKey:@"allowOthers" defaultValue:YES];
996 requiredKeyList = [params oo_arrayForKey:@"requiredKeys"];
997
998 // If these conditions are met, all members must pass:
999 if (schema == nil && valueType == nil && requiredKeyList == nil && allowOthers) return nil;
1000
1001 if (requiredKeyList != nil)
1002 {
1003 requiredKeys = [NSMutableSet setWithArray:requiredKeyList];
1004 }
1005
1007
1008 // Test member objects.
1009 for (keyEnum = [value keyEnumerator]; (key = [keyEnum nextObject]) && !stop; )
1010 {
1011 subProperty = [(NSDictionary *)value objectForKey:key];
1012 typeSpec = [schema objectForKey:key];
1013 if (typeSpec == nil) typeSpec = valueType;
1014
1015 DebugDump(@"- \"%@\"", key);
1017
1018 if (typeSpec != nil)
1019 {
1020 if (![verifier verifyPList:rootPList
1021 named:name
1022 subProperty:subProperty
1023 againstSchemaType:typeSpec
1024 atPath:BackLink(&keyPath, key)
1025 tentative:tentative
1026 error:NULL
1027 stop:&stop])
1028 {
1029 OK = NO;
1030 }
1031 }
1032 else if (!allowOthers && ![requiredKeys containsObject:key] && [schema objectForKey:key] == nil)
1033 {
1034 // Report error now rather than returning it, since there may be several unknown keys.
1035 if (!tentative)
1036 {
1037 NSError *error = ErrorWithProperty(kPListErrorDictionaryUnknownKey, &keyPath, kUnknownKeyErrorKey, key, @"Unpermitted key \"%@\" in dictionary.", StringForErrorReport(key));
1038 stop = ![verifier delegateVerifierWithPropertyList:rootPList
1039 named:name
1040 failedForProperty:value
1041 withError:error
1042 expectedType:params];
1043 }
1044 OK = NO;
1045 }
1046
1048
1049 [requiredKeys removeObject:key];
1050
1051 if ((stop && !tentative) || (tentative && !OK))
1052 {
1053 prematureExit = YES;
1054 break;
1055 }
1056 }
1057
1059
1060 // Check that all required keys were present.
1061 if (!prematureExit && [requiredKeys count] != 0)
1062 {
1063 return ErrorWithProperty(kPListErrorDictionaryMissingRequiredKeys, &keyPath, kMissingRequiredKeysErrorKey, requiredKeys, @"Required keys %@ missing from dictionary.", SetForErrorReport(requiredKeys));
1064 }
1065
1066 *outStop = stop && !tentative;
1067
1068 if (!OK) return ErrorFailureAlreadyReported();
1069 else return nil;
1070}
@ kPListErrorDictionaryMissingRequiredKeys
@ kPListErrorDictionaryUnknownKey
NSString *const kMissingRequiredKeysErrorKey
static NSString * SetForErrorReport(NSSet *set)
static NSString * StringForErrorReport(NSString *string)
OOINLINE BackLinkChain BackLink(BackLinkChain *link, id element)
#define DebugDumpIndent()
NSString *const kUnknownKeyErrorKey
#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()

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

Definition at line 1256 of file OOPListSchemaVerifier.m.

1257{
1258 NSArray *values = nil;
1259 NSString *filteredString = nil;
1260 NSError *error = nil;
1261
1262 DebugDump(@"%@", @"* enumeration");
1263
1264 REQUIRE_TYPE(NSString, @"string");
1265
1266 values = [params oo_arrayForKey:@"values"];
1267 DebugDump(@" - \"%@\" in %@", StringForErrorReport(value), ArrayForErrorReport(values));
1268
1269 if (values == nil)
1270 {
1271 *outStop = YES;
1272 return Error(kPListErrorSchemaNoEnumerationValues, &keyPath, @"Bad schema: no options specified for oneOf type.");
1273 }
1274
1275 filteredString = ApplyStringFilter(value, [params objectForKey:@"filter"], keyPath, &error);
1276 if (filteredString == nil) return error;
1277
1278 if ([values containsObject:filteredString]) return nil;
1279
1280 return Error(kPListErrorEnumerationBadValue, &keyPath, @"Value \"%@\" not recognized, should be one of %@.", StringForErrorReport(value), ArrayForErrorReport(values));
1281}
@ 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()

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

Definition at line 1137 of file OOPListSchemaVerifier.m.

1138{
1139 double numericValue;
1140 double constraint;
1141
1142 numericValue = OODoubleFromObject(value, 0);
1143
1144 DebugDump(@"* float: %g", numericValue);
1145
1146 // Check basic parseability. If there's inequality here, the default value is being returned.
1147 if (numericValue != OODoubleFromObject(value, 1))
1148 {
1149 return ErrorTypeMismatch([NSNumber class], @"number", value, keyPath);
1150 }
1151
1152 // Check constraints.
1153 constraint = [params oo_doubleForKey:@"minimum" defaultValue:-INFINITY];
1154 if (numericValue < constraint)
1155 {
1156 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Number is too small (%g, minimum is %g).", numericValue, constraint);
1157 }
1158
1159 constraint = [params oo_doubleForKey:@"maximum" defaultValue:INFINITY];
1160 if (constraint < numericValue)
1161 {
1162 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Number is too large (%g, maximum is %g).", numericValue, constraint);
1163 }
1164
1165 return nil;
1166}
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()

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

Definition at line 1294 of file OOPListSchemaVerifier.m.

1295{
1296 DebugDump(@"* fuzzy boolean: %@", value);
1297
1298 // Check basic parseability. If there's inequality here, the default value is being returned.
1299 if (OODoubleFromObject(value, 0) == OODoubleFromObject(value, 1)) return nil;
1300 else if (OOBooleanFromObject(value, 0) == OOBooleanFromObject(value, 1)) return nil;
1301 else return ErrorTypeMismatch([NSNumber class], @"fuzzy boolean", value, keyPath);
1302}

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

+ Here is the call graph for this function:

◆ Verify_Integer()

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

Definition at line 1073 of file OOPListSchemaVerifier.m.

1074{
1075 long long numericValue;
1076 long long constraint;
1077
1078 numericValue = OOLongLongFromObject(value, 0);
1079
1080 DebugDump(@"* integer: %lli", numericValue);
1081
1082 // Check basic parseability. If there's inequality here, the default value is being returned.
1083 if (numericValue != OOLongLongFromObject(value, 1))
1084 {
1085 return ErrorTypeMismatch([NSNumber class], @"integer", value, keyPath);
1086 }
1087
1088 // Check constraints.
1089 constraint = [params oo_longLongForKey:@"minimum" defaultValue:LLONG_MIN];
1090 if (numericValue < constraint)
1091 {
1092 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Number is too small (%lli, minimum is %lli).", numericValue, constraint);
1093 }
1094
1095 constraint = [params oo_longLongForKey:@"maximum" defaultValue:LLONG_MAX];
1096 if (constraint < numericValue)
1097 {
1098 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Number is too large (%lli, maximum is %lli).", numericValue, constraint);
1099 }
1100
1101 return nil;
1102}
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()

static NSError * Verify_OneOf ( 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 NSArray *options = nil;
1209 BOOL OK = NO, stop = NO;
1210 NSEnumerator *optionEnum = nil;
1211 id option = nil;
1212 NSError *error;
1213 NSMutableDictionary *errors = nil;
1214
1215 DebugDump(@"%@", @"* oneOf");
1216
1217 options = [params oo_arrayForKey:@"options"];
1218 if (options == nil)
1219 {
1220 *outStop = YES;
1221 return Error(kPListErrorSchemaNoOneOfOptions, &keyPath, @"Bad schema: no options specified for oneOf type.");
1222 }
1223
1224 errors = [[NSMutableDictionary alloc] initWithCapacity:[options count]];
1225
1226 for (optionEnum = [options objectEnumerator]; (option = [optionEnum nextObject]) ;)
1227 {
1228 if ([verifier verifyPList:rootPList
1229 named:name
1230 subProperty:value
1231 againstSchemaType:option
1232 atPath:keyPath
1233 tentative:YES
1234 error:&error
1235 stop:&stop])
1236 {
1237 DebugDump(@"%@", @"> Match.");
1238 OK = YES;
1239 break;
1240 }
1241 [errors setObject:error forKey:option];
1242 }
1243
1244 if (!OK)
1245 {
1246 DebugDump(@"%@", @"! No match.");
1247 return ErrorWithProperty(kPListErrorOneOfNoMatch, &keyPath, kErrorsByOptionErrorKey, [errors autorelease], @"No matching type rule could be found.");
1248 }
1249
1250 // Ignore stop in tentatives.
1251 [errors release];
1252 return nil;
1253}
@ kPListErrorSchemaNoOneOfOptions
@ kPListErrorOneOfNoMatch
NSString *const kErrorsByOptionErrorKey

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

+ Here is the call graph for this function:

◆ Verify_PositiveFloat()

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

Definition at line 1169 of file OOPListSchemaVerifier.m.

1170{
1171 double numericValue;
1172 double constraint;
1173
1174 numericValue = OODoubleFromObject(value, 0);
1175
1176 DebugDump(@"* positive float: %g", numericValue);
1177
1178 // Check basic parseability. If there's inequality here, the default value is being returned.
1179 if (numericValue != OODoubleFromObject(value, 1))
1180 {
1181 return ErrorTypeMismatch([NSNumber class], @"positive number", value, keyPath);
1182 }
1183
1184 if (numericValue < 0)
1185 {
1186 return Error(kPListErrorNumberIsNegative, &keyPath, @"Expected non-negative number, found %g.", numericValue);
1187 }
1188
1189 // Check constraints.
1190 constraint = [params oo_doubleForKey:@"minimum" defaultValue:0];
1191 if (numericValue < constraint)
1192 {
1193 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Number is too small (%g, minimum is %g).", numericValue, constraint);
1194 }
1195
1196 constraint = [params oo_doubleForKey:@"maximum" defaultValue:INFINITY];
1197 if (constraint < numericValue)
1198 {
1199 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Number is too large (%g, maximum is %g).", numericValue, constraint);
1200 }
1201
1202 return nil;
1203}
@ kPListErrorNumberIsNegative

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

+ Here is the call graph for this function:

◆ Verify_PositiveInteger()

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

Definition at line 1105 of file OOPListSchemaVerifier.m.

1106{
1107 unsigned long long numericValue;
1108 unsigned long long constraint;
1109
1110 numericValue = OOUnsignedLongLongFromObject(value, 0);
1111
1112 DebugDump(@"* positive integer: %llu", numericValue);
1113
1114 // Check basic parseability. If there's inequality here, the default value is being returned.
1115 if (numericValue != OOUnsignedLongLongFromObject(value, 1))
1116 {
1117 return ErrorTypeMismatch([NSNumber class], @"positive integer", value, keyPath);
1118 }
1119
1120 // Check constraints.
1121 constraint = [params oo_unsignedLongLongForKey:@"minimum" defaultValue:0];
1122 if (numericValue < constraint)
1123 {
1124 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Number is too small (%llu, minimum is %llu).", numericValue, constraint);
1125 }
1126
1127 constraint = [params oo_unsignedLongLongForKey:@"maximum" defaultValue:ULLONG_MAX];
1128 if (constraint < numericValue)
1129 {
1130 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Number is too large (%llu, maximum is %llu).", numericValue, constraint);
1131 }
1132
1133 return nil;
1134}
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()

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

Definition at line 1315 of file OOPListSchemaVerifier.m.

1316{
1317 DebugDump(@"* quaternion: %@", value);
1318
1319 // Check basic parseability. If there's inequality here, the default value is being returned.
1320 if (quaternion_equal(OOQuaternionFromObject(value, kZeroQuaternion), OOQuaternionFromObject(value, kIdentityQuaternion))) return nil;
1321 else return ErrorTypeMismatch(Nil, @"quaternion", value, keyPath);
1322}
Quaternion OOQuaternionFromObject(id object, Quaternion defaultValue)
const Quaternion kIdentityQuaternion
const Quaternion kZeroQuaternion

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

+ Here is the call graph for this function:

◆ Verify_String()

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

Definition at line 838 of file OOPListSchemaVerifier.m.

839{
840 NSString *filteredString = nil;
841 id testValue = nil;
842 NSUInteger length;
843 NSUInteger lengthConstraint;
844 NSError *error = nil;
845
846 REQUIRE_TYPE(NSString, @"string");
847
848 DebugDump(@"* string: \"%@\"", StringForErrorReport(value));
849
850 // Apply filters
851 filteredString = ApplyStringFilter(value, [params objectForKey:@"filter"], keyPath, &error);
852 if (filteredString == nil) return error;
853
854 // Apply substring requirements
855 testValue = [params objectForKey:@"requiredPrefix"];
856 if (testValue != nil)
857 {
858 if (!ApplyStringTest(filteredString, testValue, @selector(hasPrefix:), @"prefix", keyPath, &error))
859 {
860 if (error == nil) error = ErrorWithProperty(kPListErrorStringPrefixMissing, &keyPath, kMissingSubStringErrorKey, testValue, @"String \"%@\" does not have required %@ %@.", StringForErrorReport(value), @"prefix", StringOrArrayForErrorReport(testValue, @"in "));
861 return error;
862 }
863 }
864
865 testValue = [params objectForKey:@"requiredSuffix"];
866 if (testValue != nil)
867 {
868 if (!ApplyStringTest(filteredString, testValue, @selector(hasSuffix:), @"suffix", keyPath, &error))
869 {
870 if (error == nil) error = ErrorWithProperty(kPListErrorStringSuffixMissing, &keyPath, kMissingSubStringErrorKey, testValue, @"String \"%@\" does not have required %@ %@.", StringForErrorReport(value), @"suffix", StringOrArrayForErrorReport(testValue, @"in "));
871 return error;
872 }
873 }
874
875 testValue = [params objectForKey:@"requiredSubString"];
876 if (testValue != nil)
877 {
878 if (!ApplyStringTest(filteredString, testValue, @selector(ooPListVerifierHasSubString:), @"substring", keyPath, &error))
879 {
880 if (error == nil) error = ErrorWithProperty(kPListErrorStringSubstringMissing, &keyPath, kMissingSubStringErrorKey, testValue, @"String \"%@\" does not have required %@ %@.", StringForErrorReport(value), @"substring", StringOrArrayForErrorReport(testValue, @"in "));
881 return error;
882 }
883 }
884
885 // Apply length bounds.
886 length = [filteredString length];
887 lengthConstraint = [params oo_unsignedIntegerForKey:@"minLength"];
888 if (length < lengthConstraint)
889 {
890 return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"String \"%@\" is too short (%u bytes, minimum is %u).", StringForErrorReport(filteredString), length, lengthConstraint);
891 }
892
893 lengthConstraint = [params oo_unsignedIntegerForKey:@"maxLength" defaultValue:NSUIntegerMax];
894 if (lengthConstraint < length)
895 {
896 return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"String \"%@\" is too long (%u bytes, maximum is %u).", StringForErrorReport(filteredString), length, lengthConstraint);
897 }
898
899 // All tests passed.
900 return nil;
901}
@ kPListErrorStringSubstringMissing
@ kPListErrorStringSuffixMissing
@ kPListErrorStringPrefixMissing
static BOOL ApplyStringTest(NSString *string, id test, SEL testSelector, NSString *testDescription, BackLinkChain keyPath, NSError **outError)
static NSString * StringOrArrayForErrorReport(id value, NSString *arrayPrefix)
NSString *const kMissingSubStringErrorKey

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()

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

Definition at line 1305 of file OOPListSchemaVerifier.m.

1306{
1307 DebugDump(@"* vector: %@", value);
1308
1309 // Check basic parseability. If there's inequality here, the default value is being returned.
1310 if (vector_equal(OOVectorFromObject(value, kZeroVector), OOVectorFromObject(value, kBasisXVector))) return nil;
1311 else return ErrorTypeMismatch(Nil, @"vector", value, keyPath);
1312}
Vector OOVectorFromObject(id object, Vector defaultValue)
const Vector kZeroVector
Definition OOVector.m:28
const Vector kBasisXVector
Definition OOVector.m:29

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

+ Here is the call graph for this function:

Variable Documentation

◆ kErrorsByOptionErrorKey

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

Definition at line 85 of file OOPListSchemaVerifier.m.

Referenced by Verify_OneOf().

◆ kExpectedClassErrorKey

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

Definition at line 79 of file OOPListSchemaVerifier.m.

◆ kExpectedClassNameErrorKey

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

Definition at line 80 of file OOPListSchemaVerifier.m.

◆ kMissingRequiredKeysErrorKey

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

Definition at line 82 of file OOPListSchemaVerifier.m.

Referenced by Verify_Dictionary().

◆ kMissingSubStringErrorKey

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

Definition at line 83 of file OOPListSchemaVerifier.m.

Referenced by Verify_String().

◆ kOOPListSchemaVerifierErrorDomain

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

Definition at line 74 of file OOPListSchemaVerifier.m.

◆ kPListKeyPathErrorKey

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

Definition at line 76 of file OOPListSchemaVerifier.m.

◆ kSchemaKeyPathErrorKey

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

Definition at line 77 of file OOPListSchemaVerifier.m.

◆ kUndefinedMacroErrorKey

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

Definition at line 88 of file OOPListSchemaVerifier.m.

◆ kUnknownKeyErrorKey

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

Definition at line 81 of file OOPListSchemaVerifier.m.

Referenced by Verify_Dictionary().

◆ kUnknownTypeErrorKey

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

Definition at line 87 of file OOPListSchemaVerifier.m.

Referenced by StringToSchemaType().

◆ kUnnownFilterErrorKey

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

Definition at line 84 of file OOPListSchemaVerifier.m.

Referenced by ApplyStringFilter().

◆ sDebugDump

BOOL sDebugDump = NO
static

Definition at line 58 of file OOPListSchemaVerifier.m.