Ensure that C header don't import C++ types

PiperOrigin-RevId: 564435119
This commit is contained in:
Sebastian Schmidt 2023-09-11 10:45:05 -07:00 committed by Copybara-Service
parent e206f9acdb
commit 315982df0f
18 changed files with 194 additions and 49 deletions

View File

@ -18,17 +18,32 @@ licenses(["notice"])
cc_library(
name = "category",
srcs = ["category.cc"],
hdrs = ["category.h"],
deps = ["//mediapipe/tasks/cc/components/containers:category"],
)
cc_library(
name = "category_converter",
srcs = ["category_converter.cc"],
hdrs = ["category_converter.h"],
deps = [
":category",
"//mediapipe/tasks/cc/components/containers:category",
],
)
cc_library(
name = "classification_result",
srcs = ["classification_result.cc"],
hdrs = ["classification_result.h"],
)
cc_library(
name = "classification_result_converter",
srcs = ["classification_result_converter.cc"],
hdrs = ["classification_result_converter.h"],
deps = [
":category",
":category_converter",
":classification_result",
"//mediapipe/tasks/cc/components/containers:classification_result",
],
)

View File

@ -16,9 +16,10 @@ limitations under the License.
#ifndef MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_CATEGORY_H_
#define MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_CATEGORY_H_
#include "mediapipe/tasks/cc/components/containers/category.h"
#ifdef __cplusplus
extern "C" {
#endif
// Defines a single classification result.
//
// The label maps packed into the TFLite Model Metadata [1] are used to populate
@ -41,13 +42,9 @@ struct Category {
// packed in the TFLite Model Metadata if present.
const char* display_name;
};
}
namespace mediapie::tasks::c::components::containers {
void CppConvertToCategory(mediapipe::tasks::components::containers::Category in,
Category* out);
} // namespace mediapie::tasks::c::components::containers
#ifdef __cplusplus
} // extern C
#endif
#endif // MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_CATEGORY_H_

View File

