int Vector_get_length(Vector v){
return v->len;
}
-
-/*---------------- string vector --------------- */
-
-static void strdealloactor(void *v){
- char **s = v;
- free(*s);
-}
-
-Vector StringVector_new(int len, int delete_element_strings){
- /* delete_element_strings decides whether we need to delete each string in the vector or leave it to be cleaned by other handles */
- if (!delete_element_strings){
- return Vector_new(len, sizeof(char*), NULL);
- } else {
- return Vector_new(len, sizeof(char*), strdealloactor);
- }
-
-}
-Vector StringVector_add(Vector v, char *s){
- return Vector_add(v, &s);
-}
-
-void StringVector_delete(Vector v){
- return Vector_delete(v);
-}
-
-char** StringVector_get(Vector v, int i){
- char **p = Vector_get(v, i);
- if (!p) return NULL;
- return p;
-}
-
-int StringVector_get_length(Vector v){
- return Vector_get_length(v);
-}
-
-Vector StringVector_reset(Vector v, char *content, int pos){
- return Vector_reset(v, &content, pos);
-}
-
-void StringVector_fprint1(FILE *fp, StringVector v){
- int i;
- if (!v) return;
- for (i = 0; i < StringVector_get_length(v); i++){
- fprintf(fp,"%s\n", *(StringVector_get(v, i)));
- }
-}
-
-void StringVector_fprint(FILE *fp, StringVector v){
- int i;
- if (!v) return;
- for (i = 0; i < StringVector_get_length(v); i++){
- fprintf(fp,"%d %s\n", i+1,*(StringVector_get(v, i)));
- }
-}
-
-StringVector StringVector_part(StringVector v, int n, int *selected_list){
- /* select a list of n elements from vector v and form a new vector */
- StringVector u;
- char *s, *s2;
- int i;
- u = StringVector_new(1, TRUE);
- for (i = 0; i < n; i++){
- s = *(StringVector_get(v, selected_list[i]));
- s2 = MALLOC(sizeof(char)*(strlen(s)+1));
- strcpy(s2, s);
- StringVector_add(u, s2);
- }
- return u;
-}
Vector Vector_reset(Vector v, void *stuff, int i);
-/*------------- vector of strings ----------- */
-
-typedef Vector StringVector;
-
-Vector StringVector_new(int len, int delete_element_strings);
-Vector StringVector_add(Vector v, char *i);
-void StringVector_delete(Vector v);
-char** StringVector_get(Vector v, int i);
-int StringVector_get_length(Vector v);
-Vector StringVector_reset(Vector v, char *content, int pos);
-void StringVector_fprint(FILE *fp, StringVector v);
-void StringVector_fprint1(FILE *fp, StringVector v);
-StringVector StringVector_part(StringVector v, int n, int *selected_list);
-
#endif