Opened 10 years ago

Closed 9 years ago

#8020 closed defect (Invalid)

UIUtilDisp is some strange....

Reported by: sunny an Owned by: stuartm
Priority: minor Milestone: 0.24
Component: MythTV - User Interface Library Version: 0.22
Severity: medium Keywords: Assign
Cc: Ticket locked: no

Description

template <typename ErrorDispatch = ETPrintWarning>
struct UIUtilDisp
{
    template <typename ContainerType, typename UIType>
    static bool Assign(ContainerType *container, UIType *&item,
                       const QString &name, bool *err = NULL)
    {
        if (!container)
        {
            if (err)
                *err |= ErrorDispatch::Container(name);
            else
                ErrorDispatch::Container(name);
            return true;
        }

        item = dynamic_cast<UIType *>(container->GetChild(name));

        if (item)
            return false;
        
        /* from here, item had NULL definitely. Where err value is set from? */

        if (err)
            *err |= ErrorDispatch::Child(container->objectName(), name);
        else
            ErrorDispatch::Child(container->objectName(), name);
        return true;
    }
};

above code snippet is in lib/libmythui/mythuiutls.h

In following codes, event though GetChild?("ex") failed, err get false.
But I think that err should have get true after run UIUtilE::Assign.

bool err = false;
UIUtilE::Assign(this, m_example, "ex", &err);

Change History (5)

comment:1 Changed 10 years ago by stuartm

Owner: changed from stuartm to Anduin Withers
Status: newassigned

comment:2 Changed 10 years ago by stuartm

Milestone: 0.22unknown

comment:3 Changed 9 years ago by robertm

Owner: changed from Anduin Withers to stuartm

comment:4 Changed 9 years ago by stuartm

Milestone: unknown0.24
Status: assignedaccepted

comment:5 Changed 9 years ago by stuartm

Resolution: Invalid
Status: acceptedclosed

Although I'd agree that this code does not read easily, with all the templating etc it's obscure to say the least, the logic appears correct.

if item is null, then we evaluate if (err) (true, err is a pointer not a bool), we then do a OR (|) bit op to *err (address of err, a bool).

Note: See TracTickets for help on using tickets.