Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-7240

namespace of class enum from dictionaries

    XMLWordPrintable

Details

    Description

      As you know one of the difference between enum and class enum is that class enum}}s have their own scope, while {{enum are injected in the scope containing the definition.

      It means that if I define in the header

      mylib.h

      namespace ns
      {
        enum Color { Red, Green };
        enum class Flavor : char { Up, Down };  // underlying type is char
        enum class Orientation : long int { Down, Up };
      };
      void test();

      the I have to use them as

      mylib.cpp

      #include "mylib.h"
       
      void test()
      {
        ns::Color color = ns::Red;
        ns::Flavor flavor = ns::Flavor::Up;
        // this does not work:
        // ns::Flavor flavor = ns::Up;
       
        if (color == 0) { }
        // this does not work:
        // if (flavor == 0) { }
      }

      I suppose that the same scoping rule should be valid for the python code automatically generated (and if not you have collision problem in addition)

      import ROOT; ROOT.gROOT.ProcessLine(".L mylib.cxx")

      (Minor) Issue 1

      In [6]: ROOT.ns.Flavor
      Out[6]: int

      it should be ROOT.char or something similar

      Issue 2

      In [8]: ROOT.ns.Flavor.Up
      ---------------------------------------------------------------------------
      AttributeError                            Traceback (most recent call last)
      <ipython-input-8-d7bfea300838> in <module>()
      ----> 1 ROOT.ns.Flavor.Up
       
      AttributeError: type object 'int' has no attribute 'Up'

      Issue 3

      In [10]: ROOT.ns.Up
      Out[10]: 1

      This should not work. In addition it is also ambiguous (ns::Flavor::Up or ns::Orientation::Up)

      (Minor) issue 4

      In [11]: ROOT.ns.Up == 1   # should be ROOT.ns.Flavor.Up
      Out[11]: True

      this should not work (as the equivalent c++ code)

      Attachments

        Activity

          People

            etejedor Enric Tejedor Saavedra
            turra Ruggero Turra
            Votes:
            5 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: