1 /* Copyright (c) 2009, 2010 Nicira, Inc.
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.
16 #ifndef OVSDB_CONDITION_H
17 #define OVSDB_CONDITION_H 1
21 #include "ovsdb-data.h"
25 struct ovsdb_table_schema;
28 /* These list is ordered first with boolean functions and then in
29 * ascending order of the fraction of tables row that they are
30 * (heuristically) expected to leave in query results. */
31 #define OVSDB_FUNCTIONS \
32 OVSDB_FUNCTION(OVSDB_F_FALSE, "false") \
33 OVSDB_FUNCTION(OVSDB_F_TRUE, "true") \
34 OVSDB_FUNCTION(OVSDB_F_EQ, "==") \
35 OVSDB_FUNCTION(OVSDB_F_INCLUDES, "includes") \
36 OVSDB_FUNCTION(OVSDB_F_LE, "<=") \
37 OVSDB_FUNCTION(OVSDB_F_LT, "<") \
38 OVSDB_FUNCTION(OVSDB_F_GE, ">=") \
39 OVSDB_FUNCTION(OVSDB_F_GT, ">") \
40 OVSDB_FUNCTION(OVSDB_F_EXCLUDES, "excludes") \
41 OVSDB_FUNCTION(OVSDB_F_NE, "!=")
44 #define OVSDB_FUNCTION(ENUM, NAME) ENUM,
47 OVSDB_F_LAST = OVSDB_F_NE
50 struct ovsdb_error *ovsdb_function_from_string(const char *,
51 enum ovsdb_function *)
52 OVS_WARN_UNUSED_RESULT;
53 const char *ovsdb_function_to_string(enum ovsdb_function);
56 enum ovsdb_function function;
57 const struct ovsdb_column *column;
59 struct ovsdb_datum arg;
62 struct ovsdb_condition {
63 struct ovsdb_clause *clauses;
67 #define OVSDB_CONDITION_INITIALIZER { NULL, 0}
69 void ovsdb_condition_init(struct ovsdb_condition *);
70 bool ovsdb_condition_empty(const struct ovsdb_condition *);
71 struct ovsdb_error *ovsdb_condition_from_json(
72 const struct ovsdb_table_schema *,
73 const struct json *, struct ovsdb_symbol_table *,
74 struct ovsdb_condition *) OVS_WARN_UNUSED_RESULT;
75 struct json *ovsdb_condition_to_json(const struct ovsdb_condition *);
76 void ovsdb_condition_destroy(struct ovsdb_condition *);
77 bool ovsdb_condition_match_every_clause(const struct ovsdb_row *,
78 const struct ovsdb_condition *);
79 bool ovsdb_condition_match_any_clause(const struct ovsdb_datum *,
80 const struct ovsdb_condition *,
81 unsigned int index_map[]);
82 int ovsdb_condition_cmp_3way(const struct ovsdb_condition *a,
83 const struct ovsdb_condition *b);
84 void ovsdb_condition_clone(struct ovsdb_condition *to,
85 const struct ovsdb_condition *from);
86 bool ovsdb_condition_is_true(const struct ovsdb_condition *cond);
87 bool ovsdb_condition_is_false(const struct ovsdb_condition *cond);
88 const struct ovsdb_column **
89 ovsdb_condition_get_columns(const struct ovsdb_condition *cond,
93 ovsdb_condition_empty_or_match_any(const struct ovsdb_datum *row_datum,
94 const struct ovsdb_condition *cnd,
95 unsigned int index_map[])
97 return (ovsdb_condition_empty(cnd) ||
98 ovsdb_condition_match_any_clause(row_datum, cnd, index_map));
101 #endif /* ovsdb/condition.h */