INGOR
Loading...
Searching...
No Matches
ytType.h
1/*
2 util/ytType.{h,c} : Type abstraction
3 Copyright (C) 2018, 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 The 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#ifndef __YTLIB_TYPE_H
36#define __YTLIB_TYPE_H
37
41typedef enum {
44
47
50
53 ytType_UINT_P,
54
57
58 ytType_DOUBLE_P,
59
62
65
68
71
74
77 ytType_Array_P,
78
81 ytType_IntArray_P,
82
85 ytType_DoubleArray_P,
86
89
92 ytType_StrBuff,
93 ytType_KeyValues,
94 ytType_KeyValues_P,
95 ytType_ParseArgs,
96
97 ytType_Data,
98
99 ytType_Graph,
100 ytType_PGraph,
101 ytType_PCGraph,
102 ytType_CompleteGraph,
103 ytType_AdjGraph,
104 ytType_MapGraph,
105 ytType_DBNGraph,
106
107 ytType_Network,
108 ytType_Node,
109 ytType_Edge,
110
111 ytType_FUNC,
112
113 ytType_VOID_P,
114
115 ytType_Value,
116
119} ytType;
120
121#include <stdio.h>
122#include <stdint.h>
123
124typedef struct ytObject_t ytObject;
125typedef uint8_t ytByte;
126
127typedef ytObject * (*ytType_new_f)();
128typedef void (*ytType_delete_f)(void *);
129typedef ytObject * (*ytType_parse_f)(const char *);
130typedef ytObject * (*ytType_clone_f)(const ytObject *);
131typedef void (*ytType_copy_f)(ytObject *, const ytObject *);
132typedef void (*ytType_print_f)(const ytObject *, FILE *);
133typedef int (*ytType_sprint_f)(const ytObject *, char *, size_t);
134typedef int (*ytType_compare_f)(const ytObject *, const ytObject *);
135typedef void (*ytType_dump_f)(const ytObject *, FILE *);
136typedef size_t (*ytType_size_f)(const ytObject *);
137typedef ytByte * (*ytType_serialize_f)(const ytObject *, ytByte **);
138typedef ytObject * (*ytType_deserialize_f)(ytByte ** const);
139#ifdef USE_MPI
140#include <mpi.h>
141typedef void (*ytType_MPI_Bcast_f)(ytObject **, int, MPI_Comm);
142#else
143typedef void (*ytType_MPI_Bcast_f)(ytObject **);
144#endif
145
146const char * ytType_name(ytType type);
147ytType ytType_parse(const char * name);
148int ytType_super(ytType super, ytType sub);
149ytType_new_f ytType_getNew(ytType type);
150ytType_delete_f ytType_getDelete(ytType type);
151ytType_parse_f ytType_getParse(ytType type);
152ytType_clone_f ytType_getClone(ytType type);
153ytType_copy_f ytType_getCopy(ytType type);
154ytType_print_f ytType_getPrint(ytType type);
155ytType_sprint_f ytType_getSprint(ytType type);
156ytType_compare_f ytType_getCompare(ytType type);
157ytType_dump_f ytType_getDump(ytType type);
158ytType_size_f ytType_getSize(ytType type);
159ytType_serialize_f ytType_getSerialize(ytType type);
160ytType_deserialize_f ytType_getDeserialize(ytType type);
161ytType_MPI_Bcast_f ytType_get_MPI_Bcast(ytType type);
162
163ytObject * ytType_IntArrayParse(const char * str);
164ytObject * ytType_DoubleArrayParse(const char * str);
165ytObject * ytType_StrArrayParse(const char * str);
166
167void ytType_intSerialize2(const int * value, ytByte ** pptr);
168int ytType_intDeserialize2(ytByte ** const ptr);
169void ytType_doubleSerialize2(const double * value, ytByte ** pptr);
170double ytType_doubleDeserialize2(ytByte ** const ptr);
171void ytType_strSerialize2(const char * value, ytByte ** pptr);
172
173
174int ytType_test(int argc, char * argv[]);
175
176#endif /* __YTLIB_TYPE_H */
The basis class.
int ytType_super(ytType super, ytType sub)
Checks if the type is a subclass of the given type.
Definition ytType.c:341
ytType
Types supported by ytLib.
Definition ytType.h:41
ytType_copy_f ytType_getCopy(ytType type)
Returns the copy function for the given type.
Definition ytType.c:388
ytType_new_f ytType_getNew(ytType type)
Returns the default constructor of the given type.
Definition ytType.c:368
const char * ytType_name(ytType type)
Returns the name of the type.
Definition ytType.c:334
ytType_clone_f ytType_getClone(ytType type)
Returns the copy function for the given type.
Definition ytType.c:382
ytType ytType_parse(const char *name)
Returns the ytType value of the given type name.
Definition ytType.c:356
@ ytType_ERROR
For representing errors.
Definition ytType.h:118
@ ytType_SIZE_T_P
primitive size_t *.
Definition ytType.h:70
@ ytType_Object
ytObject.
Definition ytType.h:73
@ ytType_INT_P
primitive int *.
Definition ytType.h:49
@ ytType_DOUBLE
primitive double.
Definition ytType.h:56
@ ytType_CHAR_P
primitive char *.
Definition ytType.h:61
@ ytType_Array
ytArray.
Definition ytType.h:76
@ ytType_StrArray_P
pointer to ytStrArray.
Definition ytType.h:91
@ ytType_NULL
NULL.
Definition ytType.h:43
@ ytType_UINT
primitive unsigned int.
Definition ytType.h:52
@ ytType_INT
primitive int.
Definition ytType.h:46
@ ytType_SIZE_T
primitive size_t.
Definition ytType.h:67
@ ytType_CHAR_PP
primitive char **.
Definition ytType.h:64
@ ytType_IntArray
ytIntArray.
Definition ytType.h:80
@ ytType_DoubleArray
ytDoubleArray.
Definition ytType.h:84
@ ytType_StrArray
ytStrArray.
Definition ytType.h:88