//Fonction qui crée un pokemon Pokemon new_pokemon (char* nom, char* type, int lvl, int atk, int def, int hpmax, int hp, Attaque att1, Attaque att2, Attaque att3, Attaque att4) { Pokemon pok = {nom, string_type_to_int(type), lvl, atk, def, hpmax, hp}; pok.Attaques[0] = att1; pok.Attaques[1] = att2; pok.Attaques[2] = att3; pok.Attaques[3] = att4; return(pok); }
Column MetaDataConfig::fill_column_meta(ElementTree::ElementPtr node) { String name, type, fk_table, fk_field, prop_name, xml_name, index; int flags = 0, size = 0, col_type = 0; Yb::Value default_val; if (!node->has_attr(_T("name"))) throw MandatoryAttributeAbsent(_T("column"), _T("name")); else name = node->get_attr(_T("name")); if (!node->has_attr(_T("type"))) throw MandatoryAttributeAbsent(_T("column"), _T("type")); else { type = node->get_attr(_T("type")); col_type = string_type_to_int(type, name); } if (node->has_attr(_T("default"))) { String value = node->get_attr(_T("default")); switch (col_type) { case Value::FLOAT: try { double x; from_string(value, x); default_val = Value(x); } catch(const std::exception &) { throw ParseError(String(_T("Wrong default value '")) + value + _T("' for float element '") + name + _T("'")); } break; case Value::DECIMAL: try { Decimal x; from_string(value, x); default_val = Value(x); } catch(const std::exception &) { throw ParseError(String(_T("Wrong default value '")) + value + _T("' for decimal element '") + name + _T("'")); } break; case Value::INTEGER: case Value::LONGINT: try { LongInt x; from_string(value, x); default_val = Value(x); } catch(const std::exception &) { throw ParseError(String(_T("Wrong default value '")) + value + _T("' for integer element '") + name + _T("'")); } break; case Value::DATETIME: if (Yb::StrUtils::str_to_lower(node->get_attr(_T("default"))) != String(_T("sysdate"))) throw ParseError(String(_T("Wrong default value for datetime element '"))+ name + _T("'")); default_val = Value(_T("sysdate")); break; default: default_val = Value(node->get_attr(_T("default"))); } } if (node->has_attr(_T("size"))) from_string(node->get_attr(_T("size")), size); if (node->has_attr(_T("property"))) prop_name = node->get_attr(_T("property")); if (node->has_attr(_T("xml-name"))) xml_name = node->get_attr(_T("xml-name")); ElementTree::Elements::const_iterator child = node->children_.begin(), cend = node->children_.end(); for (; child != cend; ++child) { if (!(*child)->name_.compare(_T("read-only"))) flags |= Column::RO; if (!(*child)->name_.compare(_T("primary-key"))) flags |= Column::PK; if (!(*child)->name_.compare(_T("foreign-key"))) { get_foreign_key_data(*child, fk_table, fk_field); } if (!(*child)->name_.compare(_T("index"))) { index = (*child)->get_text(); } } bool nullable = !(flags & Column::PK); if (node->has_attr(_T("null"))) { //if (col_type == Value::STRING) // throw InvalidCombination(_T("nullable attribute cannot be used for strings")); if (node->get_attr(_T("null")) == _T("false")) nullable = false; } if (nullable) flags |= Column::NULLABLE; if((size > 0) && (col_type != Value::STRING)) throw InvalidCombination(_T("Size musn't me used for not a String type")); Column result(name, col_type, size, flags, default_val, fk_table, fk_field, xml_name, prop_name, index); return result; }
//Fonction qui crée une attaque Attaque new_attack (char* nom, int force, char* type) { Attaque a = {nom, force, string_type_to_int(type)}; return(a); }