| // Copyright 2026 Google LLC |
| // |
| // 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 |
| // |
| // https://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 THIRD_PARTY_CREDENTIO_FORMATS_FORMAT_H_ |
| #define THIRD_PARTY_CREDENTIO_FORMATS_FORMAT_H_ |
| |
| #include <memory> |
| #include <string> |
| #include <utility> |
| #include <vector> |
| |
| #include "absl/status/status.h" |
| #include "absl/status/statusor.h" |
| #include "formats/assessor.h" |
| #include "formats/extractor.h" |
| |
| namespace credentio { |
| |
| struct FormatOptions { |
| std::unique_ptr<FormatAssessor> assessor; |
| std::unique_ptr<FormatExtractor> extractor; |
| std::vector<std::string> mime_types; |
| }; |
| |
| // Format is the entry point for all format-specific logic. |
| class Format { |
| public: |
| static absl::StatusOr<std::unique_ptr<Format>> Create(FormatOptions options) { |
| if (options.assessor == nullptr) { |
| return absl::InvalidArgumentError("FormatAssessor is required"); |
| } |
| if (options.extractor == nullptr) { |
| return absl::InvalidArgumentError("FormatExtractor is required"); |
| } |
| if (options.mime_types.empty()) { |
| return absl::InvalidArgumentError("At least one mime type is required"); |
| } |
| return std::unique_ptr<Format>(new Format(std::move(options))); |
| } |
| ~Format() = default; |
| |
| const FormatAssessor* assessor() const { return assessor_.get(); } |
| |
| const FormatExtractor* extractor() const { return extractor_.get(); } |
| |
| const std::vector<std::string>& mime_types() const { return mime_types_; } |
| |
| private: |
| explicit Format(FormatOptions options) |
| : assessor_(std::move(options.assessor)), |
| extractor_(std::move(options.extractor)), |
| mime_types_(std::move(options.mime_types)) {} |
| |
| const std::unique_ptr<FormatAssessor> assessor_; |
| const std::unique_ptr<FormatExtractor> extractor_; |
| const std::vector<std::string> mime_types_; |
| }; |
| |
| } // namespace credentio |
| |
| #endif // THIRD_PARTY_CREDENTIO_FORMATS_FORMAT_H_ |