X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fvalue.h;h=b1b27ed16eae86b938a99e5db3b2f45d89bafb36;hb=refs%2Fheads%2Fmdd;hp=046a9a3aa638a5e69b77bbecca8f8447e30d820b;hpb=388fb23b17cd58ec28964cca517fcd79dea92197;p=pspp diff --git a/src/data/value.h b/src/data/value.h index 046a9a3aa6..b1b27ed16e 100644 --- a/src/data/value.h +++ b/src/data/value.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2007, 2009, 2010, 2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "xalloc.h" @@ -45,43 +46,45 @@ union value { double f; - char short_string[MAX_SHORT_STRING]; - char *long_string; + uint8_t short_string[MAX_SHORT_STRING]; + uint8_t *long_string; }; static inline void value_init (union value *, int width); +static inline void value_clone (union value *, const union value *, int width); static inline bool value_needs_init (int width); static inline bool value_try_init (union value *, int width); static inline void value_destroy (union value *, int width); static inline double value_num (const union value *); -static inline const char *value_str (const union value *, int width); -static inline char *value_str_rw (union value *, int width); - -int compare_values (const void *, const void *, const void *var); -unsigned hash_value (const void *, const void *var); +static inline const uint8_t *value_str (const union value *, int width); +static inline uint8_t *value_str_rw (union value *, int width); static inline void value_copy (union value *, const union value *, int width); void value_copy_rpad (union value *, int dst_width, const union value *, int src_width, char pad); -void value_copy_str_rpad (union value *, int dst_width, const char *, +void value_copy_str_rpad (union value *, int dst_width, const uint8_t *, char pad); void value_copy_buf_rpad (union value *dst, int dst_width, - const char *src, size_t src_len, char pad); + const uint8_t *src, size_t src_len, char pad); void value_set_missing (union value *, int width); int value_compare_3way (const union value *, const union value *, int width); bool value_equal (const union value *, const union value *, int width); -size_t value_hash (const union value *, int width, unsigned int basis); +unsigned int value_hash (const union value *, int width, unsigned int basis); bool value_is_resizable (const union value *, int old_width, int new_width); bool value_needs_resize (int old_width, int new_width); void value_resize (union value *, int old_width, int new_width); +bool value_is_spaces (const union value *, int width); + static inline void value_swap (union value *, union value *); struct pool; void value_init_pool (struct pool *, union value *, int width); +void value_clone_pool (struct pool *, union value *, const union value *, + int width); void value_resize_pool (struct pool *, union value *, int old_width, int new_width); @@ -100,6 +103,17 @@ value_init (union value *v, int width) v->long_string = xmalloc (width); } +/* Initializes V as a value of the given WIDTH, as with value_init(), and + copies SRC's value into V as its initial value. */ +static inline void +value_clone (union value *v, const union value *src, int width) +{ + if (width <= MAX_SHORT_STRING) + *v = *src; + else + v->long_string = xmemdup (src->long_string, width); +} + /* Returns true if a value of the given WIDTH actually needs to have the value_init and value_destroy functions called, false if those functions are no-ops for values of the given WIDTH. @@ -150,7 +164,7 @@ value_num (const union value *v) It is important that WIDTH be the actual value that was passed to value_init. Passing, e.g., a smaller value because only that number of bytes will be accessed will not always work. */ -static inline const char * +static inline const uint8_t * value_str (const union value *v, int width) { assert (width > 0); @@ -164,7 +178,7 @@ value_str (const union value *v, int width) It is important that WIDTH be the actual value that was passed to value_init. Passing, e.g., a smaller value because only that number of bytes will be accessed will not always work. */ -static inline char * +static inline uint8_t * value_str_rw (union value *v, int width) { assert (width > 0);