Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 197ad625 authored by Sean Kim's avatar Sean Kim Committed by Gerrit Code Review
Browse files

Merge "codec2: Fix ambiguity in operator overloads" into main

parents 9b1c4a98 9ae27447
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -427,7 +427,9 @@ public:
    inline bool operator==(const C2Param &o) const {
        return equals(o) && memcmp(this, &o, _mSize) == 0;
    }
#if __cplusplus < 202002
    inline bool operator!=(const C2Param &o) const { return !operator==(o); }
#endif

    /// safe(r) type cast from pointer and size
    inline static C2Param* From(void *addr, size_t len) {
+28 −8
Original line number Diff line number Diff line
@@ -212,6 +212,26 @@ protected:
    }
};

/// Define equality (and inequality) operators for params.
#if __cplusplus < 202002

#define DEFINE_EQUALITY_OPERATORS(_Type, T) \
    inline bool operator==(const _Type &o) const { \
        return this->T::operator==(o); \
    } \
    inline bool operator!=(const _Type &o) const { \
    return !operator==(o); \
    }

#else

#define DEFINE_EQUALITY_OPERATORS(_Type, T) \
    inline bool operator==(const _Type &o) const { \
        return this->T::operator==(o); \
    }

#endif

/// Define From() cast operators for params.
#define DEFINE_CAST_OPERATORS(_Type) \
    inline static _Type* From(C2Param *other) { \
@@ -404,12 +424,12 @@ public:
    /// Specialization for an input port parameter.
    struct input : public T, public S,
            public _C2StructCheck<S, ParamIndex, T::PARAM_KIND | T::Index::DIR_INPUT> {
        using T::operator!=;
        _C2_CORE_INDEX_OVERRIDE(ParamIndex)
        /// Wrapper around base structure's constructor.
        template<typename ...Args>
        inline input(const Args(&... args)) : T(sizeof(_Type), input::PARAM_TYPE), S(args...) { }

        DEFINE_EQUALITY_OPERATORS(input, T)
        DEFINE_CAST_OPERATORS(input)

    };
@@ -417,12 +437,12 @@ public:
    /// Specialization for an output port parameter.
    struct output : public T, public S,
            public _C2StructCheck<S, ParamIndex, T::PARAM_KIND | T::Index::DIR_OUTPUT> {
        using T::operator!=;
        _C2_CORE_INDEX_OVERRIDE(ParamIndex)
        /// Wrapper around base structure's constructor.
        template<typename ...Args>
        inline output(const Args(&... args)) : T(sizeof(_Type), output::PARAM_TYPE), S(args...) { }

        DEFINE_EQUALITY_OPERATORS(output, T)
        DEFINE_CAST_OPERATORS(output)
    };
};
@@ -472,7 +492,6 @@ public:
    /// Specialization for an input port parameter.
    struct input : public T,
            public _C2FlexStructCheck<S, ParamIndex, T::PARAM_KIND | T::Index::DIR_INPUT> {
        using T::operator!=;
    private:
        /// Wrapper around base structure's constructor while also specifying port/direction.
        template<typename ...Args>
@@ -482,6 +501,7 @@ public:
    public:
        S m; ///< wrapped flexible structure

        DEFINE_EQUALITY_OPERATORS(input, T)
        DEFINE_FLEXIBLE_METHODS(input, S)
        DEFINE_CAST_OPERATORS(input)
    };
@@ -489,7 +509,6 @@ public:
    /// Specialization for an output port parameter.
    struct output : public T,
            public _C2FlexStructCheck<S, ParamIndex, T::PARAM_KIND | T::Index::DIR_OUTPUT> {
        using T::operator!=;
    private:
        /// Wrapper around base structure's constructor while also specifying port/direction.
        template<typename ...Args>
@@ -499,6 +518,7 @@ public:
    public:
        S m; ///< wrapped flexible structure

        DEFINE_EQUALITY_OPERATORS(output, T)
        DEFINE_FLEXIBLE_METHODS(output, S)
        DEFINE_CAST_OPERATORS(output)
    };
