Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » user 'Value' [FEATURE REQUEST]
user 'Value' [FEATURE REQUEST] [message #3437] Thu, 25 May 2006 11:04 Go to next message
qwerty is currently offline  qwerty
Messages: 130
Registered: May 2006
Experienced Member
one user Value on Arrays etc. It come would handy.

like:

Array<int> ints;

Value ints.userValue;

something like Tag. it could be on other classes, but my knowledge of upp are not so far....
Re: user 'Value' [FEATURE REQUEST] [message #3440 is a reply to message #3437] Thu, 25 May 2006 15:17 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Usually this is solved by defining your own class/struct, something like

struct ArrayWithVal {
Array<int> ints;
Value userValue;
};

In C++ probably construction like

class ArrayWithVal : public Array<int> {
Value userValue;
};
(err.. you should probably write that as template)

would maybe give you advantage in some situations (ability to store both Array<> and ArrayWithVal into the Array<> * pointer, or to give some function ArrayWithVal instead of Array<>, etc..)

Depends on what you need and how much sure you are about what you are doing, when you are designing new class.
Re: user 'Value' [FEATURE REQUEST] [message #3441 is a reply to message #3440] Thu, 25 May 2006 16:13 Go to previous messageGo to next message
qwerty is currently offline  qwerty
Messages: 130
Registered: May 2006
Experienced Member
err, yes, I tried to put a void onto this Cool , a leave that for upp fathers or at least some upp guru, cause they know, if it is possible and easier to implement into upp or to make user his own like you wrote...

when it's about upp, one never know Razz
Re: user 'Value' [FEATURE REQUEST] [message #3455 is a reply to message #3437] Thu, 25 May 2006 21:26 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
I think the solution with inheritance is the most easy and usefull one.

template <class T>
class ArrayWithVal : public Array<T>, Moveable< ArrayWithVal<T> > {
public:
	Value		userValue;
};


(Maybe "MoveableAndDeepCopyOption< ... >" can be used, but Value is just "Moveable", and so I'm not sure if the DeepCopy would be still possible)

I don't think such short piece of code is worth of addition to UPP core. Actually this is the most simple example of what is OOP capable of, and why it has advantages over procedural programming for certain tasks (like this one).

Anyway, I think the "Value" is a good choice in UPP as long as you don't care about it's size in memory (i.e. you will not produce hundrets instances of that class together).

Other common solution is to use void *, or DWORD type.
Both of them allow you to store 32bit ints into user value. The void * is also more understandable if you put there pointer pointing to your custom structure holding more values.
Buth those two are usual for plain C code, and as I said, Value is very good choice in UPP, unless you are memory consumption concerned.
Re: user 'Value' [FEATURE REQUEST] [message #3456 is a reply to message #3455] Thu, 25 May 2006 21:28 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Of course the userValue can be private/protected, then add some public methods to work with the value, if you want to hide that data from direct access.
I think the default constructor should be enough for everyone (in this special case, not in general). Wink
Re: user 'Value' [FEATURE REQUEST] [message #3465 is a reply to message #3456] Thu, 25 May 2006 23:24 Go to previous message
qwerty is currently offline  qwerty
Messages: 130
Registered: May 2006
Experienced Member
more than enought so far, Upp deity bless you Twisted Evil !
Previous Topic: short-hand
Next Topic: container.At(not_existed_item_index)
Goto Forum:
  


Current Time: Sat Apr 27 15:28:09 CEST 2024

Total time taken to generate the page: 1.00764 seconds