/* Determine if the value of a string is a known numerical value */ bool IsNumericValue (const string& o_formula) { bool result = true; string formula = StripParens (o_formula); list<string> operands = SeparateOperands (formula); // one operand only if (operands.size() == 1) { ///////////////////////////// Literal if (IsNumber (operands.front() )) { return true; } /* if */ ///////////////////////////// Value Identifier ///////////////////////////// Function Call if (IsFunctionCall (operands.front ())) { return false; bool bresult = IsNumericValue (SeparateArguments (GetArguments (operands.front())) ) ; return bresult; } /* if */ return false; } /* if */ // multiple operands else { for (list<string>::iterator o = operands.begin(); o != operands.end(); ) { if (!IsNumericValue (*o)) { return false; } /* if */ o++; if (o != operands.end()) o++; } /* for */ return true; } /* else */ } /* IsNumericValue */
bool IsNumericValue (const list<string>& arguments) { /* TEMPORARY */ if (arguments.size() > 1) return false; for (list<string>::const_iterator o = arguments.begin(); o != arguments.end(); o++) { if (!IsNumericValue (*o)) return false; } /* for */ return true; } /* IsNumericValue */
bool wxRegKey::QueryValue(const wxString& szValue, long *plValue) const { if ( CONST_CAST Open(Read) ) { DWORD dwType, dwSize = sizeof(DWORD); RegString pBuf = (RegString)plValue; m_dwLastError = RegQueryValueEx((HKEY) m_hKey, RegValueStr(szValue), RESERVED, &dwType, pBuf, &dwSize); if ( m_dwLastError != ERROR_SUCCESS ) { wxLogSysError(m_dwLastError, _("Can't read value of key '%s'"), GetName().c_str()); return false; } else { // check that we read the value of right type wxASSERT_MSG( IsNumericValue(szValue), wxT("Type mismatch in wxRegKey::QueryValue().") ); return true; } } else return false; }
bool wxRegKey::QueryValue(const wxString& szValue, wxString& strValue, bool WXUNUSED_IN_WINCE(raw)) const { if ( CONST_CAST Open(Read) ) { // first get the type and size of the data DWORD dwType=REG_NONE, dwSize=0; m_dwLastError = RegQueryValueEx((HKEY) m_hKey, RegValueStr(szValue), RESERVED, &dwType, NULL, &dwSize); if ( m_dwLastError == ERROR_SUCCESS ) { if ( !dwSize ) { // must treat this case specially as GetWriteBuf() doesn't like // being called with 0 size strValue.Empty(); } else { m_dwLastError = RegQueryValueEx((HKEY) m_hKey, RegValueStr(szValue), RESERVED, &dwType, (RegString)(wxChar*)wxStringBuffer(strValue, dwSize), &dwSize); // expand the var expansions in the string unless disabled #ifndef __WXWINCE__ if ( (dwType == REG_EXPAND_SZ) && !raw ) { DWORD dwExpSize = ::ExpandEnvironmentStrings(strValue.t_str(), NULL, 0); bool ok = dwExpSize != 0; if ( ok ) { wxString strExpValue; ok = ::ExpandEnvironmentStrings(strValue.t_str(), wxStringBuffer(strExpValue, dwExpSize), dwExpSize ) != 0; strValue = strExpValue; } if ( !ok ) { wxLogLastError(wxT("ExpandEnvironmentStrings")); } } #endif // __WXWINCE__ } if ( m_dwLastError == ERROR_SUCCESS ) { // check that it was the right type wxASSERT_MSG( !IsNumericValue(szValue), wxT("Type mismatch in wxRegKey::QueryValue().") ); return true; } } } wxLogSysError(m_dwLastError, _("Can't read value of '%s'"), GetFullName(this, szValue)); return false; }
string Eval (const string& o_operation) { string operation = OperatorsToFunctionCalls (o_operation); //really redundant operation = StripWhitespaceBE (operation); operation = StripParens (operation); //auto operands = SeparateOperands (operation); operand count has to be one at this point list <string> operands = SeparateOperands (operation); if (operands.size() == 1) { // literal value if (IsNumericValue (operation)) return tostr (NumEval (operation)); //maybe return operation directly function_t fcode; string function_name = GetFunctionName(operation); //function if (IsFunctionCall (operation)) { SeparateArguments (StripB (function_name, operation)); return run_function (function_name, SeparateArguments (StripB (function_name, operation))); } // if // only one operand at this point, which is a variable if (IsVariable (operation)) return GetVariable (operands.front())-> Value (); // check for Literals // TODO: OperationType does so many unncessasry checks (for variables, waveforms, etc) // its better to figure out some way to skip those checks type_t optype = OperationType (operation); if (optype == TYPE_TEXT or optype == TYPE_NUM) return operation; // NaV: Not a value if (operation == "NaV") error ("operation did not return a valid value"); // Unknown object error ("object `" + operation + "' is unsupported."); } // if else { string result = ""; for (list<string>::iterator o = operands.begin(); o != operands.end(); o++) { if (IsOperator (*o)) { result += *o; } /* if */ else { result += Eval (*o); } /* else */ } /* for */ return StripE (" ", result); } /* else */ } /* eval */