Hi,
I would like to know what is the best way of doing the following thing.
I am developping a GUI application with a tree and for each item of my
tree I can associate(gui mechanism) a class to store extra information.
So i have this :
ifndef PRJTREE_H
#define PRJTREE_H
#include <wx/treectrl.h>
enum EItemType
{
eRoot = 0,
eReaderGroup,
eReaderItem,
eCardGroup,
eCardItem,
eCardCmdGroup,
eCardCmdItem
};
/*
wxTreeItemData is some (arbitrary) user class associated with some item.
The main advantage of having this class is that wxTreeItemData objects
are destroyed automatically by the tree and, as this class has virtual
destructor
*/
class PrjItemData : public wxTreeItemData
{
public:
PrjItemData(EItemType enuItemType = eRoot) {m_enuItemType =
enuItemType;}
private:
EItemType m_enuItemType;
};
class PrjTree : public wxTreeCtrl
{
public:
PrjTree() { }
PrjTree(wxWindow * parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style);
virtual ~PrjTree(){};
void AddItem(EItemType eType, const wxString& strItemName);
DECLARE_DYNAMIC_CLASS(PrjTree)
DECLARE_EVENT_TABLE()
};
And in my AddItem when I add an item to my tree I associate a
PrjItemData with it.
void PrjTree::AddItem(EItemType eParentType, const wxString& strItemName)
{
wxTreeItemId idItem = GetItemCorrespondingTo( eParentType);
AppendItem(idItem, strItemName, -1, -1, new PrjItemData
(eParentType) );
}
#endif
Now my question is should I let enum as global or would it be better to
put it inside one of the two classes?
Should I use namespace ?
I tried to put enum in PrjTree but in this case when I define
PrjItemData I suppose I should write (not even sure if it works) this
class PrjItemData : public wxTreeItemData
{
public:
PrjItemData(PrjTree::EItemType enuItemType = eRoot) {m_enuItemType
= enuItemType;}
private:
EItemType m_enuItemType;
}; 1 3313
Vincent RICHOMME wrote: Hi,
I would like to know what is the best way of doing the following thing. I am developping a GUI application with a tree and for each item of my tree I can associate(gui mechanism) a class to store extra information. So i have this :
ifndef PRJTREE_H #define PRJTREE_H
#include <wx/treectrl.h>
enum EItemType { eRoot = 0, eReaderGroup, eReaderItem, eCardGroup, eCardItem, eCardCmdGroup, eCardCmdItem };
/* wxTreeItemData is some (arbitrary) user class associated with some item. The main advantage of having this class is that wxTreeItemData objects are destroyed automatically by the tree and, as this class has virtual destructor */ class PrjItemData : public wxTreeItemData { public: PrjItemData(EItemType enuItemType = eRoot) {m_enuItemType = enuItemType;}
private: EItemType m_enuItemType;
}; class PrjTree : public wxTreeCtrl { public:
PrjTree() { } PrjTree(wxWindow * parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style); virtual ~PrjTree(){};
void AddItem(EItemType eType, const wxString& strItemName);
DECLARE_DYNAMIC_CLASS(PrjTree) DECLARE_EVENT_TABLE() };
And in my AddItem when I add an item to my tree I associate a PrjItemData with it.
void PrjTree::AddItem(EItemType eParentType, const wxString& strItemName) { wxTreeItemId idItem = GetItemCorrespondingTo( eParentType);
AppendItem(idItem, strItemName, -1, -1, new PrjItemData (eParentType) ); } #endif Now my question is should I let enum as global or would it be better to put it inside one of the two classes? Should I use namespace ?
The main problem with a global enum is that symbols may clash with
other names. Namespaces could do the job, but then you end up with more
complicated names
namespace EItemType
{
enum Type { eRoot=0 };
}
EItemType::Type t = EItemType::eRoot;
However, if you use 1) more descriptive enum symbols (tree_type_root)
and 2) put the whole thing in a namespace (prjtree for example), a
"global" (now namespace) -scope enum may be alright. That's not what I
recommend though.
I tried to put enum in PrjTree but in this case when I define PrjItemData I suppose I should write (not even sure if it works) this
class PrjItemData : public wxTreeItemData { public: PrjItemData(PrjTree::EItemType enuItemType = eRoot) {m_enuItemType = enuItemType;}
If EItemType is on PrjTree, you must qualify the enum symbols:
PrjTree::EItemType e = PrjTree:eRoot;
I would prefer this. You keep type safety and scope.
private: EItemType m_enuItemType; };
I once implemented a scoped_enum as a macro which wrapped an enum into
a class, defining some operators and conversions. You may search for it
on google groups, but you'll have to adapt it because it used a non
standard trick (declaration of enums).
Jonathan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: john doe |
last post by:
A quick question, about so-called 'best practices', I'm interested in
which of A/B of the two examples people would choose, and why.
public enum MyEnum
{
Option1 = 0,
Option2 = 1,
Option3 =...
|
by: Schoo |
last post by:
I have some program constants that I need to set and I thought it would be
best to set them all up in a central location so that I can change them
quickly when we go from development to production....
|
by: Shayne H |
last post by:
What is the best way to enumerate a grouping of strings?
The way I have been doing it is:
Public Enum PlatformID
Unknown
Win16
Win32
Win32NT
WinCE
End Enum
|
by: Alex Feldman |
last post by:
Which of the following is better? Defining an enum type inside a class
as a nested type, or in the the namespace?
An example of nested type enumerated type would be:
public Class Product...
|
by: Kris |
last post by:
I read a column on sharing types between web services at
http://msdn.microsoft.com/library/en-us/dnservice/html/service07162002.asp
Sharing types can be acheived, similar to what described here...
|
by: jlamb77 |
last post by:
Hi,
I am in the process of creating a schema definition to validate some
XML data that will look like the following:
ProductA
SubProductA
SubProductB
SubProductC
|
by: joshfink |
last post by:
Hey guys,
I am writing an application where I want to follow the best practices on error handling.
This is what I have:
I created an enum for various issues that could happen within the...
|
by: Andy Champ |
last post by:
What I want to do (and can't...) is
Template <typename Tclass base
{
// whatever
}
class derived: public base<derived::myVals>
{
Enum myVals
|
by: =?GB2312?B?17/HvyBaaHVvLCBRaWFuZw==?= |
last post by:
Hi,
I would like to have someone comments on what's the best practice
defining error codes in C.
Here's what I think:
solution A:
using enum
pros: type safe. better for debug (some debugger...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |