Operator Question - Not very important but good to understand

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
ChronoGraff
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Apr 22, 2015 5:42 pm

Operator Question - Not very important but good to understand

Post by ChronoGraff »

Hi guys. I have Google'd and not found an answer. I kind of understand what these operators mean but it would be great if someone could actually explain what they mean so I fully understand these operators. I see them used throughout wxWidgets and C++ itself.

Code: Select all

 &= ~()
 &=
 |=


Many thanks and greatly appreciated.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Operator Question - Not very important but good to understand

Post by doublemax »

I have Google'd and not found an answer.
I find that a little hard to believe.

I don't think i could explain it better than this:
http://en.wikipedia.org/wiki/Bitwise_operations_in_C

Can you explain what exactly you're not understanding?
Use the source, Luke!
ChronoGraff
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Apr 22, 2015 5:42 pm

Re: Operator Question - Not very important but good to understand

Post by ChronoGraff »

You find it hard that I Google'd and couldn't find an answer to why I am using these in the wxWidgets samples? hmm... that's quite pressumptious, no?

Not meaning to be rude, I said I understand partly what they are but in the sample context I do not... not meaning to sound rude. But thanks for the reply. And yes, I do Google and yes I do read documentation and no I am not an idiot lol ;) I'd just like to fully understand the following. Properly understand the following.

Maybe I asked the question incorrectly. My apologies.

Code: Select all

    style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL | wxTB_BOTTOM | wxTB_RIGHT | wxTB_TOP | wxTB_HORZ_LAYOUT);
    switch (_toolbarPosition)
    {
        case TOOLBAR_LEFT: {
            style |= wxTB_LEFT;
        } break;
        case TOOLBAR_TOP: {
            style |= wxTB_TOP;
        } break;
        case TOOLBAR_RIGHT: {
            style |= wxTB_RIGHT;
        } break;
        case TOOLBAR_BOTTOM: {
            style |= wxTB_BOTTOM;
        } break;
    }

    if (_showTooltips)
    {
        style &= ~(wxTB_NO_TOOLTIPS);
    }
    else
    {
        style |= wxTB_NO_TOOLTIPS;
    }

    if (style & wxTB_TEXT && !(style & wxTB_NOICONS) && _horizontalText)
    {
        style |= wxTB_HORZ_LAYOUT;
    }
ChronoGraff
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Apr 22, 2015 5:42 pm

Re: Operator Question - Not very important but good to understand

Post by ChronoGraff »

The samples are great, to be quite honest, I switched from QT to wxWidgets, I only want to know and understand completely what I am writing. Some areas of C++ I am grey... however in the context of wxWidgets I would like to understand fully so I can know what I am using and why.

Many thanks.

D
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Operator Question - Not very important but good to understand

Post by doublemax »

Code: Select all

wxTB_HORIZONTAL | wxTB_VERTICAL | wxTB_BOTTOM | wxTB_RIGHT | wxTB_TOP | wxTB_HORZ_LAYOUT
These defines all have values that - when displayed in binary - have only one bit set, e.g.

Code: Select all

wxTB_HORIZONTAL = 0x0004 = binary 0000.0000.0000.0100
wxTB_VERTICAL =   0x0008 = binary 0000.0000.0000.1000
These are often used as "flags" to switch a certain feature on or off. The advantage is that you can set/unset up to 32 individual flags by passing a single 32bit integer value to a function.

Code: Select all

style |= wxTB_HORIZONTAL;
The OR operator will set one individual flag (=bit)

Code: Select all

style &= ~(wxTB_HORIZONTAL);
To clear an individual flag you perform an AND with the negated value.

Code: Select all

style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL | wxTB_BOTTOM | wxTB_RIGHT | wxTB_TOP | wxTB_HORZ_LAYOUT);
This clears (set to 0) all the given flags.

I switched from QT to wxWidgets
Just out of curiosity, why?
Use the source, Luke!
ChronoGraff
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed Apr 22, 2015 5:42 pm

Re: Operator Question - Not very important but good to understand

Post by ChronoGraff »

Thats a great explanation!!! Many many thanks.

Ok... QT5 was a revelation to me. I am new to GUI programming, I love it now. Growing in experience (still novice) I found QT5 to be quite, well... quite abstracted. Too much abstraction, as if layers upon layers. It's almost like I am writing QT DSL!

Yes I understand wxWidgets has it's own macros and DSL type, not quite abstracted tho and! The most important factor is, wxWidgets uses the native UI elements of the operating system, to me it creates a smaller binary statically linked and for some reason feels a lot more elegant. There is more writing to be done, yes, and a lot to understand but the pay off is worth it.

I have written a GUI, well, I am in the process of writing and I have already had it running on 4 different platforms flawlessly. 3 versions of OS X and Windows 7. Trying that with QT was a bit of a headache, not to mention the .pro file you have use and .moc???

QT5 or QT quite simply is not the bells and whistles I expected. It abstracts too much away and I want to learn C++ but also learn how to write cross platform GUI. wxWidgets allows me to do that and easily, well... you understand what I mean by "easily". It lets me write C++! Not QT DSL! Which I have grown to dislike.

I don't understand why so many people diss wxWidgets when I find it far more low level than QT, yes its a high level abstraction to GUI programming but nowhere like QT.
Post Reply