/* ** GeneralContainer.h ** ** Copyright (c) 2004 ** ** Author: Yen-Ju Chen ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __GeneralContainer__ #define __GeneralContainer__ /* GeneralContainer suits for data structure having NSArray of NSDictionary. * Each NSDictionary has a TitleKey for key. * Subclass of GeneralContainer can add more key for its usage. * All the data in and out container is copied. * Key must be NSString. */ #include #include @class NSMutableArray; static NSString *TitleKey = @"TitleKey"; static NSString *UniqueNumberKey = @"UniqueNumberKey"; /* Backup */ void makeBackup (NSString *path); @interface GeneralContainer: NSObject { NSMutableArray *container; NSString *containerPath; } - (unsigned int) uniqueNumber; /* low-level methods */ - (void) sortTitle: (NSComparisonResult) order; - (BOOL) isDuplicatedTitle: (NSString *) title; - (BOOL) isDuplicatedTitle: (NSString *) title skipIndex: (unsigned int) index; /* return index after add object */ - (unsigned int) addObject: (id) object forKey: (id) key; - (unsigned int) addObject: (id) object atIndex: (unsigned int) index forKey: (id) key; - (void) setObject: (id) object atIndex: (unsigned int) index forKey: (id) key; - (id) objectAtIndex: (unsigned int) index forKey: (id) key; - (void) removeObjectAtIndex: (unsigned int) index; - (void) removeObjectForKey: (id) key atIndex: (unsigned int) index; - (unsigned int) count; /* Unique number */ - (void) setUniqueNumber: (unsigned int) uid atIndex: (unsigned int) index; - (unsigned int) uniqueNumberAtIndex: (unsigned int) index; - (unsigned int) indexOfUniqueNumber: (unsigned int) uid; /* write accessory */ - (unsigned int) newTitle: (NSString *) title; - (unsigned int) newTitle: (NSString *) title atIndex: (unsigned int) index; - (void) setTitle: (NSString *) title atIndex: (unsigned int) index; /* read accessory */ - (NSString *) titleAtIndex: (unsigned int) index; - (unsigned int) indexOfTitle: (NSString *) title; /* read from files*/ - (BOOL) readFromFile: (NSString *) absolutePath; - (BOOL) loadSourceAtPath: (NSString *) absolutePath; /* used for unload source or export source */ - (BOOL) writeToFile: (NSString *) absolutePath; /* will call unloadSourceAtPath. * if absolutePath == nil, use the path from -loadSourceAtPath */ - (BOOL) unloadSourceAtPath: (NSString *) absolutePath; - (NSString *) path; @end #endif /* __GeneralContainer__ */