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