Giter VIP home page Giter VIP logo

enum_extend's Introduction

Enum Extend {#mainpage}

A C++ library that extends the functionality of enums.

Motivation

C++, the STL and boost lack some often needed functionality in regard to enums:

  • It is not possible to iterate over all defined enumerated values.
  • There are no pre or postfix ++/-- operators to advance to the next defined enumerated value.
  • Often enumerated values needs a string representation to further operations - at least to log those into files.

Enum Extend Library Overview

The following is possible with this library:

  using enum_extend::range;
  using enum_extend::extender;
  using enum_extend::filtered_range;
  
  enum Color
  {
    Red = 0, 
    Green = 4, 
    Blue = 8
  };

  // Let's walk over all defined values
  for (auto c : range<Color>()) {
    // ...
  }
  
  auto c = Color::Red;
  // we can increase as well
  ++c;

  // We iterate in reverse order over all defined values
  std::vector<Color> allReverseColors;
  std::copy(extender<Color>::rbegin(),
            extender<Color>::rend(), 
            std::back_inserter(allReverseColors));


  // Just iterate over all values that match a certain criteria; 
  // usefull if the enumerated values are defined as combined bit fields
  auto FilterRed = [](Color c) { return c == Color::Red; };
  for (auto c : filtered_range<Color>(FilterRed)) {
    // Do just something with red values
  }
  
  
  // easier can this be archived by the following macros:
  
  // for the header file
  #define MACROCOLOR_ENUM_SPEC (MacroColorEnum, (Red)(Green)(Blue))
  ENUM_EXTEND_DECLARE_ENUM(MACROCOLOR_ENUM_SPEC)
  
  // for the cpp file
  ENUM_EXTEND_DEFINE_ENUM(MACROCOLOR_ENUM_SPEC)

Macros exist as well for creating an enum class or a typed enum class.

Documentation

A first tutorial is here A summary of all macros is here

Author

Felix Petriconi (felix at petriconi.net)

Contributions

Comments, feedback or contributions are welcome!

License

Boost 1.0 License

Version

0.1 (alpha)

Prerequisites

  • C++ 11 (partly, as far as Visual Studio 2013 supports it)
  • CMake 2.8 or later
  • Boost Preprocessor (1.55)
  • GoogleTest 1.7 (It is part of the repository, because it's CMakeFiles.txt needs some patches to compile with Visual Studio)

Platform

Compiler Status
Visual Studio 2013 x64 All tests pass
Clang 3.6 All tests pass

Installation Win

  • Clone into e.g. D:\misc\enum_extend
  • Create a build folder, eg D:\misc\enum_extend_build
  • Open a command prompt in that enum_extend_build
  • Have CMake in the path
  • Execute cmake -G "Visual Studio 12 Win64" ..\enum_extend
  • Open created solution in .\enum_extend_build\enum_library.sln
  • Compile and run all test

ToDo

  • Doxygen documentation

enum_extend's People

Contributors

felixpetriconi avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.