Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CMT

macrumors regular
Original poster
Aug 24, 2009
104
10
Many headers from Apple, line the NSTableView, have structs declared containing flags:

Code:
typedef struct __TvFlags {
    unsigned int        allowsColumnReordering:1;
    unsigned int        allowsColumnResizing:1;
    unsigned int        oldDrawsGridFlag:1;
    unsigned int        allowsEmptySelection:1;
    unsigned int        allowsMultipleSelection:1;
    unsigned int        allowsColumnSelection:1;
    unsigned int        selectionType:2;
    unsigned int        changingLayout:1; // Unused
    unsigned int        compareWidthWithSuperview:2;
    unsigned int        delegateWillDisplayCell:1;
    ...
    unsigned int        delegateShouldEditTableColumn:1;
    unsigned int        delegateShouldSelectRow:1;
    unsigned int        delegateShouldSelectTableColumn:1;
    unsigned int        delegateSelectionShouldChangeInTableView:1;
    unsigned int        oldAutoresizesAllColumnsToFit:1;
    unsigned int        dataSourceSetObjectValue:1;
    unsigned int        selectionPostingDisableCount:7;
} _TvFlags;

This brings me 2 questions:

1.What is this ":1" (or ":2") at the end of each line? I've never seen this!
2.How can I then access this struct from inside object: _TvFlags.(~) or _TvFlags->(~) (dereferenced)

Thanks!
 
Look up "bit fields" in a C language reference doc.

2.How can I then access this struct from inside object: _TvFlags.(~) or _TvFlags->(~) (dereferenced)
That doesn't make syntactical sense. _TvFlags is a typedef. You wouldn't use uint_32.(~). I'm not even sure what you intend (~) to mean.

If your question is, "How do I access the bit fields of the _tvFlags member variable, whose type is _TvFlags?", then the answer can be obtained by looking up "bit fields" in a C language reference doc. The short answer is: the same way you'd access any other member of any other struct. Since NSSize or NSRect is also a typedef'ed struct, consider how you'd access its members.

And you'd do well to heed this comment from NSTableView.h:
Code:
 /*All instance variables are private*/
 
Look up "bit fields" in a C language reference doc.
Thanks. I had never learned about it (beginner programmer)

That doesn't make syntactical sense. _TvFlags is a typedef.
Indeed. Sorry, I mean to use the struct itself like you concluded.

I'm not even sure what you intend (~) to mean.
Means "something".

The short answer is: the same way you'd access any other member of any other struct. Since NSSize or NSRect is also a typedef'ed struct, consider how you'd access its members.
Ok, thanks for the comparison which clarified things.

And you'd do well to heed this comment from NSTableView.h:
Code:
 /*All instance variables are private*/
I know they are private, and I do not intent to use this struct, just pointed it out. I will be using these struct's to flags in my classes.

Thank you chown33, everything is clear now.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.