1 /* Copyright (c) 2009 Nicira Networks
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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define OVSDB_TYPES_H 1
26 /* An atomic type: one that OVSDB regards as a single unit of data. */
27 enum ovsdb_atomic_type {
28 OVSDB_TYPE_VOID, /* No value. */
29 OVSDB_TYPE_INTEGER, /* Signed 64-bit integer. */
30 OVSDB_TYPE_REAL, /* IEEE 754 double-precision floating point. */
31 OVSDB_TYPE_BOOLEAN, /* True or false. */
32 OVSDB_TYPE_STRING, /* UTF-8 string. */
33 OVSDB_TYPE_UUID, /* RFC 4122 UUID referencing a table row. */
37 static inline bool ovsdb_atomic_type_is_valid(enum ovsdb_atomic_type);
38 static inline bool ovsdb_atomic_type_is_valid_key(enum ovsdb_atomic_type);
39 bool ovsdb_atomic_type_from_string(const char *, enum ovsdb_atomic_type *);
40 struct ovsdb_error *ovsdb_atomic_type_from_json(enum ovsdb_atomic_type *,
42 const char *ovsdb_atomic_type_to_string(enum ovsdb_atomic_type);
43 struct json *ovsdb_atomic_type_to_json(enum ovsdb_atomic_type);
45 /* An OVSDB type. One of:
49 * - A set of atomic types.
51 * - A map from one atomic type to another.
54 enum ovsdb_atomic_type key_type;
55 enum ovsdb_atomic_type value_type;
57 unsigned int n_max; /* UINT_MAX stands in for "unlimited". */
60 #define OVSDB_TYPE_SCALAR_INITIALIZER(KEY_TYPE) \
61 { KEY_TYPE, OVSDB_TYPE_VOID, 1, 1 }
63 extern const struct ovsdb_type ovsdb_type_integer;
64 extern const struct ovsdb_type ovsdb_type_real;
65 extern const struct ovsdb_type ovsdb_type_boolean;
66 extern const struct ovsdb_type ovsdb_type_string;
67 extern const struct ovsdb_type ovsdb_type_uuid;
69 bool ovsdb_type_is_valid(const struct ovsdb_type *);
71 static inline bool ovsdb_type_is_scalar(const struct ovsdb_type *);
72 static inline bool ovsdb_type_is_optional(const struct ovsdb_type *);
73 static inline bool ovsdb_type_is_composite(const struct ovsdb_type *);
74 static inline bool ovsdb_type_is_set(const struct ovsdb_type *);
75 static inline bool ovsdb_type_is_map(const struct ovsdb_type *);
77 char *ovsdb_type_to_english(const struct ovsdb_type *);
79 struct ovsdb_error *ovsdb_type_from_json(struct ovsdb_type *,
82 struct json *ovsdb_type_to_json(const struct ovsdb_type *);
84 /* Inline function implementations. */
87 ovsdb_atomic_type_is_valid(enum ovsdb_atomic_type atomic_type)
89 return atomic_type >= 0 && atomic_type < OVSDB_N_TYPES;
93 ovsdb_atomic_type_is_valid_key(enum ovsdb_atomic_type atomic_type)
95 /* XXX should we disallow reals or booleans as keys? */
96 return ovsdb_atomic_type_is_valid(atomic_type);
99 static inline bool ovsdb_type_is_scalar(const struct ovsdb_type *type)
101 return (type->value_type == OVSDB_TYPE_VOID
102 && type->n_min == 1 && type->n_max == 1);
105 static inline bool ovsdb_type_is_optional(const struct ovsdb_type *type)
107 return type->n_min == 0;
110 static inline bool ovsdb_type_is_composite(const struct ovsdb_type *type)
112 return type->n_max > 1;
115 static inline bool ovsdb_type_is_set(const struct ovsdb_type *type)
117 return (type->value_type == OVSDB_TYPE_VOID
118 && (type->n_min != 1 || type->n_max != 1));
121 static inline bool ovsdb_type_is_map(const struct ovsdb_type *type)
123 return type->value_type != OVSDB_TYPE_VOID;
126 #endif /* ovsdb-types.h */