Changeset 28250


Ignore:
Timestamp:
Aug 26, 2007, 9:36:05 AM (13 years ago)
Author:
rhwood@…
Message:

MPObject now based on DPObject from PortsManager instead of DPCocoa

Location:
users/rhwood/Pallet/MPTool
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • users/rhwood/Pallet/MPTool/MPObject.h

    r23417 r28250  
    1 //
    2 //  MPObject.h
    3 //  DarwinPorts
    4 //
    51/*
    6  Copyright (c) 2003 Apple Computer, Inc.
    7  All rights reserved.
    8 
    9  Redistribution and use in source and binary forms, with or without
    10  modification, are permitted provided that the following conditions
    11  are met:
    12  1. Redistributions of source code must retain the above copyright
    13  notice, this list of conditions and the following disclaimer.
    14  2. Redistributions in binary form must reproduce the above copyright
    15  notice, this list of conditions and the following disclaimer in the
    16  documentation and/or other materials provided with the distribution.
    17  3. Neither the name of Apple Computer, Inc. nor the names of its contributors
    18  may be used to endorse or promote products derived from this software
    19  without specific prior written permission.
    20 
    21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    22  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    23  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    24  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    25  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    26  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    27  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    28  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    29  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    30  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    31  POSSIBILITY OF SUCH DAMAGE.
     2 * MPObject.h
     3 * DarwinPorts
     4 *
     5 * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
     6 *
     7 * Redistribution and use in source and binary forms, with or without
     8 * modification, are permitted provided that the following conditions
     9 * are met:
     10 *
     11 * 1. Redistributions of source code must retain the above copyright
     12 *    notice, this list of conditions and the following disclaimer.
     13 * 2. Redistributions in binary form must reproduce the above copyright
     14 *    notice, this list of conditions and the following disclaimer in the
     15 *    documentation and/or other materials provided with the distribution.
     16 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     17 *    its contributors may be used to endorse or promote products derived
     18 *    from this software without specific prior written permission.
     19 *
     20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3230 */
    3331
     
    3836{
    3937@private
     38    char *_cString;
    4039    NSString *_cocoaString; 
    4140    NSDictionary *_cocoaDictionary; 
     
    5251- (char *) cString;
    5352- (NSString *) stringValue;
     53- (NSDictionary *) dictionaryValue;
    5454
    5555/** comparisons **/
  • users/rhwood/Pallet/MPTool/MPObject.m

    r23417 r28250  
    1 //
    2 //  MPObject.m
    3 //  DarwinPorts
    4 //
    51/*
    6  Copyright (c) 2003 Apple Computer, Inc.
    7  All rights reserved.
    8  
    9  Redistribution and use in source and binary forms, with or without
    10  modification, are permitted provided that the following conditions
    11  are met:
    12  1. Redistributions of source code must retain the above copyright
    13     notice, this list of conditions and the following disclaimer.
    14  2. Redistributions in binary form must reproduce the above copyright
    15     notice, this list of conditions and the following disclaimer in the
    16     documentation and/or other materials provided with the distribution.
    17  3. Neither the name of Apple Computer, Inc. nor the names of its contributors
    18     may be used to endorse or promote products derived from this software
    19     without specific prior written permission.
    20  
    21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    22  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    23  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    24  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    25  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    26  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    27  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    28  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    29  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    30  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    31  POSSIBILITY OF SUCH DAMAGE.
     2 * MPObject.m
     3 * DarwinPorts
     4 *
     5 * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
     6 *
     7 * Redistribution and use in source and binary forms, with or without
     8 * modification, are permitted provided that the following conditions
     9 * are met:
     10 *
     11 * 1. Redistributions of source code must retain the above copyright
     12 *    notice, this list of conditions and the following disclaimer.
     13 * 2. Redistributions in binary form must reproduce the above copyright
     14 *    notice, this list of conditions and the following disclaimer in the
     15 *    documentation and/or other materials provided with the distribution.
     16 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     17 *    its contributors may be used to endorse or promote products derived
     18 *    from this software without specific prior written permission.
     19 *
     20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3230 */
    3331
     
    4644+ (MPObject *) objectWithString: (NSString *)string
    4745{
    48     static NSMutableDictionary *cachedObjects;
    49     MPObject *object = nil;
    50     if (!cachedObjects)
    51     {
    52         cachedObjects = [[NSMutableDictionary alloc] init];
    53     }
    54     object = [cachedObjects objectForKey: string];
    55     if (!object)
    56     {
    57         const char *cString = [string cString];
    58         Tcl_Obj *tclObj = Tcl_NewStringObj(cString, strlen(cString));
    59         object = [[[self alloc] initWithTclObj: tclObj] autorelease];
    60         [cachedObjects setObject: object forKey: string];
    61     }
     46    const char *cString = [string cString];
     47    Tcl_Obj *tclObj = Tcl_NewStringObj(cString, strlen(cString));
     48    MPObject *object = [[[self alloc] initWithTclObj: tclObj] autorelease];
     49   
    6250    return object;
    6351}
     
    8573    Tcl_DecrRefCount(_tclObj);
    8674    [_cocoaString release];
    87     [_cocoaDictionary release];
     75    if (_cString != NULL)
     76        free(_cString);
    8877    [super dealloc];
    8978}
     
    10190- (char *) cString
    10291{
    103     return Tcl_GetString(_tclObj);
     92    /*
     93     * Tcl_Obj value pointers are only safe
     94     * until the next Tcl_Get*FromObj call.
     95     */
     96    if (_cString == NULL) {
     97        _cString = strdup(Tcl_GetStringFromObj(_tclObj, NULL));
     98    }
     99    return _cString;
    104100}
    105101
     
    112108    }
    113109    return _cocoaString;
     110}
     111
     112- (NSDictionary*) dictionaryValue
     113{
     114    Tcl_Obj **elemPtrs;
     115    int elemLen, i;
     116
     117    if (nil == _cocoaDictionary)
     118    {
     119        if (Tcl_ListObjGetElements(NULL, _tclObj, &elemLen, &elemPtrs) != TCL_OK)
     120            return nil;
     121
     122        if (elemLen & 1 || elemLen == 0)
     123            return nil;
     124
     125        NSMutableArray *keys = [NSMutableArray array];
     126        NSMutableArray *values = [NSMutableArray array];
     127
     128        for (i = 0; i < elemLen; i += 2) {
     129            [keys addObject: [NSString stringWithCString: Tcl_GetString(elemPtrs[i])]];
     130            [values addObject: [NSString stringWithCString: Tcl_GetString(elemPtrs[i + 1])]];
     131        }
     132
     133        _cocoaDictionary = [NSDictionary dictionaryWithObjects: values forKeys: keys];
     134    }
     135
     136    return _cocoaDictionary;
    114137}
    115138
Note: See TracChangeset for help on using the changeset viewer.