INGOR
ytNode.h
1/*
2 net/ytNode.{h,c} : Node in networks
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 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_NODE_H
37#define __YTLIB_NODE_H
38
39#include "lang/ytObject.h"
40#include "util/ytKeyValues.h"
41
42typedef struct {
43 ytObject obj;
44 char * name;
45 ytKeyValues * prop;
46} ytNode;
47
48ytNode * ytNode_new();
49void ytNode_delete(ytNode * this);
50ytNode * ytNode_newName(const char * name);
51ytNode * ytNode_clone(const ytNode * this);
52void ytNode_dump(ytNode * this, FILE * fp);
53void ytNode_setName(ytNode * this, const char * name);
54const char * ytNode_getName(const ytNode * this);
55ytObject * ytNode_obj(ytNode * this);
57size_t ytNode_numProperties(const ytNode * this);
58void ytNode_addProperty(ytNode * this, const char * key, ytObject * value);
59void ytNode_setProperty(ytNode * this, const char * key, ytObject * value);
60void ytNode_setPropertyInt(ytNode * this, const char * key, int value);
61void ytNode_setPropertyDouble(ytNode * this, const char * key, double value);
62void ytNode_setPropertyString(ytNode * this, const char * key, const char * value);
63ytObject * ytNode_getProperty(const ytNode * this, const char * key);
64ytObject * ytNode_getPropertyAt(ytNode * this, size_t i);
65int ytNode_getPropertyInt(ytNode * this, const char * key, int defValue);
66const char * ytNode_getPropertyString(const ytNode * this, const char * key);
68const char * ytNode_getPropertyKey(const ytNode * this, size_t i);
69ytType ytNode_getPropertyType(const ytNode * this, size_t i );
70
71size_t ytNode_size(const ytNode * this);
72ytByte * ytNode_serialize(const ytNode * this, ytByte ** pptr);
73ytNode * ytNode_deserialize(ytByte ** const pptr);
74size_t ytNode_sizeI(const ytObject * obj);
75ytByte * ytNode_serializeI(const ytObject * obj, ytByte ** pptr);
76ytObject * ytNode_deserializeI(ytByte ** const pptr);
77
78#ifndef DOXY
79int ytNode_test(int argc, char * argv[]);
80#endif /* DOXY */
81
82#endif /* __YTLIB_NODE_H */
key-value pairs.
The basis class.
Expandable array.
ytType
Types supported by ytLib.
Definition: ytType.h:41
Network node.
Definition: ytNode.h:42
const char * ytNode_getName(const ytNode *this)
Returns the name of this node.
Definition: ytNode.c:143
ytNode * ytNode_clone(const ytNode *this)
Generates a clone of this ytNode instance.
Definition: ytNode.c:108
ytObject * ytNode_getPropertyAt(ytNode *this, size_t i)
Returns a property value at the specified position.
Definition: ytNode.c:187
ytObject * ytNode_obj(ytNode *this)
Returns the pointer to this instance as ytObject.
Definition: ytNode.c:88
ytStrArray * ytNode_getPropertyKeys(ytNode *this, ytStrArray *ar)
Returns all the property keys.
Definition: ytNode.c:225
ytObject * ytNode_getProperty(const ytNode *this, const char *key)
Gets a property associated with the given key.
Definition: ytNode.c:180
void ytNode_setPropertyDouble(ytNode *this, const char *key, double value)
Adds a double precision real value property.
Definition: ytNode.c:165
void ytNode_setPropertyString(ytNode *this, const char *key, const char *value)
Adds a string value property.
Definition: ytNode.c:172
void ytNode_setProperty(ytNode *this, const char *key, ytObject *value)
Adds a property key-value pair.
Definition: ytNode.c:149
void ytNode_setPropertyInt(ytNode *this, const char *key, int value)
Adds an integer value property.
Definition: ytNode.c:158
void ytNode_setName(ytNode *this, const char *name)
Sets the name of this node.
Definition: ytNode.c:132
ytNode * ytNode_newName(const char *name)
Definition: ytNode.c:78
int ytNode_getPropertyInt(ytNode *this, const char *key, int defValue)
Returns the integer property value.
Definition: ytNode.c:194
void ytNode_delete(ytNode *this)
Deletes the ytNode instance.
Definition: ytNode.c:69
const char * ytNode_getPropertyString(const ytNode *this, const char *key)
Returns the string property value.
Definition: ytNode.c:204
size_t ytNode_numProperties(const ytNode *this)
Returns the number of properties set in this node.
Definition: ytNode.c:214
ytByte * ytNode_serialize(const ytNode *this, ytByte **pptr)
Serializes the ytNode instance.
Definition: ytNode.c:258
ytNode * ytNode_from(ytObject *obj)
Returns the pointer to the ytNode instance from ytObject.
Definition: ytNode.c:96
size_t ytNode_size(const ytNode *this)
Returns the serialized size of the instance.
Definition: ytNode.c:241
const char * ytNode_getPropertyKey(const ytNode *this, size_t i)
Returns the property key at the specified position.
Definition: ytNode.c:234