Best way to map/join two autogenerated enums
- by tomlip
What is the best C++ (not C++11) way of joining two enums from autogenerated class similar to one presented below:
namespace A {
  namespace B { ...
    class CarInfo {
      enum State {   // basically same enums defined in different classes
        Running,
        Stopped,
        Broken
      }
    }
    class BikeInfo {
      enum State {   // basically same enums defined in different classes
        Running,
        Stopped,
        Broken
      }
    }
  }
}
What is needed is unified enum State for both classes that is seen to outside world alongside with safe type conversion.
The best and probably most straightforward way I came up with is to create external enum:
enum State {
  Running,
  Stopped,
  Broken
}
together with conversion functions
State stateEnumConv(A::B::CarInfo::State aState);
State stateEnumConv(A::B::BikeInfo::State aState);
A::B::CarInfo::State stateEnumConv(State aState);
A::B::BikeInfo::State stateEnumConv(State aState);
Direction into right approach is needed.
Gosh coming from C I hate those long namespaces everywhere an I wish it could be only A::B level like in presented example. Four conversion functions seem redundant note that CarInfo::State and BikeInfo::State has same enum "members".