Здравствуйте, Константин Л., Вы писали:
КЛ>
КЛ>class MetadataType
КЛ>{
КЛ> MetadataType();
КЛ> MetadataType( const MetadataType& );
КЛ> MetadataType& operator =( const MetadataType& );
КЛ>public:
КЛ> enum Enum
КЛ> {
КЛ> CompanySymbol,
КЛ> CompanyName,
КЛ> Industry,
КЛ> Keyword,
КЛ> Other
КЛ> };
КЛ>};
КЛ>
КЛ>Позволяет четко квалифицировать значения энума.
КЛ>Кто-нибудь так делает?
Я так делаю. В нижеследующем коде рад выслушать критику. Идея была такая, чтобы параметром шаблона мог выступить ограниченный набор вариантов:
....
#if defined(WIN32)
#include <windows.h>
#define GENERIC_READ_WRITE (GENERIC_READ|GENERIC_WRITE)
#elif defined(_POSIX_)
#include <stdio.h> /* 'sprintf' */
#include <unistd.h> /* 'lseek' */
#include <fcntl.h> /* 'open' */
#include <sys/stat.h> /* 'S_IRUSR,... */
#include <sys/syslimits.h> /* 'PATH_MAX,... */
#include <errno.h> /* 'extern int errno' */
#include <string.h> /* "char* strerror( int errnum ); */
#define CloseHandle(x) close(x)
#define MAX_PATH PATH_MAX
#define INVALID_HANDLE_VALUE (-1)
#define CREATE_NEW O_CREAT|O_EXCL
#define CREATE_ALWAYS O_CREAT|O_TRUNC
#define OPEN_EXISTING 0
#define OPEN_ALWAYS O_CREAT
#define TRUNCATE_EXISTING O_TRUNC
#define GENERIC_READ O_RDONLY
#define GENERIC_WRITE O_WRONLY
#define GENERIC_READ_WRITE O_RDWR
#define FILE_BEGIN SEEK_SET
#define FILE_CURRENT SEEK_CUR
#define FILE_END SEEK_END
#define FILE_FLAG_WRITE_THROUGH O_SYNC
typedef int HANDLE;
#else
#error ERROR: WIN32 or POSIX supported!
#endif
class FileOpening {
public:
enum Enum {
CreateNew=CREATE_NEW, //!< Creates a new file. The function fails if the specified file already exists.
CreateAlways=CREATE_ALWAYS, //!< Creates a new file. If the file exists, the function overwrites the file, clears the existing attributes, and combines the file attributes and flags specified by dwFlagsAndAttributes with FILE_ATTRIBUTE_ARCHIVE.
OpenExisting=OPEN_EXISTING, //!< Opens the file. The function fails if the file does not exist.
OpenAlways=OPEN_ALWAYS, //!< Opens the file, if it exists. If the file does not exist, the function creates the file as if dwCreationDisposition were CREATE_NEW.
TruncateExisting=TRUNCATE_EXISTING //!< Opens the file. Once opened, the file is truncated so that its size is zero bytes. The calling process must open the file with at least GENERIC_WRITE access. The function fails if the file does not exist.
};
};
class FileAccess {
public:
enum Enum {
ReadOnly=GENERIC_READ, //!< Open file for reading only.
ReadWrite=GENERIC_READ_WRITE, //!< Open file for reading and writing.
WriteOnly=GENERIC_WRITE //!< Open file for writing only.
};
};
................
template <
enum FileOpening::Enum OpenTraits,
enum FileAccess::Enum AccessTraits = FileAccess::ReadOnly,
enum FileShare::Enum ShareTraits = FileShare::NoShare
> class File {
public:
................