Abstract base class for SmartEnums. Contains no members, just provided as a convenient way of checking that a class is in fact a SmartEnum, using is(T : ISmartEnum).
Struct template representing a single member of an enum -- containing a string for the enum identifier and a code for the corresponding value.
Two way map struct template
Template to mixin a SmartEnum class with the codes automatically generated, starting at 0.
Template to mixin a SmartEnum class.
Members forming the core of each class generated by the SmartEnum mixin. This template is mixed into each class created by the SmartEnum template.
Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. Alternatively, this file may be distributed under the terms of the Tango 3-Clause BSD License (see LICENSE_BSD.txt for details).
Copyright (c) 2009-2016 dunnhumby Germany GmbH. All rights reserved.
Smart enum template class, encapsulates an enum with a map of its codes and descriptions.
Contains two main mixin templates:
1. SmartEnum 2. AutoSmartEnum
1. SmartEnum
import ocean.core.SmartEnum; import ocean.io.Stdout;
alias SmartEnumValue!(int) Code;
mixin(SmartEnum!("Commands", Code("first", 1), Code("second", 2) ));
// Getting descriptions of codes // (Note that the getter methods work like opIn, returning pointers.) Stdout.formatln("Description for code first = {}", *Commands.description(Commands.first)); Stdout.formatln("Description for code 1 = {}", *Commands.description(1));
// Getting codes by description // (Note that the getter methods work like opIn, returning pointers.) Stdout.formatln("Code for description 'first' = {}", *Commands.code("first"));
// Testing whether codes exist Stdout.formatln("1 in enum? {}", !!(1 in Commands)); Stdout.formatln("first in enum? {}", !!(Commands.first in Commands));
// Testing whether codes exist by description Stdout.formatln("'first' in enum? {}", !!("first" in Commands)); Stdout.formatln("'third' in enum? {}", !!("third" in Commands));
// Iteration over enum foreach ( code, descr; Commands ) { Stdout.formatln("{} -> {}", code, descr); }
Template to automatically create a SmartEnum from a list of strings. The enum's base type is specified, and the enum values are automatically numbered, starting at 0.
Usage example: