INGOR
ytStrArray.h
1/*
2 ytStrArray.{h,c} : Expanable char * Array
3 Copyright (C) 2016, Yoshinori Tamada <tamada A T ytlab.jp>
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12
13 * Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in
15 the documentation and/or other materials provided with the
16 distribution.
17
18 * Neither the name of Kyoto University nor the names of its
19 contributors may be used to endorse or promote products derived
20 from this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#ifndef __YTLIB_STR_ARRAY_H
37#define __YTLIB_STR_ARRAY_H
38
39#include <stdio.h>
40#include <stdlib.h>
41
42#include "lang/ytObject.h"
43
44#define ytStrArray_ERROR_VALUE ((size_t) -1)
45
50/*typedef struct ytStrArray_t ytStrArray;*/
51#ifndef DOXY
52typedef struct ytStrArray_t {
53 ytObject obj;
54 char * * ptr;
55 size_t size;
56 size_t buff_size;
58#endif
59
60#ifdef YTLIB_MEMCHECK
61#define ytStrArray_new() ytStrArray_newm(__FILE__,__LINE__)
62ytStrArray * ytStrArray_newm(const char * file, int line);
63#else
65#endif
66void ytStrArray_delete(ytStrArray * this);
67void ytStrArray_deletev(void * this);
69void ytStrArray_deleteAllv(void * this);
71ytObject * ytStrArray_cloneI(const ytObject * this);
72ytStrArray * ytStrArray_arrayNew(size_t size);
73void ytStrArray_arrayDelete(ytStrArray * this, size_t size);
74void ytStrArray_dump(const ytStrArray * this, FILE * fp);
75void ytStrArray_dumpv(const ytObject * this, FILE * fp);
76size_t ytStrArray_size(const ytStrArray * this);
77size_t ytStrArray_buffSize(const ytStrArray * this);
78size_t ytStrArray_memSize(const ytStrArray * this);
79size_t ytStrArray_arrayMemSize(const ytStrArray * this, size_t n);
80void ytStrArray_clear(ytStrArray * this);
81ytStrArray * ytStrArray_setBuffSize(ytStrArray * this, size_t new_size);
82void ytStrArray_add(ytStrArray * this, char * value);
83void ytStrArray_addStrArray(ytStrArray * this, const ytStrArray * values);
84void ytStrArray_set(ytStrArray * this, size_t index, char * value);
85void ytStrArray_setSize(ytStrArray * this, size_t size);
86void ytStrArray_insert(ytStrArray * this, size_t index, char * value);
87char * ytStrArray_remove(ytStrArray * this, size_t index);
88void ytStrArray_copy(ytStrArray * this, const ytStrArray * src);
89void ytStrArray_copyArray(ytStrArray * this, size_t index, const char * * array, size_t size);
90char * ytStrArray_get(const ytStrArray * this, size_t index);
91char * ytStrArray_pop(ytStrArray * this);
92char * * ytStrArray_ptr(ytStrArray * this);
93void ytStrArray_sort(ytStrArray * this);
94size_t ytStrArray_find(const ytStrArray * this, const char * v);
95void ytStrArray_print(const ytStrArray * this, FILE * fp, char * delim);
96int ytStrArray_sprint(const ytStrArray * this, char * buff, size_t size, char * delim);
97ytObject * ytStrArray_obj(ytStrArray * this);
98ytObject * ytStrArray_pObj(ytStrArray ** ptr);
99ytStrArray * ytStrArray_from(ytObject * this);
100ytStrArray ** ytStrArray_objP(ytObject * this);
101size_t ytStrArray_memorySize(const ytStrArray * this);
102size_t ytStrArray_memorySizeI(const ytObject * this);
103ytByte * ytStrArray_serializeI(const ytObject * obj, ytByte ** pptr);
104ytByte * ytStrArray_serialize(const ytStrArray * this, ytByte ** pptr);
105ytStrArray * ytStrArray_deserialize(ytByte ** const pptr);
106ytObject * ytStrArray_deserializeI(ytByte ** const ptr);
107#ifdef USE_MPI
108#include <mpi.h>
109void ytStrArray_MPI_Bcast(ytStrArray ** pObj, int root, MPI_Comm comm);
110void ytStrArray_MPI_BcastI(ytObject ** pObject, int root, MPI_Comm comm);
111#endif
112
113#endif /* __YTLIB_STR_ARRAY_H */
The basis class.
Expandable array.
ytStrArray * ytStrArray_setBuffSize(ytStrArray *this, size_t new_size)
Changes the size of buffer.
Definition: ytStrArray.c:240
size_t ytStrArray_find(const ytStrArray *this, const char *v)
Returns the index of the value identical to the given one.
Definition: ytStrArray.c:467
void ytStrArray_copy(ytStrArray *this, const ytStrArray *src)
Copies values in another array into this.
Definition: ytStrArray.c:405
void ytStrArray_MPI_Bcast(ytStrArray **pObject, int root, MPI_Comm comm)
Broadcasts the array with MPI.
Definition: ytStrArray.c:649
ytStrArray * ytStrArray_new()
Creates a new ytStrArray instance.
Definition: ytStrArray.c:85
ytStrArray * ytStrArray_arrayNew(size_t size)
Creates the array of ytStrArray instances.
Definition: ytStrArray.c:181
void ytStrArray_set(ytStrArray *this, size_t index, char *value)
Sets a value at the specified position.
Definition: ytStrArray.c:324
void ytStrArray_clear(ytStrArray *this)
Removes all the elements in the array.
Definition: ytStrArray.c:281
void ytStrArray_deleteAll(ytStrArray *this)
Releases the array and all the elements in the array.
Definition: ytStrArray.c:115
void ytStrArray_setSize(ytStrArray *this, size_t size)
Changes the size of the array.
Definition: ytStrArray.c:358
void ytStrArray_print(const ytStrArray *this, FILE *fp, char *delim)
Prints the elements in the array.
Definition: ytStrArray.c:481
size_t ytStrArray_buffSize(const ytStrArray *this)
Returns the current buffer size allocated.
Definition: ytStrArray.c:228
char * ytStrArray_pop(ytStrArray *this)
Returns the last element.
Definition: ytStrArray.c:441
void ytStrArray_arrayDelete(ytStrArray *this, size_t size)
Deletes the array of ytStrArray instances.
Definition: ytStrArray.c:198
char * ytStrArray_remove(ytStrArray *this, size_t index)
Definition: ytStrArray.c:393
ytObject * ytStrArray_cloneI(const ytObject *this)
Returns the clone of this ytStrArray instance.
Definition: ytStrArray.c:154
void ytStrArray_copyArray(ytStrArray *this, size_t index, const char **array, size_t size)
Copies values in an array into this array.
Definition: ytStrArray.c:419
size_t ytStrArray_arrayMemSize(const ytStrArray *this, size_t n)
Returns the total size of memory used by the array of the array.
Definition: ytStrArray.c:267
void ytStrArray_add(ytStrArray *this, char *value)
Adds a value.
Definition: ytStrArray.c:289
void ytStrArray_insert(ytStrArray *this, size_t index, char *value)
Inserts a value at the specified position.
Definition: ytStrArray.c:370
size_t ytStrArray_memSize(const ytStrArray *this)
Returns the size of memory where the specified instance occupies.
Definition: ytStrArray.c:259
ytStrArray * ytStrArray_clone(const ytStrArray *this)
Returns the clone of this ytStrArray instance.
Definition: ytStrArray.c:139
void ytStrArray_sort(ytStrArray *this)
Sorts the elements in ascending order.
Definition: ytStrArray.c:458