Home » U++ Library support » U++ Core » Value: BOOLEAN_V, USERVALUE_V [REQUEST]
Re: Value: BOOLEAN_V, USERVALUE_V [REQUEST] [message #7126 is a reply to message #7119] |
Fri, 15 December 2006 09:41   |
fallingdutch
Messages: 258 Registered: July 2006
|
Experienced Member |
|
|
luzr wrote on Thu, 14 December 2006 20:28 | I am not quite sure BOOL_V is a good idea, but be it...
|
Why isn't it a good idea in your oppinon?
it is needed in database, too
luzr wrote on Thu, 14 December 2006 20:28 |
But IMHO be aware that such solution is extremely fragile because of conversions between numerical values (note that IsNumber is the recommended method of type inquiry there).
|
What about just adding a new ID BOOL_V and a function IsBool that returns true if the Value was constructed with a bool as param.
all other conversions will stay the same, so bool is returned as integer, means IsNumber tests on BOOL_V, too and BOOL_V is casted to int every time. so the whole is not broken, but one can distinguish, wether the value was created with a boolean or with any other number.
That would result in:
//Value.h
const int BOOLEAN_V = [booleanid];
inline dword ValueTypeNo(const bool) {return BOOLEAN_V;}
inline bool IsNumber(const Value& v) { return v.GetType() == DOUBLE_V || v.GetType() == INT_V || \
v.GetType() == BOOL_V || v.GetType() == INT64_V; }
//Value.cpp
Value::Value(bool b) { ptr = new RichValueRep<bool>(b);}
Value::operator int() const //same for int64, double
{
if(IsNull()) return Null;
return GetType() == INT_V ? RichValue<int>::Extract(*this)
: GetType() == INT64_V ? int(RichValue<int64>::Extract(*this))
: GetType() == BOOL_V ? int(RichValue<bool>::Extract(*this))
: int(RichValue<double>::Extract(*this));
}
luzr wrote on Thu, 14 December 2006 20:28 |
Maybe the right solution is to provide special type, RpcBool, or something like that.
|
That would mean i have to create a RpcValue:Value with just the changes mentioned above.
luzr wrote on Thu, 14 December 2006 20:28 |
USERVALUE_V does not have sense. I must admit that the idea of numeric ids is somewhat fragile as well, but USERVALUE_V would not solve that. At least Value system checks for duplicate definitions.
|
Why not? so anyone using u++ and wants to define his own id knows where to start: USERVALUE_V+k (k in {0,1,2, ...} is known to be unused.
Bas
|
|
|
Goto Forum:
Current Time: Wed Sep 03 20:07:30 CEST 2025
Total time taken to generate the page: 0.00774 seconds
|