GNUstep Core Data  0.1
CoreDataUtilities.h
00001 /* Declarations of utility functions for the GNUstep Core Data framework.
00002    Copyright (C) 2005 Free Software Foundation, Inc.
00003 
00004    Written by:  Saso Kiselkov <diablos@manga.sk>
00005    Date: August 2005
00006 
00007    This file is part of the GNUstep Core Data framework.
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Lesser General Public
00011    License as published by the Free Software Foundation; either
00012    version 2.1 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Lesser General Public License for more details.
00018 
00019    You should have received a copy of the GNU Lesser General Public
00020    License along with this library; if not, write to the Free
00021    Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
00022 */
00023 
00024 #ifndef _CoreDataUtilities_h_
00025 #define _CoreDataUtilities_h_
00026 
00027 @class NSError, NSString;
00028 
00035 static inline void
00036 SetNonNullError (NSError ** ptr, NSError * error)
00037 {
00038   if (ptr != NULL)
00039     {
00040       *ptr = error;
00041     }
00042 }
00043 
00053 static inline BOOL
00054 ObjectMatchedByFetchRequest (NSManagedObject * object,
00055                              NSFetchRequest * fetchRequest)
00056 {
00057   NSEntityDescription * entity = [fetchRequest entity];
00058   NSPredicate * predicate = [fetchRequest predicate];
00059   NSArray * affectedStores = [fetchRequest affectedStores];
00060 
00061   if (entity != nil)
00062     {
00063       if ([[object entity] isEqual: entity] == NO)
00064         {
00065           return NO;
00066         }
00067     }
00068 
00069   if (predicate != nil)
00070     {
00071       if ([predicate evaluateWithObject: object] == NO)
00072         {
00073           return NO;
00074         }
00075     }
00076 
00077   if (affectedStores != nil)
00078     {
00079       if ([affectedStores containsObject: [[object objectID]
00080         persistentStore]] == NO)
00081         {
00082           return NO;
00083         }
00084     }
00085 
00086   return YES;
00087 }
00088 
00089 #endif // _CoreDataUtilities_h_