public T getUnit <T>() { Type paramType = typeof(T); if (paramType == typeof(Parameters.Units[])) { // request to return as Parameters.Units[] // create a copy (since an array is passed by reference) Parameters.Units[] cUnits = new Parameters.Units[units.Length]; for (int i = 0; i < units.Length; i++) { cUnits[i] = units[i]; } // return value return((T)Convert.ChangeType(cUnits, typeof(Parameters.Units[]))); } else { // request to return as other // message and return false logger.Error("Could not retrieve the unit for parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "') as '" + paramType.Name + "', can only return value as 'Parameters.Units[]'. Returning 0"); return((T)Convert.ChangeType(Parameters.emptyValue <T>(), typeof(T))); } }
public T getUnit <T>() { Type paramType = typeof(T); if (paramType == typeof(Parameters.Units[])) { // request to return as Parameters.Units[] // return value Parameters.Units[] units = new Parameters.Units[values.Length]; for (int i = 0; i < values.Length; i++) { units[i] = Parameters.Units.ValueOrSamples; } return((T)Convert.ChangeType(units, typeof(Parameters.Units[]))); } else { // request to return as other // message and return false logger.Error("Could not retrieve the unit for parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "') as '" + paramType.Name + "', can only return value as 'Parameters.Units[]'. Returning 0"); return((T)Convert.ChangeType(Parameters.emptyValue <T>(), typeof(T))); } }
public bool setValue(string value) { // try to parse the value double doubleValue; Parameters.Units unit; if (!tryParseValue(value, out doubleValue, out unit)) { // message logger.Error("Could not store the value for parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "'), value '" + value + "' could not be parsed as double"); // return failure return(false); } // check if the parameter has options and the unit is set in seconds if (this.options.Length > 0 && unit == Parameters.Units.Seconds) { // message logger.Warn("Parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "') has a list of options, yet the value is specified in seconds, this is unlikely to be correct"); } // assign this.value = doubleValue; this.unit = unit; // return success return(true); }
public bool setValue(int[][] values) { // check if options (fixed columns) are set and if the set matches the dimensions if (this.options.Length > 0 && this.options.Length != values.Length) { // message logger.Error("Could not store the values for parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "'), the number of columns in the value matrix does not match the options (fixed number of colums) set for the parameter"); // return failure return(false); } // re-initialize the buffer holding the units for the values units = new Parameters.Units[values.Length][]; for (int i = 0; i < values.Length; i++) { units[i] = new Parameters.Units[values[i].Length]; } // set the values this.values = values; // return success return(true); }
protected bool tryParseValue(string value, out double doubleValue, out Parameters.Units unit) { doubleValue = 0.0; unit = Parameters.Units.ValueOrSamples; // lower case and trim all whitespace value = value.ToLower().TrimAll(); // check if value is in seconds if (value.Length > 1 && value.Substring(value.Length - 1).Equals("s")) { unit = Parameters.Units.Seconds; value = value.Substring(0, value.Length - 1); } // return false if the value is empty if (String.IsNullOrEmpty(value)) { return(false); } // check if value is numeric and can be converted to a double // return false if unsucessful if (!double.TryParse(value, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, Parameters.NumberCulture, out doubleValue)) { return(false); } // successfull parsing, return true return(true); }
public bool setValue(string paramName, double paramValue, Parameters.Units paramUnit) { lock (lockParameters) { iParam param = getParameter(paramName); if (param == null) { logger.Error("Could not find parameter '" + paramName + "' in parameter set '" + paramSetName + "', value not set"); return(false); } // check if the parameter is indeed used to store a double if (param.GetType() != typeof(ParamDouble)) { logger.Error("Could not set parameter '" + paramName + "' in parameter set '" + paramSetName + "', trying to set a double value in a '" + param.GetType().Name + "' parameter"); return(false); } // set the value if (!((ParamDouble)param).setValue(paramValue)) { return(false); } if (!((ParamDouble)param).setUnit(paramUnit)) { return(false); } // return success return(true); } }
public bool setValue(string paramName, double[][] paramValue) { Parameters.Units[][] paramUnit = new Parameters.Units[paramValue.Length][]; for (int i = 0; i < paramUnit.Length; i++) { paramUnit[i] = new Parameters.Units[paramValue[i].Length]; } return(setValue(paramName, paramValue, paramUnit)); }
public bool setUnit(Parameters.Units unit) { // check if the parameter has options and the unit is set in seconds if (this.options.Length > 0 && unit == Parameters.Units.Seconds) { // message logger.Warn("Parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "') has a list of options, yet the value set to be in seconds, this is unlikely to be correct"); } // set units this.unit = unit; // return success return(true); }
public bool setValue(string value) { // try to split up the string string[] split = value.Split(Parameters.ArrDelimiters, StringSplitOptions.RemoveEmptyEntries); // parse the values as integers int[] values = new int[split.Length]; Parameters.Units[] units = new Parameters.Units[split.Length]; for (int i = 0; i < split.Length; i++) { // try to parse the value int intValue; Parameters.Units unit; if (!tryParseValue(split[i], out intValue, out unit)) { // message logger.Error("Could not store the values for parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "'), the value(s) '" + value + "' could not be parsed as an array of integers due to value '" + split[i] + "'"); // return failure return(false); } // check if the parameter has options and the unit is set in seconds if (this.options.Length > 0 && unit == Parameters.Units.Seconds) { // message logger.Warn("Parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "') has a list of options, yet one of the values is specified in seconds, this is unlikely to be correct"); } // add to the array of integers values[i] = intValue; units[i] = unit; } // store the values this.values = values; this.units = units; // return success return(true); }
public bool setValue(string value) { // check if the input is empty if (String.IsNullOrEmpty(value)) { // store empty matrices this.values = new int[0][]; this.units = new Parameters.Units[0][]; // return success return(true); } // try to split up the columns of the string string[] splitColumns = value.Split(Parameters.MatColumnDelimiters); // check if options (fixed columns) are set and if the set matches the dimensions if (this.options.Length > 0 && this.options.Length != splitColumns.Length) { // message logger.Error("Could not store the values for parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "'), the number of columns in the value matrix does not match the options (fixed number of colums) set for the parameter"); // return failure return(false); } // resize the array columns int[][] values = new int[splitColumns.Length][]; Parameters.Units[][] units = new Parameters.Units[splitColumns.Length][]; // parse the values as doubles for (int i = 0; i < splitColumns.Length; i++) { // try to split up the rows of each column string string[] splitRows = splitColumns[i].Split(Parameters.MatRowDelimiters); // check whether the current row has the same number of values (as the row before it) if (i > 0 && splitRows.Length != values[i - 1].Length) { // message logger.Error("Could not store the values for parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "'), the rows have different numbers of values"); // return failure return(false); } // resize the arrays rows values[i] = new int[splitRows.Length]; units[i] = new Parameters.Units[splitRows.Length]; // loop through each row in the column (cell) for (int j = 0; j < splitRows.Length; j++) { // try to parse the value int intValue; Parameters.Units unit; if (!tryParseValue(splitRows[j], out intValue, out unit)) { // message logger.Error("Could not store the values for parameter '" + this.Name + "' (parameter set: '" + this.getParentSetName() + "'), the value(s) '" + splitRows[j] + "' could not be parsed as an array of integers due to value '" + splitRows[j] + "'"); // return failure return(false); } // add to the array of doubles values[i][j] = intValue; units[i][j] = unit; } } // store the values this.values = values; this.units = units; // return success return(true); }