BLIP/BLIPProperties.h
author Jens Alfke <jens@mooseyard.com>
Sun May 10 19:05:52 2009 -0700 (2009-05-10)
changeset 46 50dc5502ef46
parent 0 9d67172bb323
permissions -rw-r--r--
Unnecessary self-merge (I'm just being confused with hg. Sorry.)
     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     @private
    49     NSMutableDictionary *_properties;
    50 }
    51 
    52 /** Initializes a new instance, adding all the key/value pairs from the given NSDictionary. */
    53 - (id) initWithDictionary: (NSDictionary*)dict;
    54 
    55 /** Sets the value of a property. A nil value is allowed, and removes the property. */
    56 - (void) setValue: (NSString*)value ofProperty: (NSString*)prop;
    57 
    58 /** Sets the receiver's key/value pairs from the given NSDictionary.
    59     All previously existing properties are removed first. */
    60 - (void) setAllProperties: (NSDictionary*)properties;
    61 
    62 @end