/* PSPP - a program for statistical analysis.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2011 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
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
-#include <data/value.h>
-#include <libpspp/compiler.h>
+
+#include "data/value.h"
+#include "libpspp/cast.h"
+#include "libpspp/compiler.h"
/* Case prototype.
{
size_t ref_cnt; /* Reference count. */
- /* Tracking of long string widths. Lazily maintained: when
- 'long_strings' is null and 'n_long_strings' is nonzero,
- the former must be regenerated. */
- size_t *long_strings; /* Array of indexes of long string widths. */
- size_t n_long_strings; /* Number of long string widths. */
+ /* Tracking of string widths. Lazily maintained: when 'strings' is null
+ and 'n_strings' is nonzero, the former must be regenerated. */
+ size_t *strings; /* Array of indexes of string widths. */
+ size_t n_strings; /* Number of string widths. */
/* Widths. */
size_t n_widths; /* Number of widths. */
/* Creation and destruction. */
struct caseproto *caseproto_create (void) MALLOC_LIKE;
-static inline struct caseproto *caseproto_ref (const struct caseproto *);
-struct caseproto *caseproto_ref_pool (const struct caseproto *, struct pool *);
+static inline struct caseproto *caseproto_ref (const struct caseproto *) WARN_UNUSED_RESULT;
+struct caseproto *caseproto_ref_pool (const struct caseproto *, struct pool *) WARN_UNUSED_RESULT;
static inline void caseproto_unref (struct caseproto *);
/* Inspecting stored widths. */
size_t before, int width)
WARN_UNUSED_RESULT;
struct caseproto *caseproto_remove_widths (struct caseproto *,
- size_t idx, size_t cnt)
+ size_t idx, size_t n)
WARN_UNUSED_RESULT;
struct caseproto *caseproto_move_widths (struct caseproto *,
size_t old_start, size_t new_start,
- size_t cnt)
+ size_t n)
WARN_UNUSED_RESULT;
/* Working with "union value" arrays. */
void caseproto_copy (const struct caseproto *, size_t idx, size_t count,
union value *dst, const union value *src);
-/* Inspecting the cache of long string widths.
+/* Inspecting the cache of string widths.
- (These functions are useful for allocating cases, which
- requires allocating a block memory for each long string value
- in the case.) */
-static inline size_t caseproto_get_n_long_strings (const struct caseproto *);
-static inline size_t caseproto_get_long_string_idx (const struct caseproto *,
- size_t idx1);
+ (These functions are useful for allocating cases, which requires allocating
+ a block of memory for each string value in the case.) */
+static inline size_t caseproto_get_n_strings (const struct caseproto *);
+static inline size_t caseproto_get_string_idx (const struct caseproto *,
+ size_t idx1);
/* For use in assertions. */
bool caseproto_range_is_valid (const struct caseproto *,
static inline struct caseproto *
caseproto_ref (const struct caseproto *proto_)
{
- struct caseproto *proto = (struct caseproto *) proto_;
+ struct caseproto *proto = CONST_CAST (struct caseproto *, proto_);
proto->ref_cnt++;
return proto;
}
static inline void
caseproto_unref (struct caseproto *proto)
{
- if (proto != NULL && !--proto->ref_cnt)
+ if (proto != NULL && --proto->ref_cnt == 0)
caseproto_free__ (proto);
}
\f
\f
/* Inspecting the cache of long string widths. */
-void caseproto_refresh_long_string_cache__ (const struct caseproto *);
+void caseproto_refresh_string_cache__ (const struct caseproto *);
-/* Returns the number of long string widths in PROTO; that is,
- the number of widths in PROTO that are greater than or equal
- to MIN_LONG_STRING. */
+/* Returns the number of strings in PROTO. */
static inline size_t
-caseproto_get_n_long_strings (const struct caseproto *proto)
+caseproto_get_n_strings (const struct caseproto *proto)
{
- return proto->n_long_strings;
+ return proto->n_strings;
}
-/* Given long string width IDX1, returns a value IDX2 for which
- caseproto_get_width(PROTO, IDX2) will return a value greater
- than or equal to MIN_LONG_STRING. IDX1 must be less than
- caseproto_get_n_long_strings(PROTO), and IDX2 will be less
- than caseproto_get_n_widths(PROTO). */
+/* Given string width IDX1, returns a value IDX2 for which
+ caseproto_get_width(PROTO, IDX2) will return a value greater than 0. IDX1
+ must be less than caseproto_get_n_strings(PROTO), and IDX2 will be less than
+ caseproto_get_n_widths(PROTO). */
static inline size_t
-caseproto_get_long_string_idx (const struct caseproto *proto, size_t idx1)
+caseproto_get_string_idx (const struct caseproto *proto, size_t idx1)
{
- if (proto->long_strings == NULL)
- caseproto_refresh_long_string_cache__ (proto);
+ if (proto->strings == NULL)
+ caseproto_refresh_string_cache__ (proto);
- assert (idx1 < proto->n_long_strings);
- return proto->long_strings[idx1];
+ assert (idx1 < proto->n_strings);
+ return proto->strings[idx1];
}
#endif /* data/caseproto.h */