Hello all,
Sorry to ask such a simple question, but I just want to be absolutely sure I've grokked this concept properly:
I want to get and set various bits (flags) in a long using masks defined in internetConfig.h (see below
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">
typedef long ICMapEntryFlags;
typedef short ICFixedLength;
#if !OLDROUTINENAMES
struct ICMapEntry {
short totalLength;
ICFixedLength fixedLength;
short version;
OSType fileType;
OSType fileCreator;
OSType postCreator;
ICMapEntryFlags flags;
Str255 extension;
Str255 creatorAppName;
Str255 postAppName;
Str255 MIMEType;
Str255 entryName;
....
enum {
kICMapBinaryBit = 0, /* file should be transfered in binary as opposed to text mode*/
kICMapResourceForkBit = 1, /* the resource fork of the file is significant*/
kICMapDataForkBit = 2, /* the data fork of the file is significant*/
kICMapPostBit = 3, /* post process using post fields*/
kICMapNotIncomingBit = 4, /* ignore this mapping for incoming files*/
kICMapNotOutgoingBit = 5 /* ignore this mapping for outgoing files*/
};
enum {
kICMapBinaryMask = 0x00000001, /* file should be transfered in binary as opposed to text mode*/
kICMapResourceForkMask = 0x00000002, /* the resource fork of the file is significant*/
kICMapDataForkMask = 0x00000004, /* the data fork of the file is significant*/
kICMapPostMask = 0x00000008, /* post process using post fields*/
kICMapNotIncomingMask = 0x00000010, /* ignore this mapping for incoming files*/
kICMapNotOutgoingMask = 0x00000020 /* ignore this mapping for outgoing files*/
};
};</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I have read the following link:
<a href="http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=bit+mask&action=Search" target="_blank">http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=bit+mask&action=Search</a>
which lead me to write the following code:
("entry" is an instance variable.)
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">
-(BOOL)shouldIgnoreMappingForOutgoingFiles
{
ICMapEntryFlags flags;
BOOL ignore;
flags=entry.flags;
ignore=(flags & kICMapNotOutgoingMask);
return ignore;
}
-(void)setShouldIgnoreMappingForOutgoingFiles

BOOL )yn
{
ICMapEntryFlags flags;
if (yn) {
flags=(entry.flags | kICMapNotOutgoingMask);
} else {
flags=(entry.flags ^ kICMapNotOutgoingMask);
}
entry.flags=flags;
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">If I want to alter "flags" so that just the "not outgoing" bit is set to YES then I use bitwise OR.
If I want to alter "flags" so that just the "not outgoing" bit is set to NO then I use bitwise Exclusive OR.
Is this right? The reading part seems to work, but the setting has some very strange behaviour.
<small>[ 07-13-2002, 10:08 AM: Message edited by: Diggory Laycock ]</small>