Skip to content

Commit

Permalink
Ensure that C header don't import C++ types
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 564435119
  • Loading branch information
schmidt-sebastian authored and copybara-github committed Sep 11, 2023
1 parent e206f9a commit 315982d
Show file tree
Hide file tree
Showing 18 changed files with 194 additions and 49 deletions.
21 changes: 18 additions & 3 deletions mediapipe/tasks/c/components/containers/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
15 changes: 6 additions & 9 deletions mediapipe/tasks/c/components/containers/category.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
29 changes: 29 additions & 0 deletions mediapipe/tasks/c/components/containers/category_converter.h
Original file line number Diff line number Diff line change
@@ -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_
15 changes: 5 additions & 10 deletions mediapipe/tasks/c/components/containers/classification_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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_
12 changes: 10 additions & 2 deletions mediapipe/tasks/c/components/processors/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
16 changes: 7 additions & 9 deletions mediapipe/tasks/c/components/processors/classifier_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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_
12 changes: 10 additions & 2 deletions mediapipe/tasks/c/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
13 changes: 4 additions & 9 deletions mediapipe/tasks/c/core/base_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
29 changes: 29 additions & 0 deletions mediapipe/tasks/c/core/base_options_converter.h
Original file line number Diff line number Diff line change
@@ -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_
3 changes: 3 additions & 0 deletions mediapipe/tasks/c/text/text_classifier/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
3 changes: 3 additions & 0 deletions mediapipe/tasks/c/text/text_classifier/text_classifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 315982d

Please sign in to comment.