diff options
author | Chad Versace <chad.versace@linux.intel.com> | 2013-05-09 18:55:22 -0700 |
---|---|---|
committer | Chad Versace <chad.versace@linux.intel.com> | 2013-05-09 22:23:31 -0700 |
commit | 61f68b29eba91b6312b588fbe94d9e7b933fc2aa (patch) | |
tree | d2fc063b6f0a6b1ef3418eb622636e54fe4bffe0 | |
parent | 2fb18e9e1315e0b857f16c2ba974e79a159b5c82 (diff) |
core: Add internal version of waffle_attrib_list funcs
For each function waffle_attrib_list_VERB, add function
wcore_attrib_list_VERB and implement the first with the second. The
prepares us to remove internal calls to public API.
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
-rw-r--r-- | src/waffle/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/waffle/api/waffle_attrib_list.c | 54 | ||||
-rw-r--r-- | src/waffle/core/wcore_attrib_list.c | 103 | ||||
-rw-r--r-- | src/waffle/core/wcore_attrib_list.h | 51 |
4 files changed, 163 insertions, 46 deletions
diff --git a/src/waffle/CMakeLists.txt b/src/waffle/CMakeLists.txt index be49c55..590aa72 100644 --- a/src/waffle/CMakeLists.txt +++ b/src/waffle/CMakeLists.txt @@ -51,6 +51,7 @@ set(waffle_sources api/waffle_gl_misc.c api/waffle_init.c api/waffle_window.c + core/wcore_attrib_list.c core/wcore_config_attrs.c core/wcore_display.c core/wcore_error.c diff --git a/src/waffle/api/waffle_attrib_list.c b/src/waffle/api/waffle_attrib_list.c index 479528c..5a00699 100644 --- a/src/waffle/api/waffle_attrib_list.c +++ b/src/waffle/api/waffle_attrib_list.c @@ -1,4 +1,4 @@ -// Copyright 2012 Intel Corporation +// Copyright 2013 Intel Corporation // // All rights reserved. // @@ -29,22 +29,15 @@ /// @file /// @ingroup api +#include "wcore_attrib_list.h" #include "wcore_error.h" int32_t waffle_attrib_list_length(const int32_t attrib_list[]) { - const int32_t *i = attrib_list; wcore_error_reset(); - - if (attrib_list == NULL) - return 0; - - while (*i != 0) - i += 2; - - return (i - attrib_list) / 2; + return wcore_attrib_list_length(attrib_list); } bool @@ -54,19 +47,7 @@ waffle_attrib_list_get( int32_t *value) { wcore_error_reset(); - - if (attrib_list == NULL) - return false; - - for (int i = 0; attrib_list[i] != 0; i += 2) { - if (attrib_list[i] != key) - continue; - - *value = attrib_list[i + 1]; - return true; - } - - return false; + return wcore_attrib_list_get(attrib_list, key, value); } bool @@ -76,13 +57,9 @@ waffle_attrib_list_get_with_default( int32_t *value, int32_t default_value) { - if (waffle_attrib_list_get(attrib_list, key, value)) { - return true; - } - else { - *value = default_value; - return false; - } + wcore_error_reset(); + return wcore_attrib_list_get_with_default(attrib_list, key, value, + default_value); } bool @@ -91,23 +68,8 @@ waffle_attrib_list_update( int32_t key, int32_t value) { - int32_t *i = attrib_list; - wcore_error_reset(); - - if (attrib_list == NULL) - return false; - - while (*i != 0 && *i != key) - i += 2; - - if (*i == key) { - i[1] = value; - return true; - } - else { - return false; - } + return wcore_attrib_list_update(attrib_list, key, value); } /// @} diff --git a/src/waffle/core/wcore_attrib_list.c b/src/waffle/core/wcore_attrib_list.c new file mode 100644 index 0000000..ba380b8 --- /dev/null +++ b/src/waffle/core/wcore_attrib_list.c @@ -0,0 +1,103 @@ +// Copyright 2013 Intel Corporation +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "wcore_attrib_list.h" + +#include <stdbool.h> +#include <stdint.h> +#include <stddef.h> + +int32_t +wcore_attrib_list_length(const int32_t attrib_list[]) +{ + const int32_t *i = attrib_list; + + if (attrib_list == NULL) + return 0; + + while (*i != 0) + i += 2; + + return (i - attrib_list) / 2; +} + +bool +wcore_attrib_list_get( + const int32_t *attrib_list, + int32_t key, + int32_t *value) +{ + if (attrib_list == NULL) + return false; + + for (int i = 0; attrib_list[i] != 0; i += 2) { + if (attrib_list[i] != key) + continue; + + *value = attrib_list[i + 1]; + return true; + } + + return false; +} + +bool +wcore_attrib_list_get_with_default( + const int32_t attrib_list[], + int32_t key, + int32_t *value, + int32_t default_value) +{ + if (wcore_attrib_list_get(attrib_list, key, value)) { + return true; + } + else { + *value = default_value; + return false; + } +} + +bool +wcore_attrib_list_update( + int32_t *attrib_list, + int32_t key, + int32_t value) +{ + int32_t *i = attrib_list; + + if (attrib_list == NULL) + return false; + + while (*i != 0 && *i != key) + i += 2; + + if (*i == key) { + i[1] = value; + return true; + } + else { + return false; + } +} diff --git a/src/waffle/core/wcore_attrib_list.h b/src/waffle/core/wcore_attrib_list.h new file mode 100644 index 0000000..30d2096 --- /dev/null +++ b/src/waffle/core/wcore_attrib_list.h @@ -0,0 +1,51 @@ +// Copyright 2013 Intel Corporation +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once + +#include <stdbool.h> +#include <stdint.h> + +int32_t +wcore_attrib_list_length(const int32_t attrib_list[]); + +bool +wcore_attrib_list_get( + const int32_t *attrib_list, + int32_t key, + int32_t *value); + +bool +wcore_attrib_list_get_with_default( + const int32_t attrib_list[], + int32_t key, + int32_t *value, + int32_t default_value); + +bool +wcore_attrib_list_update( + int32_t *attrib_list, + int32_t key, + int32_t value); |