treewide: Replace <name>_cnt by n_<name>s and <name>_cap by allocated_<name>.
[pspp] / src / data / case.h
index d00c2ad37badd69cc80f9991d99a70bf8d88084c..256d66019dd81f7ca25275291fcadc05b42b8964 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2004, 2007, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2007, 2009, 2010, 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 <stddef.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <libpspp/compiler.h>
-#include <data/caseproto.h>
+
+#include "libpspp/compiler.h"
+#include "libpspp/str.h"
+#include "data/caseproto.h"
 
 struct variable;
 
@@ -61,11 +63,11 @@ struct ccase *case_try_create (const struct caseproto *) MALLOC_LIKE;
 struct ccase *case_clone (const struct ccase *) MALLOC_LIKE;
 
 static inline struct ccase *case_unshare (struct ccase *) WARN_UNUSED_RESULT;
-static inline struct ccase *case_ref (const struct ccase *);
+struct ccase *case_ref (const struct ccase *) WARN_UNUSED_RESULT;
 static inline void case_unref (struct ccase *);
 static inline bool case_is_shared (const struct ccase *);
 
-static inline size_t case_get_value_cnt (const struct ccase *);
+static inline size_t case_get_n_values (const struct ccase *);
 static inline const struct caseproto *case_get_proto (const struct ccase *);
 
 size_t case_get_cost (const struct caseproto *);
@@ -93,9 +95,13 @@ union value *case_data_rw_idx (struct ccase *, size_t idx);
 
 double case_num (const struct ccase *, const struct variable *);
 double case_num_idx (const struct ccase *, size_t idx);
+double *case_num_rw (struct ccase *, const struct variable *);
+double *case_num_rw_idx (struct ccase *, size_t idx);
 
 const uint8_t *case_str (const struct ccase *, const struct variable *);
 const uint8_t *case_str_idx (const struct ccase *, size_t idx);
+struct substring case_ss (const struct ccase *, const struct variable *);
+struct substring case_ss_idx (const struct ccase *, size_t width, size_t idx);
 uint8_t *case_str_rw (struct ccase *, const struct variable *);
 uint8_t *case_str_rw_idx (struct ccase *, size_t idx);
 
@@ -120,7 +126,7 @@ void case_unref__ (struct ccase *);
    This function should be used before attempting to modify any
    of the data in a case that might be shared, e.g.:
         c = case_unshare (c);              // Make sure that C is not shared.
-        case_data_rw (c, myvar)->f = 1;    // Modify data in C.
+        *case_num_rw (c, myvar) = 1;       // Modify data in C.
 */
 static inline struct ccase *
 case_unshare (struct ccase *c)
@@ -130,16 +136,6 @@ case_unshare (struct ccase *c)
   return c;
 }
 
-/* Increments case C's reference count and returns C.  Afterward,
-   case C is shared among its reference count holders. */
-static inline struct ccase *
-case_ref (const struct ccase *c_)
-{
-  struct ccase *c = CONST_CAST (struct ccase *, c_);
-  c->ref_cnt++;
-  return c;
-}
-
 /* Decrements case C's reference count.  Frees C if its
    reference count drops to 0.
 
@@ -147,7 +143,7 @@ case_ref (const struct ccase *c_)
 static inline void
 case_unref (struct ccase *c)
 {
-  if (c != NULL && !--c->ref_cnt)
+  if (c != NULL && --c->ref_cnt == 0)
     case_unref__ (c);
 }
 
@@ -162,7 +158,7 @@ case_is_shared (const struct ccase *c)
 
 /* Returns the number of union values in C. */
 static inline size_t
-case_get_value_cnt (const struct ccase *c)
+case_get_n_values (const struct ccase *c)
 {
   return caseproto_get_n_widths (c->proto);
 }