diff options
author | Ben Warren <ben@skyportsystems.com> | 2016-04-04 21:32:08 -0400 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2016-04-14 13:48:05 -0700 |
commit | ae06a5610a4d5d3fa1d723966aaf356140983f0b (patch) | |
tree | d66c030ad65da89faa2a92d5dc6c453f9f8b6a2f /include | |
parent | 064d7f842838bdc41a3b80e49ec92eee19e6e41b (diff) | |
download | openvswitch-ae06a5610a4d5d3fa1d723966aaf356140983f0b.tar.gz |
Move lib/type-props.h to include/openvswitch directory
Signed-off-by: Ben Warren <ben@skyportsystems.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/openvswitch/automake.mk | 1 | ||||
-rw-r--r-- | include/openvswitch/type-props.h | 55 |
2 files changed, 56 insertions, 0 deletions
diff --git a/include/openvswitch/automake.mk b/include/openvswitch/automake.mk index 21b863801..a96daff4c 100644 --- a/include/openvswitch/automake.mk +++ b/include/openvswitch/automake.mk @@ -15,6 +15,7 @@ openvswitchinclude_HEADERS = \ include/openvswitch/thread.h \ include/openvswitch/token-bucket.h \ include/openvswitch/tun-metadata.h \ + include/openvswitch/type-props.h \ include/openvswitch/types.h \ include/openvswitch/util.h \ include/openvswitch/uuid.h \ diff --git a/include/openvswitch/type-props.h b/include/openvswitch/type-props.h new file mode 100644 index 000000000..bf879cd82 --- /dev/null +++ b/include/openvswitch/type-props.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2008, 2011, 2015 Nicira, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OPENVSWITCH_TYPE_PROPS_H +#define OPENVSWITCH_TYPE_PROPS_H 1 + +#include <limits.h> + +/* True if TYPE is _Bool, false otherwise. */ +#define TYPE_IS_BOOL(TYPE) ((TYPE) 1 == (TYPE) 2) + +/* True if TYPE is an integer type (including _Bool), false if it is a + * floating-point type. */ +#define TYPE_IS_INTEGER(TYPE) ((TYPE) 1.5 == (TYPE) 1) + +/* True if TYPE is a signed integer or floating point type, otherwise false. */ +#define TYPE_IS_SIGNED(TYPE) ((TYPE) 1 > (TYPE) -1) + +/* The number of value bits in an signed or unsigned integer TYPE: + * + * - _Bool has 1 value bit. + * + * - An N-bit unsigned integer type has N value bits. + * + * - An N-bit signed integer type has N-1 value bits. + */ +#define TYPE_VALUE_BITS(TYPE) \ + (TYPE_IS_BOOL(TYPE) ? 1 : sizeof(TYPE) * CHAR_BIT - TYPE_IS_SIGNED(TYPE)) + +/* The minimum or maximum value of a signed or unsigned integer TYPE. */ +#define TYPE_MINIMUM(TYPE) (TYPE_IS_SIGNED(TYPE) ? -TYPE_MAXIMUM(TYPE) - 1 : 0) +#define TYPE_MAXIMUM(TYPE) \ + ((((TYPE)1 << (TYPE_VALUE_BITS(TYPE) - 1)) - 1) * 2 + 1) + +/* Number of decimal digits required to format an integer of the given TYPE. + * Includes space for a sign, if TYPE is signed, but not for a null + * terminator. + * + * The value is an overestimate. */ +#define INT_STRLEN(TYPE) (TYPE_IS_SIGNED(TYPE) + TYPE_VALUE_BITS(TYPE) / 3 + 1) + +#endif /* type-props.h */ |