@@ -553,7 +573,6 @@ public:
    struct input : public T, public S,
            public _C2StructCheck<S, ParamIndex,
                    T::PARAM_KIND | T::Index::IS_STREAM_FLAG | T::Type::DIR_INPUT> {
        using T::operator!=;
        _C2_CORE_INDEX_OVERRIDE(ParamIndex)

        /// Default constructor. Stream-ID is undefined.
@@ -565,6 +584,7 @@ public:
        /// Set stream-id. \retval true if the stream-id was successfully set.
        inline bool setStream(unsigned stream) { return C2Param::setStream(stream); }

        DEFINE_EQUALITY_OPERATORS(input, T)
        DEFINE_CAST_OPERATORS(input)
    };

@@ -572,7 +592,6 @@ public:
    struct output : public T, public S,
            public _C2StructCheck<S, ParamIndex,
                    T::PARAM_KIND | T::Index::IS_STREAM_FLAG | T::Type::DIR_OUTPUT> {
        using T::operator!=;
        _C2_CORE_INDEX_OVERRIDE(ParamIndex)

        /// Default constructor. Stream-ID is undefined.
@@ -584,6 +603,7 @@ public:
        /// Set stream-id. \retval true if the stream-id was successfully set.
        inline bool setStream(unsigned stream) { return C2Param::setStream(stream); }

        DEFINE_EQUALITY_OPERATORS(output, T)
        DEFINE_CAST_OPERATORS(output)
    };
};
@@ -640,7 +660,6 @@ public:
    struct input : public T,
            public _C2FlexStructCheck<S, ParamIndex,
                    T::PARAM_KIND | T::Index::IS_STREAM_FLAG | T::Type::DIR_INPUT> {
        using T::operator!=;
    private:
        /// Default constructor. Stream-ID is undefined.
        inline input(size_t flexCount) : T(_Type::CalcSize(flexCount), input::PARAM_TYPE) { }
@@ -655,6 +674,7 @@ public:
        /// Set stream-id. \retval true if the stream-id was successfully set.
        inline bool setStream(unsigned stream) { return C2Param::setStream(stream); }

        DEFINE_EQUALITY_OPERATORS(input, T)
        DEFINE_FLEXIBLE_METHODS(input, S)
        DEFINE_CAST_OPERATORS(input)
    };
@@ -663,7 +683,6 @@ public:
    struct output : public T,
            public _C2FlexStructCheck<S, ParamIndex,
                    T::PARAM_KIND | T::Index::IS_STREAM_FLAG | T::Type::DIR_OUTPUT> {
        using T::operator!=;
    private:
        /// Default constructor. Stream-ID is undefined.
        inline output(size_t flexCount) : T(_Type::CalcSize(flexCount), output::PARAM_TYPE) { }
@@ -678,6 +697,7 @@ public:
        /// Set stream-id. \retval true if the stream-id was successfully set.
        inline bool setStream(unsigned stream) { return C2Param::setStream(stream); }

        DEFINE_EQUALITY_OPERATORS(output, T)
        DEFINE_FLEXIBLE_METHODS(output, S)
        DEFINE_CAST_OPERATORS(output)
    };
+1 −1
Original line number Diff line number Diff line
@@ -235,7 +235,7 @@ void C2CompIntfTest::queryParamAsExpected(const T &expected) {
    // |*heapParams[0]| is a parameter value. The size of |heapParams| has to be one.
    ASSERT_EQ(1u, heapParams.size());
    EXPECT_TRUE(heapParams[0]);
    EXPECT_EQ(*heapParams[0], expected);
    EXPECT_EQ(*heapParams[0], (C2Param &)(expected));
}

template <typename T> void C2CompIntfTest::querySupportedParam() {