@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "mediapipe/tasks/c/components/containers/category.h"
#include "mediapipe/tasks/c/components/containers/category_converter.h"
namespace mediapie::tasks::c::components::containers {

View File

@ -0,0 +1,29 @@
/* Copyright 2023 The MediaPipe Authors.
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 MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_CATEGORY_CONVERTER_H_
#define MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_CATEGORY_CONVERTER_H_
#include "mediapipe/tasks/c/components/containers/category.h"
#include "mediapipe/tasks/cc/components/containers/category.h"
namespace mediapie::tasks::c::components::containers {
void CppConvertToCategory(mediapipe::tasks::components::containers::Category in,
Category* out);
} // namespace mediapie::tasks::c::components::containers
#endif // MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_CATEGORY_CONVERTER_H_

View File

@ -19,9 +19,9 @@ limitations under the License.
#include <stdbool.h>
#include <stdint.h>
#include "mediapipe/tasks/cc/components/containers/classification_result.h"
#ifdef __cplusplus
extern "C" {
#endif
// Defines classification results for a given classifier head.
struct Classifications {
@ -60,14 +60,9 @@ struct ClassificationResult {
// Specifies whether the timestamp contains a valid value.
bool has_timestamp_ms;
};
}
namespace mediapipe::tasks::c::components::containers {
void CppConvertToClassificationResult(
mediapipe::tasks::components::containers::ClassificationResult in,
ClassificationResult* out);
} // namespace mediapipe::tasks::c::components::containers
#ifdef __cplusplus
} // extern C
#endif
#endif // MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_CLASSIFICATION_RESULT_H_

View File

@ -13,9 +13,10 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "mediapipe/tasks/c/components/containers/classification_result.h"
#include "mediapipe/tasks/c/components/containers/classification_result_converter.h"
#include "mediapipe/tasks/c/components/containers/category.h"
#include "mediapipe/tasks/c/components/containers/category_converter.h"
namespace mediapipe::tasks::c::components::containers {

View File

@ -0,0 +1,30 @@
/* Copyright 2023 The MediaPipe Authors.
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 MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_CLASSIFICATION_RESULT_CONVERTER_H_
#define MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_CLASSIFICATION_RESULT_CONVERTER_H_
#include "mediapipe/tasks/c/components/containers/classification_result.h"
#include "mediapipe/tasks/cc/components/containers/classification_result.h"
namespace mediapipe::tasks::c::components::containers {
void CppConvertToClassificationResult(
mediapipe::tasks::components::containers::ClassificationResult in,
ClassificationResult* out);
} // namespace mediapipe::tasks::c::components::containers
#endif // MEDIAPIPE_TASKS_C_COMPONENTS_CONTAINERS_CLASSIFICATION_RESULT_CONVERTER_H_

View File

@ -18,7 +18,15 @@ licenses(["notice"])
cc_library(
name = "classifier_options",
srcs = ["classifier_options.cc"],
hdrs = ["classifier_options.h"],
deps = ["//mediapipe/tasks/cc/components/processors:classifier_options"],
)
cc_library(
name = "classifier_options_converter",
srcs = ["classifier_options_converter.cc"],
hdrs = ["classifier_options_converter.h"],
deps = [
":classifier_options",
"//mediapipe/tasks/cc/components/processors:classifier_options",
],
)

View File

@ -18,7 +18,9 @@ limitations under the License.
#include <stdint.h>
#include "mediapipe/tasks/cc/components/processors/classifier_options.h"
#ifdef __cplusplus
extern "C" {
#endif
// Classifier options for MediaPipe C classification Tasks.
struct ClassifierOptions {
@ -45,17 +47,13 @@ struct ClassifierOptions {
// The denylist of category names. If non-empty, detection results whose
// category name is in this set will be filtered out. Duplicate or unknown
// category names are ignored. Mutually exclusive with category_allowlist.
char** category_denylist = {};
char** category_denylist;
// The number of elements in the category denylist.
uint32_t category_denylist_count;
};
namespace mediapipe::tasks::c::components::processors {
void CppConvertToClassifierOptions(
ClassifierOptions in,
mediapipe::tasks::components::processors::ClassifierOptions* out);
} // namespace mediapipe::tasks::c::components::processors
#ifdef __cplusplus
} // extern C
#endif
#endif // MEDIAPIPE_TASKS_C_COMPONENTS_PROCESSORS_CLASSIFIER_OPTIONS_H_

View File

@ -13,11 +13,10 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "mediapipe/tasks/c/components/processors/classifier_options.h"
#include <cstdint>
#include <vector>
#include "mediapipe/tasks/c/components/processors/classifier_options.h"
#include "mediapipe/tasks/cc/components/processors/classifier_options.h"
namespace mediapie::c::components::processors {

View File

@ -0,0 +1,30 @@
/* Copyright 2023 The MediaPipe Authors.
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 MEDIAPIPE_TASKS_C_COMPONENTS_PROCESSORS_CLASSIFIER_OPTIONS_CONVERTER_H_
#define MEDIAPIPE_TASKS_C_COMPONENTS_PROCESSORS_CLASSIFIER_OPTIONS_CONVERTER_H_
#include "mediapipe/tasks/c/components/processors/classifier_options.h"
#include "mediapipe/tasks/cc/components/processors/classifier_options.h"
namespace mediapipe::tasks::c::components::processors {
void CppConvertToClassifierOptions(
ClassifierOptions in,
mediapipe::tasks::components::processors::ClassifierOptions* out);
} // namespace mediapipe::tasks::c::components::processors
#endif // MEDIAPIPE_TASKS_C_COMPONENTS_PROCESSORS_CLASSIFIER_OPTIONS_CONVERTER_H_

View File

@ -18,7 +18,15 @@ licenses(["notice"])
cc_library(
name = "base_options",
srcs = ["base_options.cc"],
hdrs = ["base_options.h"],
deps = ["//mediapipe/tasks/cc/core:base_options"],
)
cc_library(
name = "base_options_converter",
srcs = ["base_options_converter.cc"],
hdrs = ["base_options_converter.h"],
deps = [
":base_options",
"//mediapipe/tasks/cc/core:base_options",
],
)

View File

@ -16,9 +16,9 @@ limitations under the License.
#ifndef MEDIAPIPE_TASKS_C_CORE_BASE_OPTIONS_H_
#define MEDIAPIPE_TASKS_C_CORE_BASE_OPTIONS_H_
#include "mediapipe/tasks/cc/core/base_options.h"
#ifdef __cplusplus
extern "C" {
#endif
// Base options for MediaPipe C Tasks.
struct BaseOptions {
@ -29,13 +29,8 @@ struct BaseOptions {
char* model_asset_path;
};
#ifdef __cplusplus
} // extern C
namespace mediapipe::tasks::c::components::containers {
void CppConvertToBaseOptions(BaseOptions in,
mediapipe::tasks::core::BaseOptions* out);
} // namespace mediapipe::tasks::c::components::containers
#endif
#endif // MEDIAPIPE_TASKS_C_CORE_BASE_OPTIONS_H_

View File

@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "mediapipe/tasks/c/core/base_options.h"
#include "mediapipe/tasks/c/core/base_options_converter.h"
#include "mediapipe/tasks/cc/core/base_options.h"

View File

@ -0,0 +1,29 @@
/* Copyright 2023 The MediaPipe Authors.
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 MEDIAPIPE_TASKS_C_CORE_BASE_OPTIONS_CONVERTER_H_
#define MEDIAPIPE_TASKS_C_CORE_BASE_OPTIONS_CONVERTER_H_
#include "mediapipe/tasks/c/core/base_options.h"
#include "mediapipe/tasks/cc/core/base_options.h"
namespace mediapipe::tasks::c::components::containers {
void CppConvertToBaseOptions(BaseOptions in,
mediapipe::tasks::core::BaseOptions* out);
} // namespace mediapipe::tasks::c::components::containers
#endif // MEDIAPIPE_TASKS_C_CORE_BASE_OPTIONS_H_

View File

@ -23,8 +23,11 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
"//mediapipe/tasks/c/components/containers:classification_result",
"//mediapipe/tasks/c/components/containers:classification_result_converter",
"//mediapipe/tasks/c/components/processors:classifier_options",
"//mediapipe/tasks/c/components/processors:classifier_options_converter",
"//mediapipe/tasks/c/core:base_options",
"//mediapipe/tasks/c/core:base_options_converter",
"//mediapipe/tasks/cc/text/text_classifier",
"@com_google_absl//absl/log:absl_log",
],

View File

@ -19,8 +19,11 @@ limitations under the License.
#include "absl/log/absl_log.h"
#include "mediapipe/tasks/c/components/containers/classification_result.h"
#include "mediapipe/tasks/c/components/containers/classification_result_converter.h"
#include "mediapipe/tasks/c/components/processors/classifier_options.h"
#include "mediapipe/tasks/c/components/processors/classifier_options_converter.h"
#include "mediapipe/tasks/c/core/base_options.h"
#include "mediapipe/tasks/c/core/base_options_converter.h"
#include "mediapipe/tasks/cc/text/text_classifier/text_classifier.h"
namespace mediapipe::tasks::c::text::text_classifier {

View File

@ -20,7 +20,10 @@ limitations under the License.
#include "mediapipe/tasks/c/components/processors/classifier_options.h"
#include "mediapipe/tasks/c/core/base_options.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef ClassificationResult TextClassifierResult;
// The options for configuring a MediaPipe text classifier task.
@ -44,6 +47,8 @@ bool text_classifier_classify(void* classifier, char* utf8_str,
// Shuts down the TextClassifier when all the work is done. Frees all memory.
void text_classifier_close(void* classifier);
#ifdef __cplusplus
} // extern C
#endif
#endif // MEDIAPIPE_TASKS_C_TEXT_TEXT_CLASSIFIER_TEXT_CLASSIFIER_H_