Discussion:
BitFill 32bit integer? Need more
(too old to reply)
Stephane Baillargeon
2008-03-13 18:46:00 UTC
Permalink
I'm using a 32bit integer (BitFill) enum to store the user rights.

Example:

enum EUserRights
{
eRIGHTS_NONE = 0x00000000, // No rights at all
eRIGHTS_CREATE = 0x00000001, // Create
eRIGHTS_MODIFY = 0x00000002, // Modify
eRIGHTS_DELETE = 0x00000004, // Delete
eRIGHTS_SEARCH = 0x00000008, // Search
eRIGHTS_USER = 0x00000010, // User
eRIGHTS_ROLE = 0x00000020, // Role
...
...
...
eRIGHTS_LOGIN = 0x08000000, // Login
eRIGHTS_HAVE_ALL_RIGHTS = 0xFFFFFFFF // All rights
};

The Tag property of TMenuItems are used to enable or disable (validate if user has rights to access). My problem is this. What happens if I need more than 32 enumerators to represent the rights? Can someone give me ideas? Do I need to use 64bit or 128bit? I imagine that Big operating systems such as Fedora Core & Windows have thousands of rights... Is my approach good?

Thank You!
Remy Lebeau (TeamB)
2008-03-13 19:14:47 UTC
Permalink
Post by Stephane Baillargeon
What happens if I need more than 32 enumerators to represent
the rights?
Then you can't use a single 32-bit variable to hold the values anymore. You
will have to use an __int64 instead (or a Set, which can grow to 256
values). Obviously, you cannot store such values in the Tag property
directly. You could store it somewhere else, and then have the Tag property
contain a 32-bit pointer to it, though.
Post by Stephane Baillargeon
I imagine that Big operating systems such as Fedora Core &
Windows have thousands of rights...
Yes, but they are not all merged together in a single enum. Different types
of rights are declared in different enums that are then used together for
different purposes as needed.


Gambit
Stephane Baillargeon
2008-03-13 19:40:40 UTC
Permalink
Post by Remy Lebeau (TeamB)
You could store it somewhere else, and then have the Tag property
contain a 32-bit pointer to it, though.
Thank you for your reply. So if I understand correctly I should use multiple enums and set at runtime the Tag property. Something like this:???

enum EOne
{
eOne_A = 0X00000001,
eOne_B = 0X00000002,
...
eOne_Z = 0x04000000,
};

enum ETwo
{
eTwo_A = 0X00000001,
eTwo_B = 0X00000002,
...
eTwo_Z = 0x04000000,
};

mniMenuItem1->Tag = &eOne_A;
mniMenuItem2->Tag = &eOne_B;
mniMenuItem3->Tag = &eTwo_A;???? Does this make sense?

Thanks
Remy Lebeau (TeamB)
2008-03-13 21:55:01 UTC
Permalink
Post by Stephane Baillargeon
Something like this:???
That will not work. You cannot get a memory address to an enum value. You
need to declare an actual variable and then you can get the memory address
of the variable.

int Item1Rights = eOne_A;
int Item2Rights = eOne_B;
int Item3Rights = eTwo_A;

mniMenuItem1->Tag = &Item1Rights;
mniMenuItem2->Tag = &Item2Rights;
mniMenuItem3->Tag = &Item3Rights;


Gambit

Loading...