Jump to page: 1 2
Thread overview
super duper enumerations
Aug 17, 2001
D Man
Aug 17, 2001
Walter
Aug 17, 2001
Chris Friesen
Aug 17, 2001
D Man
Aug 17, 2001
D Man
Aug 17, 2001
Chris Friesen
Aug 17, 2001
Sheldon Simms
Aug 17, 2001
Chris Friesen
Aug 17, 2001
D Man
enumerations
Sep 09, 2001
Anthony Steele
Aug 18, 2001
John Carney
Aug 21, 2001
Kevin Quick
Dec 22, 2001
Walter
Dec 22, 2001
Pavel Minayev
Dec 22, 2001
Walter
Dec 23, 2001
Pavel Minayev
Sep 09, 2001
Anthony Steele
Sep 09, 2001
Anthony Steele
August 17, 2001
I currently use many enumerated values in my code.  I find myself setting values for bit flags and other non-linear sets.  What do you think of these ideas? (Syntax is for illustration only.)

1. Power of n enumerations or multipliers.  enum(2) { a, b c}; a = 1, b = 2,
c = 4, etc.
2. Previous value plus n.  enum blah { a, b + 0xf, c, d, e + 0x3}; a = 0, b
= 0xf, c = 0x10, d = 0x11, e = 0x14.
3. Referencing the above sample... emax(blah) = 0x14 and emin(blah) = 0 so
you can find ranges without considering the names of the enumerations or
defining the ever-present MaxVal in your enumerations.
4. Continuation of enumerations.  class A{ enum mode {input, output}; };
Class B: public A{ enum(append) mode {io, null }; };.  Useful if you add
modes via inheritance (ie, io class -- which uses multiple inheritence,
btw).  Using this would allow you to add new modes without all the
dependencies on initial statement.
5. Access enumerations as arrays.  Using #4, mode[3] in the appended
enumeration yields the value for "io."  mode[3] in the un-appended version
throws an exception.  You could remove values as well.
6. As text.  So, using #4 again, as_text(mode[0]) returns a char * to the
string "input".

If these features existed in c++, I could go home early today. *sigh* _________________________________________________

Robert Sitton

Senior Software Engineer & Digital Holographer

clockwork@austin.rr.com



"Some engineers code to live, but I live to code..."



www.zebraimaging.com www.apple.com www.nintendo.com











August 17, 2001
Wow, I never thought about enums that much! -Walter

D Man wrote in message <9liemf$s2r$1@digitaldaemon.com>...
>I currently use many enumerated values in my code.  I find myself setting values for bit flags and other non-linear sets.  What do you think of these ideas? (Syntax is for illustration only.)
>
>1. Power of n enumerations or multipliers.  enum(2) { a, b c}; a = 1, b =
2,
>c = 4, etc.
>2. Previous value plus n.  enum blah { a, b + 0xf, c, d, e + 0x3}; a = 0, b
>= 0xf, c = 0x10, d = 0x11, e = 0x14.
>3. Referencing the above sample... emax(blah) = 0x14 and emin(blah) = 0 so
>you can find ranges without considering the names of the enumerations or
>defining the ever-present MaxVal in your enumerations.
>4. Continuation of enumerations.  class A{ enum mode {input, output}; };
>Class B: public A{ enum(append) mode {io, null }; };.  Useful if you add
>modes via inheritance (ie, io class -- which uses multiple inheritence,
>btw).  Using this would allow you to add new modes without all the
>dependencies on initial statement.
>5. Access enumerations as arrays.  Using #4, mode[3] in the appended
>enumeration yields the value for "io."  mode[3] in the un-appended version
>throws an exception.  You could remove values as well.
>6. As text.  So, using #4 again, as_text(mode[0]) returns a char * to the
>string "input".
>
>If these features existed in c++, I could go home early today. *sigh* _________________________________________________
>
>Robert Sitton
>
>Senior Software Engineer & Digital Holographer
>
>clockwork@austin.rr.com
>
>
>
>"Some engineers code to live, but I live to code..."
>
>
>
>www.zebraimaging.com www.apple.com www.nintendo.com
>
>
>
>
>
>
>
>
>
>
>


August 17, 2001
D Man wrote:

> 1. Power of n enumerations or multipliers.  enum(2) { a, b c}; a = 1, b = 2,
> c = 4, etc.

I like this.  Very useful for flags.

> 2. Previous value plus n.  enum blah { a, b + 0xf, c, d, e + 0x3}; a = 0, b = 0xf, c = 0x10, d = 0x11, e = 0x14.

This one is kind of wierd, but I can see how it could be useful occasionally.

> 3. Referencing the above sample... emax(blah) = 0x14 and emin(blah) = 0 so
> you can find ranges without considering the names of the enumerations or
> defining the ever-present MaxVal in your enumerations.

YES!

> 4. Continuation of enumerations.  class A{ enum mode {input, output}; }; Class B: public A{ enum(append) mode {io, null }; };.  Useful if you add modes via inheritance (ie, io class -- which uses multiple inheritence, btw).  Using this would allow you to add new modes without all the dependencies on initial statement.

Sounds good.

> 5. Access enumerations as arrays.  Using #4, mode[3] in the appended enumeration yields the value for "io."  mode[3] in the un-appended version throws an exception.  You could remove values as well.

Hmm.  Not sure I see the point of this.  What happens if somone changes the code and re-orders the enum?  This sounds a bit dangerous to me.


> 6. As text.  So, using #4 again, as_text(mode[0]) returns a char * to the
> string "input".

YES!  I don't know how many times I've written switch statements like

case BLAH:
   cout << "BLAH";

This would be great.


I have doubts about 5, but the others could all be very handy.

Chris

-- 
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: cfriesen@nortelnetworks.com
August 17, 2001
6. Need the number values in the enumerated type.  For example, count =
mode.size();

> > 5. Access enumerations as arrays.  Using #4, mode[3] in the appended enumeration yields the value for "io."  mode[3] in the un-appended
version
> > throws an exception.  You could remove values as well.
>
> Hmm.  Not sure I see the point of this.  What happens if somone changes
the code
> and re-orders the enum?  This sounds a bit dangerous to me.

Many features in c++ are potentially dangerous.  How does this virtual
method look:
void io_base::dump_modes()
{
    cout << "Available Modes:\n";
    for(int options = 0; options < mode.size(); ++options)
    {
        cout << as_text(mode[options]) << endl;
    }
}

class io_base output:
Available modes:
exists

class reader output:
Available modes:
exists
read

class writer output:
Available modes:
exists
write

class read_write output:
Available modes:
exists
read
write



August 17, 2001
mode.size() should be mode.count(), sorry.

"D Man" <clockwork@austin.rr.com> wrote in message news:9lj6oi$1evn$1@digitaldaemon.com...
> 6. Need the number values in the enumerated type.  For example, count =
> mode.size();
>



August 17, 2001
D Man wrote:

> Many features in c++ are potentially dangerous.  How does this virtual
> method look:
> void io_base::dump_modes()
> {
>     cout << "Available Modes:\n";
>     for(int options = 0; options < mode.size(); ++options)
>     {
>         cout << as_text(mode[options]) << endl;
>     }
> }

Ah, okay.  I hadn't considered that type of usage.  Yes, it could make things easier.

Chris

-- 
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: cfriesen@nortelnetworks.com
August 17, 2001
Im Artikel <9lj6oi$1evn$1@digitaldaemon.com> schrieb "D Man" <clockwork@austin.rr.com>:

> 6. Need the number values in the enumerated type.  For example, count =
> mode.size();
> 
>> > 5. Access enumerations as arrays.  Using #4, mode[3] in the appended enumeration yields the value for "io."  mode[3] in the un-appended
> version
>> > throws an exception.  You could remove values as well.
>>
>> Hmm.  Not sure I see the point of this.  What happens if somone changes
> the code
>> and re-orders the enum?  This sounds a bit dangerous to me.
> 
> Many features in c++ are potentially dangerous.

Is that supposed to be a valid reason to introduce dangerous features in other languages.

> How does this virtual method look:
> void io_base::dump_modes()
> {
>     cout << "Available Modes:\n";
>     for(int options = 0; options < mode.size(); ++options) {
>         cout << as_text(mode[options]) << endl;
>     }
> }

Another option would be something like:

class io_base
{
  void dump_modes()
  {
    printf("Available Modes:\n");
    for a_mode in mode
      printf(a_mode.as_text());
  }
}

-- 
Sheldon Simms / sheldon@semanticedge.com
August 17, 2001
Sheldon Simms wrote:

> Another option would be something like:
> 
> class io_base
> {
>   void dump_modes()
>   {
>     printf("Available Modes:\n");
>     for a_mode in mode
>       printf(a_mode.as_text());
>   }
> }

I definately like this better.  Being able to loop over enums directly would be handy.

Chris

-- 
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: cfriesen@nortelnetworks.com
August 17, 2001
I really like this!

"Chris Friesen" <cfriesen@nortelnetworks.com> wrote in message news:3B7D56F4.9D64682C@nortelnetworks.com...
> Sheldon Simms wrote:
>
> > Another option would be something like:
> >
> > class io_base
> > {
> >   void dump_modes()
> >   {
> >     printf("Available Modes:\n");
> >     for a_mode in mode
> >       printf(a_mode.as_text());
> >   }
> > }
>
> I definately like this better.  Being able to loop over enums directly
would be
> handy.
>
> Chris
>
> --
> Chris Friesen                    | MailStop: 043/33/F10
> Nortel Networks                  | work: (613) 765-0557
> 3500 Carling Avenue              | fax:  (613) 765-2986
> Nepean, ON K2H 8E9 Canada        | email: cfriesen@nortelnetworks.com


August 18, 2001
All very good thoughts IMHO :)

"D Man" <clockwork@austin.rr.com> wrote in message news:9liemf$s2r$1@digitaldaemon.com...
> I currently use many enumerated values in my code.  I find myself setting values for bit flags and other non-linear sets.  What do you think of
these
> ideas? (Syntax is for illustration only.)
>
> 1. Power of n enumerations or multipliers.  enum(2) { a, b c}; a = 1, b =
2,
> c = 4, etc.
> 2. Previous value plus n.  enum blah { a, b + 0xf, c, d, e + 0x3}; a = 0,
b
> = 0xf, c = 0x10, d = 0x11, e = 0x14.
> 3. Referencing the above sample... emax(blah) = 0x14 and emin(blah) = 0 so
> you can find ranges without considering the names of the enumerations or
> defining the ever-present MaxVal in your enumerations.
> 4. Continuation of enumerations.  class A{ enum mode {input, output}; };
> Class B: public A{ enum(append) mode {io, null }; };.  Useful if you add
> modes via inheritance (ie, io class -- which uses multiple inheritence,
> btw).  Using this would allow you to add new modes without all the
> dependencies on initial statement.
> 5. Access enumerations as arrays.  Using #4, mode[3] in the appended
> enumeration yields the value for "io."  mode[3] in the un-appended version
> throws an exception.  You could remove values as well.
> 6. As text.  So, using #4 again, as_text(mode[0]) returns a char * to the
> string "input".
>
> If these features existed in c++, I could go home early today. *sigh* _________________________________________________
>
> Robert Sitton
>
> Senior Software Engineer & Digital Holographer
>
> clockwork@austin.rr.com
>
>
>
> "Some engineers code to live, but I live to code..."
>
>
>
> www.zebraimaging.com www.apple.com www.nintendo.com
>
>
>
>
>
>
>
>
>
>
>


« First   ‹ Prev
1 2