Repository: google/filament
File: filament/include/filament/Material.h (C/C++)

Code before:

    /**
     * Returns the number of parameters declared by this material.
     * The returned value can be 0.
     */
    size_t getParameterCount() const noexcept;

    /**
     * Gets information about this material's parameters.
     *
     * @param parameters A pointer to a list of ParameterInfo.
     *                   The list must be at least "count" large
     * @param count The number of parameters to retrieve. Must be >= 0 and can be > count.
     *
     * @return The number of parameters written to the parameters pointer.
     */
    size_t getParameters(ParameterInfo* UTILS_NONNULL parameters, size_t count) const noexcept;

    //! Indicates whether a parameter of the given name exists on this material.
    bool hasParameter(const char* UTILS_NONNULL name) const noexcept;

    //! Indicates whether an existing parameter is a sampler or not.
    bool isSampler(const char* UTILS_NONNULL name) const noexcept;

    //! Returns the material source (ASCII) if exists.
    const char* UTILS_NULLABLE getSource() const noexcept;
    /**
     *
     * Gets the name of the transform field associated for the given sampler parameter.
     * In the case where the parameter does not have a transform name field, it will return nullptr.
     *
     * @param samplerName the name of the sampler parameter to query.
     *
     * @return If exists, the transform name value otherwise returns a nullptr.
     */
    const char* UTILS_NULLABLE getParameterTransformName(
            const char* UTILS_NONNULL samplerName) const noexcept;

    /**
     * Sets the value of the given parameter on this material's default instance.
     *
     * @param name The name of the material parameter
     * @param value The value of the material parameter
     *
     * @see getDefaultInstance()
     */
    template <typename T>
    void setDefaultParameter(const char* UTILS_NONNULL name, T value) noexcept {
        getDefaultInstance()->setParameter(name, value);
    }


Review comment (suggestion):
You need to document clearly the lifetime of the `const char*`. Might be better to return a `std::string_view`.

Code after:

    /**
     * Returns the number of parameters declared by this material.
     * The returned value can be 0.
     */
    size_t getParameterCount() const noexcept;

    /**
     * Gets information about this material's parameters.
     *
     * @param parameters A pointer to a list of ParameterInfo.
     *                   The list must be at least "count" large
     * @param count The number of parameters to retrieve. Must be >= 0 and can be > count.
     *
     * @return The number of parameters written to the parameters pointer.
     */
    size_t getParameters(ParameterInfo* UTILS_NONNULL parameters, size_t count) const noexcept;

    //! Indicates whether a parameter of the given name exists on this material.
    bool hasParameter(const char* UTILS_NONNULL name) const noexcept;

    //! Indicates whether an existing parameter is a sampler or not.
    bool isSampler(const char* UTILS_NONNULL name) const noexcept;

    /**
     * Returns a view of the material source (.mat which is a JSON-ish file) string,
     * if it has been set. Otherwise, it returns a view of an empty string.
     * The lifetime of the string_view is tied to the lifetime of the Material.
     */
    std::string_view getSource() const noexcept;
    /**
     *
     * Gets the name of the transform field associated for the given sampler parameter.
     * In the case where the parameter does not have a transform name field, it will return nullptr.
     *
     * @param samplerName the name of the sampler parameter to query.
     *
     * @return If exists, the transform name value otherwise returns a nullptr.
     */
    const char* UTILS_NULLABLE getParameterTransformName(
            const char* UTILS_NONNULL samplerName) const noexcept;

    /**
     * Sets the value of the given parameter on this material's default instance.
     *
     * @param name The name of the material parameter
     * @param value The value of the material parameter
     *
     * @see getDefaultInstance()
     */
    template <typename T>