PDA

View Full Version : Question about a handler of various types of parameters



Dark_Tower
16th March 2006, 23:12
Hi everybody, I'm programming an application that does some processation for a specified input. The results of this processation are various parameters that I have to save at disk. These parameters are basicly integers and doubles. Well, I have implemented a handler class to save / load these parameters from disk. In some cases, I have to left some parameters as "unspecified". I would like to know what's the best / elegant way to implement it: consider it unspecified when the user sets the value for the parameter with a special value (negative values, for example), with an auxiliar method to set the value unspecified and save it at disk with a special value that manages the handler, ... Could anybody suggest me something?

Thanks a lot.

wysota
17th March 2006, 14:35
Could you provide an example? Your explanation is a little unclear.

Dark_Tower
17th March 2006, 17:27
Could you provide an example? Your explanation is a little unclear.

Yes, sorry. I mean that not always all the parameters with the result of the processation represent strictly a "value". In some cases, if the processation has been wrong or in some special cases , I need to set some parameters with a special value that represent that the parameter is "unknow", "unspecified", "invalid" or calculated "manually" by the user, for example. In these cases as you see these parameters dont' have a value, simply inform of something. I would like to know how it's the best way to manage these parameters that in some cases have value (int or double) but in other cases dont't. I've thought with special values that the user will set to the parameter using the handler: positive values -> valid values, negative values -> -1 = "Manually Processed", -2 = "Unknow", etc. But I don't know if it's the best way or could be another way to make it more 'elegant'?

wysota
17th March 2006, 17:49
Maybe a structure with validity flag? Something like QVariant and its isValid() member.

Dark_Tower
17th March 2006, 17:59
Maybe a structure with validity flag? Something like QVariant and its isValid() member.

Yes wystoa QVariant could work, but how could I determine the cases that the parameter is valid but it doesn't represent a value from the cases that the parameter represents strictly a value. For example, in some cases I want to indicate that the parameter is "unknow" because becomes from a manually processing. In this case I want only to indicate this fact without any value.

jacek
17th March 2006, 18:14
class SomeClass
{
public:
enum Status { Unknown, Invalid, Valid, ... };
// ...
private:
Status _status;
int _value;
}