Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Enums hierarchy and organization in C++

Reply
Thread Tools

Enums hierarchy and organization in C++

 
 
Guest Guest is offline
Junior Member
Join Date: Feb 2010
Posts: 27
 
      05-30-2008
Hi!
I am trying to get several parameters in functions as enum variables.
Consider this:

namespace Layout
{
enum type
{
DOT, NEATO, FDP, TWOPI, CIRCO
};
}

A function signature would look like this:

void render(Layout::type L);

And a typical invocation could be:

G.render(Layout::NEATO).;

This looks really OOP and elegant. However, I am unsure whethere this
design pattern is the "de facto" standard one in modern C++. I wonder
how does one organize the enums to separate different enum items in a
nice way?
 
Reply With Quote
 
 
 
 
Andrew Kerr
Guest
Posts: n/a
 
      05-30-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> void render(Layout::type L);
>
> And a typical invocation could be:
>
> G.render(Layout::NEATO).;
>
> This looks really OOP and elegant. However, I am unsure whethere this
> design pattern is the "de facto" standard one in modern C++.



> I wonder
> how does one organize the enums to separate different enum items in a
> nice way?


You've certainly nailed it. If C supported the concept of namespaces,
the declaration of an enum would place elements of the enumeration in
its namespace. Since it doesn't, doing it explicitly on your own is
perfectly legitimate and shouldn't surprise anyone.

With regard to whether it is a "de facto standard," I would go with no
it is not yet standard C++ style, but you should use namespaces anyway
and perhaps help that come about. It's quite a sensible style preference.

Other OOP languages that were designed without C compatibility in mind
(e.g. Java, C#) bring the enumerations into their own namespace as you
have done.

// C#
//
enum Layout {
DOT, NEATO, FDP, TWOPI, CIRCO
};

void Render(Layout type);

Render(Layout.NEATO);

--
Andrew Kerr
 
Reply With Quote
 
 
 
 
Pascal J. Bourguignon
Guest
Posts: n/a
 
      06-02-2008
(E-Mail Removed) writes:

> Hi!
> I am trying to get several parameters in functions as enum variables.
> Consider this:
>
> namespace Layout
> {
> enum type
> {
> DOT, NEATO, FDP, TWOPI, CIRCO
> };
> }
>
> A function signature would look like this:
>
> void render(Layout::type L);
>
> And a typical invocation could be:
>
> G.render(Layout::NEATO).;
>
> This looks really OOP and elegant. However, I am unsure whethere this
> design pattern is the "de facto" standard one in modern C++. I wonder
> how does one organize the enums to separate different enum items in a
> nice way?


If I had my say, I would write:

namespace Layout{
namespace type{
enum type{
DOT, NEATO, FDP, TWOPI, CIRCO };}}

so we can add:

namespace Layout{
namespace type{
enum type{
DOT, NEATO, FDP, TWOPI, CIRCO };}
namespace form{
enum type{
DOT, CIRCLE, TRIANGLE, SQUARE, PENTAGON, POLYGON };}}

and no problem with Layout::type:OT vs. Layout::form:OT.



--
__Pascal Bourguignon__
 
Reply With Quote
 
Stefan Naewe
Guest
Posts: n/a
 
      06-02-2008
On 5/30/2008 10:54 PM, (E-Mail Removed) wrote:
> Hi!
> I am trying to get several parameters in functions as enum variables.
> Consider this:
>
> namespace Layout
> {
> enum type
> {
> DOT, NEATO, FDP, TWOPI, CIRCO
> };
> }
>
> A function signature would look like this:
>
> void render(Layout::type L);
>
> And a typical invocation could be:
>
> G.render(Layout::NEATO).;
>
> This looks really OOP and elegant. However, I am unsure whethere this
> design pattern is the "de facto" standard one in modern C++. I wonder
> how does one organize the enums to separate different enum items in a
> nice way?


Wouldn't make a real OOP approach make more sense?
What about creating classes for DOT, NEATO, etc. ?

(Hhmm, where did I read "never switch on type codes"...Can't remember)


S.
--
Stefan Naewe stefan dot naewe at atlas-elektronik dot com
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
REVIEW: "Computer Viruses and Other Malicious Software", Organization for Economic Co-operation and Development Rob Slade, doting grandpa of Ryan and Trevor Computer Security 0 01-12-2011 03:46 AM
Configuration hierarchy organization Kenneth Porter XML 6 01-02-2008 01:20 PM
Configuration hierarchy organization Kenneth Porter C++ 6 01-02-2008 01:20 PM
Enums without identifier, enums and typedef =?utf-8?b?QXNiasO4cm4gU8OmYsO4?= C Programming 10 01-20-2007 01:20 AM
Ruby-Watir test case organization (dir hierarchy) kalensr Ruby 0 03-10-2006 04:10 PM



Advertisments