chromium/mojo/public/cpp/bindings/lib/validate_params.h

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATE_PARAMS_H_
#define MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATE_PARAMS_H_

#include <stdint.h>

#include "base/memory/raw_ptr_exclusion.h"

namespace mojo {
namespace internal {

class ValidationContext;

ValidateEnumFunc;

// !!! Do not construct directly. Use the Get*Validator() helpers below !!!
class ContainerValidateParams {};

// !!! Do not use directly. Use the Get*Validator() helpers below !!!
//
// These templates define storage for various ContainerValidateParam instances.
// The actual storage is defined as an inline variable; this forces the linker
// to merge all instances instantiated with a given set of parameters, which
// helps greatly with binary size.
template <uint32_t expected_num_elements,
          bool element_is_nullable,
          const ContainerValidateParams* element_validate_params>
struct ArrayValidateParamsHolder {};

template <uint32_t expected_num_elements,
          bool element_is_nullable,
          ValidateEnumFunc* validate_enum_func>
struct ArrayOfEnumsValidateParamsHolder {};

template <const ContainerValidateParams& key_validate_params,
          const ContainerValidateParams& element_validate_params>
struct MapValidateParamsHolder {};

// Gets a validator for an array. If `expected_num_elements` is 0, size
// validation is skipped. `element_validate_params` may optionally be null, e.g.
// for an array of uint8_t, no nested validation of uint8_t is required.
template <uint32_t expected_num_elements,
          bool element_is_nullable,
          const ContainerValidateParams* element_validate_params>
constexpr const ContainerValidateParams& GetArrayValidator() {}

// Gets a validator for an array of enums. If `expected_num_elements` is 0, size
// validation is skipped. `validate_enum_func` must not be null.',
template <uint32_t expected_num_elements,
          bool element_is_nullable,
          ValidateEnumFunc* validate_enum_func>
constexpr const ContainerValidateParams& GetArrayOfEnumsValidator() {}

// Gets a validator for a map. Internally, a map is represented as an array of
// keys and an array of values.
template <const ContainerValidateParams& key_validate_params,
          const ContainerValidateParams& element_validate_params>
constexpr const ContainerValidateParams& GetMapValidator() {}

}  // namespace internal
}  // namespace mojo

#endif  // MOJO_PUBLIC_CPP_BINDINGS_LIB_VALIDATE_PARAMS_H_