BLIP/BLIPProperties.h
author Jens Alfke <jens@mooseyard.com>
Sun Jul 13 10:59:06 2008 -0700 (2008-07-13)
changeset 23 ffdaa33a408a
child 26 cb9cdf247239
permissions -rw-r--r--
Merged 1.0 final into 1.1 branch.
     1 //
     2 //  BLIPProperties.h
     3 //  MYNetwork
     4 //
     5 //  Created by Jens Alfke on 5/13/08.
     6 //  Copyright 2008 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import <Foundation/Foundation.h>
    10 
    11 
    12 /** A key/value property store, like a set of MIME or RFC822 headers (but without the weird details).
    13     It can be written to or read from a block of data; the data is binary, not the textual
    14     format that MIME uses. */
    15 @interface BLIPProperties : NSObject <NSCopying, NSMutableCopying>
    16 
    17 /** Parse properties from a block of data.
    18     On success, returns a Properties object and sets *usedLength to the number of bytes of
    19     data consumed.
    20     If the data doesn't contain the complete properties, returns nil and sets *usedLength to zero.
    21     If the properties are syntactically invalid, returns nil and sets *usedLength to a negative number.
    22 */
    23 + (BLIPProperties*) propertiesWithEncodedData: (NSData*)data
    24                                    usedLength: (ssize_t*)usedLength;
    25 
    26 /** Returns an empty autoreleased instance. */
    27 + (BLIPProperties*) properties;
    28 
    29 /** Property value lookup. (Case-sensitive, like NSDictionary, but unlike RFC822.) */
    30 - (NSString*) valueOfProperty: (NSString*)prop;
    31 
    32 /** Returns all the properties/values as a dictionary. */
    33 @property (readonly) NSDictionary* allProperties;
    34 
    35 /** The number of properties. */
    36 @property (readonly) NSUInteger count;
    37 
    38 /** The raw data representation of the properties. */
    39 @property (readonly) NSData *encodedData;
    40 
    41 @end
    42 
    43 
    44 
    45 /** Mutable subclass of BLIPProperties, used for creating new instances. */
    46 @interface BLIPMutableProperties : BLIPProperties
    47 {
    48     NSMutableDictionary *_properties;
    49 }
    50 
    51 /** Initializes a new instance, adding all the key/value pairs from the given NSDictionary. */
    52 - (id) initWithDictionary: (NSDictionary*)dict;
    53 
    54 /** Sets the value of a property. A nil value is allowed, and removes the property. */
    55 - (void) setValue: (NSString*)value ofProperty: (NSString*)prop;
    56 
    57 /** Sets the receiver's key/value pairs from the given NSDictionary.
    58     All previously existing properties are removed first. */
    59 - (void) setAllProperties: (NSDictionary*)properties;
    60 
    61 @end