Listing 2: Header for class FileAttributes
#if !defined(FILEATTRIBUTES_H_)
#define FILEATTRIBUTES_H_
#include <windows.h>
#include <stdexcept>
#if defined(__BORLANDC__)
using namespace std;
#endif
class FileAttributes {
DWORD attributes;
public:
// "Get" functions
inline BOOL IsDirectory() const throw() {
return ((attributes & FILE_ATTRIBUTE_DIRECTORY )!=0); }
inline BOOL IsArchive() const throw() {
return ((attributes & FILE_ATTRIBUTE_ARCHIVE )!=0); }
// portions omitted ...
inline BOOL IsTemporary() const throw() {
return ((attributes & FILE_ATTRIBUTE_TEMPORARY )!=0); }
// Sometimes it's more useful just to have the raw number and do
// your own comparisons versus the various FILE_ATTRIBUTE_
// constants.
inline DWORD Value() const throw() { return attributes; }
// "Set" functions
inline void IsDirectory (const BOOL SetBit) throw() {
if(SetBit) attributes |= FILE_ATTRIBUTE_DIRECTORY;
else attributes &= (~FILE_ATTRIBUTE_DIRECTORY );}
inline void IsArchive (const BOOL SetBit) throw() {
if(SetBit) attributes |= FILE_ATTRIBUTE_ARCHIVE;
else attributes &= (~FILE_ATTRIBUTE_ARCHIVE );}
// portions omitted ...
inline void IsTemporary (const BOOL SetBit) throw() {
if(SetBit) attributes |= FILE_ATTRIBUTE_TEMPORARY;
else attributes &= (~FILE_ATTRIBUTE_TEMPORARY );}
// Constructors. Can construct from a DWORD or another
// FileAttribute object.
inline FileAttributes(const DWORD NewAttributes=0) throw() :
attributes(NewAttributes) {}
inline FileAttributes(const FileAttributes& FA) throw() {
attributes=FA.attributes; }
//Assignment operator is defined for other FileAttribute objects
//as well as for DWORDS
inline FileAttributes& operator=(const FileAttributes& FA)
throw() {
if(&FA != this) attributes=FA.attributes; return *this; }
inline FileAttributes& operator=(const DWORD dw) throw() {
attributes=dw; return *this; }
};
#endif // FILEATTRIBUTES_H_
/* End of File */