Prepare Open vSwitch 1.1.2 release.
[sliver-openvswitch.git] / ovsdb / column.h
1 /* Copyright (c) 2009, 2010 Nicira Networks
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef OVSDB_COLUMN_H
17 #define OVSDB_COLUMN_H 1
18
19 #include <stdbool.h>
20 #include "compiler.h"
21 #include "ovsdb-types.h"
22
23 struct ovsdb_table;
24
25 /* A column or a column schema (currently there is no distinction). */
26 struct ovsdb_column {
27     unsigned int index;
28     char *name;
29
30     bool mutable;
31     bool persistent;
32     struct ovsdb_type type;
33 };
34
35 /* A few columns appear in every table with standardized column indexes.
36  * These macros define those columns' indexes.
37  *
38  * Don't change these values, because ovsdb_query() depends on OVSDB_COL_UUID
39  * having value 0. */
40 enum {
41     OVSDB_COL_UUID = 0,         /* UUID for the row. */
42     OVSDB_COL_VERSION = 1,      /* Version number for the row. */
43     OVSDB_N_STD_COLUMNS
44 };
45
46 struct ovsdb_column *ovsdb_column_create(
47     const char *name, bool mutable, bool persistent,
48     const struct ovsdb_type *);
49 struct ovsdb_column *ovsdb_column_clone(const struct ovsdb_column *);
50 void ovsdb_column_destroy(struct ovsdb_column *);
51
52 struct ovsdb_error *ovsdb_column_from_json(const struct json *,
53                                            const char *name,
54                                            struct ovsdb_column **)
55     WARN_UNUSED_RESULT;
56 struct json *ovsdb_column_to_json(const struct ovsdb_column *);
57 \f
58 /* An unordered set of distinct columns. */
59
60 struct ovsdb_column_set {
61     const struct ovsdb_column **columns;
62     size_t n_columns, allocated_columns;
63 };
64
65 #define OVSDB_COLUMN_SET_INITIALIZER { NULL, 0, 0 }
66
67 void ovsdb_column_set_init(struct ovsdb_column_set *);
68 void ovsdb_column_set_destroy(struct ovsdb_column_set *);
69 void ovsdb_column_set_clone(struct ovsdb_column_set *,
70                             const struct ovsdb_column_set *);
71 struct ovsdb_error *ovsdb_column_set_from_json(const struct json *,
72                                                const struct ovsdb_table *,
73                                                struct ovsdb_column_set *);
74 struct json *ovsdb_column_set_to_json(const struct ovsdb_column_set *);
75
76 void ovsdb_column_set_add(struct ovsdb_column_set *,
77                           const struct ovsdb_column *);
78 void ovsdb_column_set_add_all(struct ovsdb_column_set *,
79                               const struct ovsdb_table *);
80 bool ovsdb_column_set_contains(const struct ovsdb_column_set *,
81                                unsigned int column_index);
82 bool ovsdb_column_set_equals(const struct ovsdb_column_set *,
83                              const struct ovsdb_column_set *);
84
85 #endif /* column.h */