BoundVariable Variable::bind(int intVal) const { switch (m_type) { case Type::UINT8: return BoundVariable(*this, (uint8_t)intVal); case Type::INT8: return BoundVariable(*this, (int8_t)intVal); case Type::UINT16: return BoundVariable(*this, (uint16_t)intVal); case Type::INT16: return BoundVariable(*this, (int16_t)intVal); default: throw std::invalid_argument("bound int to a non-integral Variable"); } }
BoundVariable Variable::bind(const BoundRegisterRange& range) const { uint8_t arr[4]; for (uint8_t i = 0; i < size(); i++) { arr[i] = range.at(i + startReg()); } return BoundVariable(*this, arr); }
BoundVariable Variable::bind(const BoundRegisterSet& set) const { uint8_t arr[4]; for (uint8_t i = 0; i < size(); i++) { arr[i] = set[i + startReg()]; } return BoundVariable(*this, arr); }
CoreVariable* CSettings::LoadSetting(PCoreString Name) { CoreVariable *Var = GetCoreVariable(Name); if (Var == NULL) return NULL; std::vector<std::string> RawData; LoadRawData(&RawData); for (int i = 0; i < (int)RawData.size(); ++i) { std::string VarName = GetElementData("Name", RawData[i]); if (strstr(VarName.c_str(), Name)) { eCoreVariableType VarType = GetElementDataType((PCoreString)GetElementData("Type", RawData[i]).c_str()); std::string VarValue = GetElementData("Value", RawData[i]); if (VarType == eCoreVariableType::VAR_UNKNOWN) continue; if (VarType == eCoreVariableType::VAR_INTEGER || VarType == eCoreVariableType::VAR_BOOL) { if (VarValue.find_first_not_of("0123456789") != EOF) *(PINT)Var->Variable = Var->iDefault; else *(PINT)Var->Variable = atoi(VarValue.c_str()); } if (VarType == eCoreVariableType::VAR_FLOAT || VarType == eCoreVariableType::VAR_DOUBLE) { if (VarValue.find_first_not_of("1234567890.") != EOF) { if (VarType == eCoreVariableType::VAR_FLOAT) *(PFLOAT)Var->Variable = Var->fDefault; if (VarType == eCoreVariableType::VAR_DOUBLE) *(PDOUBLE)Var->Variable = Var->dDefault; } else { if (VarType == eCoreVariableType::VAR_FLOAT) *(PFLOAT)Var->Variable = (float)atof(VarValue.c_str()); if (VarType == eCoreVariableType::VAR_DOUBLE) *(PDOUBLE)Var->Variable = atof(VarValue.c_str()); } } if (VarType == eCoreVariableType::VAR_STRING) strcpy_s((PCoreString)Var->Variable, VarValue.size() + 1, VarValue.c_str()); if (VarType == eCoreVariableType::VAR_COLOR) { COLOR32* Color = (COLOR32*)Var->Variable; bool Red = VarName.find("Red") != EOF; bool Green = VarName.find("Green") != EOF; bool Blue = VarName.find("Blue") != EOF; bool Alpha = VarName.find("Alpha") != EOF; if (VarValue.find_first_not_of("0123456789") != EOF) { if (Red) Color->r = Var->clrDefault.r; if (Green) Color->g = Var->clrDefault.g; if (Blue) Color->b = Var->clrDefault.b; if (Alpha) Color->a = Var->clrDefault.a; } else { if (Red) Color->r = atoi(VarValue.c_str()); if (Green) Color->g = atoi(VarValue.c_str()); if (Blue) Color->b = atoi(VarValue.c_str()); if (Alpha) Color->a = atoi(VarValue.c_str()); } } BoundVariable(Var); } } return Var; }
BoundVariable Variable::bind(float floatVal) const { // BoundVariable will throw an exception if necessary return BoundVariable(*this, floatVal); }