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(EIt emType enuItemType = eRoot) {m_enuItemType =
enuItemType;}
private:
EItemType m_enuItemType;
};
class PrjTree : public wxTreeCtrl
{
public:
PrjTree() { }
PrjTree(wxWindo w * parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style);
virtual ~PrjTree(){};
void AddItem(EItemTy pe eType, const wxString& strItemName);
DECLARE_DYNAMIC _CLASS(PrjTree)
DECLARE_EVENT_T ABLE()
};
And in my AddItem when I add an item to my tree I associate a
PrjItemData with it.
void PrjTree::AddIte m(EItemType eParentType, const wxString& strItemName)
{
wxTreeItemId idItem = GetItemCorrespo ndingTo( eParentType);
AppendItem(idIt em, 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(Prj Tree::EItemType enuItemType = eRoot) {m_enuItemType
= enuItemType;}
private:
EItemType m_enuItemType;
}; 1 3340
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(EIt emType enuItemType = eRoot) {m_enuItemType = enuItemType;}
private: EItemType m_enuItemType;
}; class PrjTree : public wxTreeCtrl { public:
PrjTree() { } PrjTree(wxWindo w * parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style); virtual ~PrjTree(){};
void AddItem(EItemTy pe eType, const wxString& strItemName);
DECLARE_DYNAMIC _CLASS(PrjTree) DECLARE_EVENT_T ABLE() };
And in my AddItem when I add an item to my tree I associate a PrjItemData with it.
void PrjTree::AddIte m(EItemType eParentType, const wxString& strItemName) { wxTreeItemId idItem = GetItemCorrespo ndingTo( eParentType);
AppendItem(idIt em, 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::eRoo t;
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(Prj Tree::EItemType enuItemType = eRoot) {m_enuItemType = enuItemType;}
If EItemType is on PrjTree, you must qualify the enum symbols:
PrjTree::EItemT ype 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 = 2,
Option4 = 3
|
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. What is the best way to
do that? Should I put them in web.config? Should I create a special class
for these settings? Wherever it is best to write them, can you give me a
line or 2 of code to show the best way to set a constant string?
...
|
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
Public Enum Status
psNormal
psCharged
End Enum
|
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 in this
article but little defferently, by defining these custom types in a seperate
assembly and importing that assembly at the top of the proxy generated and
then manullay deleting the redefined custom types in each proxy class.
But still this...
| |
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 DAL... INSERTFAILED, INSERTSUCCESSFUL etc... I am setting this enum to a property of the dal for the object to access after the dal is done with whatever method I call... get, getAll, update, insert, delete, etc...
The object can then access...
|
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 will show the name
not only the value)
cons: enum can not be forward declared which makes all error codes
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |