/*1* Copyright (c) 2010 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Portions Copyright (c) 2010 Apple Inc. All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10*11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13*14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* 3. Neither the name of the Institute nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#include "baselocl.h"3637static void38number_dealloc(void *ptr)39{40}4142static int43number_cmp(void *a, void *b)44{45int na, nb;4647if (heim_base_is_tagged_object(a))48na = heim_base_tagged_object_value(a);49else50na = *(int *)a;5152if (heim_base_is_tagged_object(b))53nb = heim_base_tagged_object_value(b);54else55nb = *(int *)b;5657return na - nb;58}5960static unsigned long61number_hash(void *ptr)62{63if (heim_base_is_tagged_object(ptr))64return heim_base_tagged_object_value(ptr);65return (unsigned long)*(int *)ptr;66}6768struct heim_type_data _heim_number_object = {69HEIM_TID_NUMBER,70"number-object",71NULL,72number_dealloc,73NULL,74number_cmp,75number_hash76};7778/**79* Create a number object80*81* @param the number to contain in the object82*83* @return a number object84*/8586heim_number_t87heim_number_create(int number)88{89heim_number_t n;9091if (number < 0xffffff && number >= 0)92return heim_base_make_tagged_object(number, HEIM_TID_NUMBER);9394n = _heim_alloc_object(&_heim_number_object, sizeof(int));95if (n)96*((int *)n) = number;97return n;98}99100/**101* Return the type ID of number objects102*103* @return type id of number objects104*/105106heim_tid_t107heim_number_get_type_id(void)108{109return HEIM_TID_NUMBER;110}111112/**113* Get the int value of the content114*115* @param number the number object to get the value from116*117* @return an int118*/119120int121heim_number_get_int(heim_number_t number)122{123if (heim_base_is_tagged_object(number))124return heim_base_tagged_object_value(number);125return *(int *)number;126}127128129