Enums

From Apache OpenOffice Wiki
Jump to: navigation, search



Enums are non-arbitrary sets of identifying values. If an interface uses an enum type, all implementations have to implement all specified enum values. It is possible to specify exceptions at the interface. Extending enums is not allowed, because this would cause incompatibilities.

Naming

Enum types begin with an uppercase letter and are put in initial caps. Avoid abbreviations. If there is a possible name-conflict with structs using the same name, add Type or Style to the enum identifier.

Enum values are completely capitalized in uppercase and words are separated by underscores. Do not use a variant of the enum type name as a prefix for the values, because some language bindings will do that automatically.

  enum FooBarType
  {
    NONE,
    READ,
    WRITE,
    USER_DEFINED = 255
  };
 
  struct FooBar
  {
    FooBarType Type;
    string FileName
  };

Three typical endings of special enum values are _NONE, _ALL and _USER_DEFINED.

Usage

If by general fact an enum represents the most common values within an open set, add a value for USER_DEFINED and specify the actual meaning by a string in the same object or argument list where the enum is used. In this case, offer a method that returns a sequence of all possible values of this string.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages