chromium/third_party/fuzztest/src/fuzztest/internal/domains/domain_type_erasure.h

// Copyright 2022 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
//
//      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.

// IWYU pragma: private, include "fuzztest/fuzztest.h"
// IWYU pragma: friend fuzztest/internal/domains/domain_base.h

// This header file contains implementation details of the domain type erasure.
// The classes `UntypedDomainConcept`, `TypedDomainConcept`, and `DomainModel`
// should not be used directly. Instead, use the domain interfaces `Domain<T>`
// and `UntypedDomain`.

#ifndef FUZZTEST_FUZZTEST_INTERNAL_DOMAINS_DOMAIN_TYPE_ERASURE_H_
#define FUZZTEST_FUZZTEST_INTERNAL_DOMAINS_DOMAIN_TYPE_ERASURE_H_

#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <memory>
#include <optional>

#include "absl/functional/function_ref.h"
#include "absl/random/bit_gen_ref.h"
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "./fuzztest/internal/any.h"
#include "./fuzztest/internal/logging.h"
#include "./fuzztest/internal/meta.h"
#include "./fuzztest/internal/printer.h"
#include "./fuzztest/internal/serialization.h"

namespace fuzztest {

GenericDomainValueType;
GenericDomainCorpusType;

namespace internal {

// `UntypedDomainConcept` erases value_type/corpus_type type information for all
// inputs and outputs. All the `Untyped[Name]` functions implement the same API
// as the `[Name]` functions, but marshall the inputs and output through the
// generic types.
class UntypedDomainConcept {};

// `TypedDomainConcept<ValueType>` extends `UntypedDomainConcept` with methods
// that handle `ValueType` inputs/outputs.
template <typename ValueType>
class TypedDomainConcept : public UntypedDomainConcept {};

// `DomainModel<D>` is a wrapper around a concrete domain `D`. It implements the
// concept classes `UntypedDomainConcept` and `TypedDomainConcept<ValueType>` by
// delegating the calls to `Untyped[Name]` and `Typed[Name]` functions to the
// corresponding `[Name]` functions on the wrapped domain.
template <typename D>
class DomainModel final : public TypedDomainConcept<value_type_t<D>> {};

}  //  namespace internal
}  //  namespace fuzztest

#endif  // FUZZTEST_FUZZTEST_INTERNAL_DOMAINS_DOMAIN_TYPE_ERASURE_H_