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 » HELPER: Value grouping to ValueArray
HELPER: Value grouping to ValueArray [message #29800] Thu, 18 November 2010 10:10 Go to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi all,

here comes a ArrayCtrl like grouper of Values to a ValueArray, returned as Value itself.
maybe its of help for someone..
since a variable arguments list is suboptimal in c++, this is definitely a better solution in general. good work who ever did this for ArrayCtrl..

syntax:
Value ToValueArray(const Value& [, const Value& ]...);


inline Value ToValueArray(const Vector<Value>& v)
{
	return ValueArray(Vector<Value>(v, 0));
}

inline Value ToValueArray(Vector<Value>& v)
{
	return ValueArray(v);
}

//$-Value ToValueArray(const Value& [, const Value& ]...);
#define  E__ToValueArray(I)      Value ToValueArray(__List##I(E__Value));
	__Expand(E__ToValueArray)
#undef   E__ToValueArray

#define E__Addv(I)    v << p##I
#define E__ToValueArrayF(I) \
Value ToValueArray(__List##I(E__Value)) { \
	Vector<Value> v; \
	__List##I(E__Addv); \
	return ValueArray(v); \
}
__Expand(E__ToValueArrayF)

CONSOLE_APP_MAIN
{
	Value v = ToValueArray(123, "Hallo", 23.0);
	RLOG(v);
}

[Updated on: Thu, 18 November 2010 10:12]

Report message to a moderator

Re: HELPER: Value grouping to ValueArray [message #29825 is a reply to message #29800] Sat, 20 November 2010 18:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Thu, 18 November 2010 04:10

hi all,

here comes a ArrayCtrl like grouper of Values to a ValueArray, returned as Value itself.



What about doing this as constructor overloads? Perhaps starting with 2 parameters to avoid copy variant. Or is it too ambiguous?

Quote:


since a variable arguments list is suboptimal in c++, this is definitely a better solution in general.



That is why Format uses the same technique...

Quote:


good work who ever did this for ArrayCtrl..



Thanks Wink

Mirek
Re: HELPER: Value grouping to ValueArray [message #29826 is a reply to message #29825] Sat, 20 November 2010 19:48 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
What about doing this as constructor overloads? Perhaps starting with 2 parameters to avoid copy variant. Or is it too ambiguous?


as far as got to know the ValueArray code, it does adding values by adding it to internal Vector<Value> anyway.
doing it like in the example above already provides the prepared Vector<Value> to pick, so no copy is done. and it saves the ValueArray interface from growing Smile and remains optional usage.

ambiguity maybe could be a side effect some day in other occassions.. i consider ValueArray(_pick Vector<Value>&) flexible enough if you ask me..

it'd also be possible to leave it like it is now and simply do
Value v = ValueArray(Vector<Value>() << 123 << "Hallo" << 34.9);

its not so nice, but neither generates extra code in Upp base to manage Smile

it was just an idea, to increase readability
Re: HELPER: Value grouping to ValueArray [message #29996 is a reply to message #29826] Thu, 02 December 2010 13:44 Go to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i came to the conclusion that easy is best again Smile

#define ASVALUEARRAY(x) ValueArray(Vector<Value>() << x)

Value v = ASVALUEARRAY(123 << "Hallo" << 34.9);

is actually same approach as in concatenating to cout, or in LOG()
so is almost natural Smile
maybe this can go to Value.h..
Previous Topic: PROPOSAL: linear Scaler helper for different min/max domains
Next Topic: Date limited to 2020 and 2015 does not work ?!?
Goto Forum:
  


Current Time: Mon Apr 29 17:37:58 CEST 2024

Total time taken to generate the page: 0.01841 seconds