public ArchetypeField(string _name_, FieldType _type_) { if (_name_ == null) { Error.BadArg("Got null archetype parse_field name"); } if (!Token.is_bare_multi_word(_name_)) { Error.BadArg("Got invalid parse_field name '{0}'", _name_); } if (_type_ == null) { Error.BadArg("Got null FieldType"); } name = _name_; type = _type_; // Initialize default_value with a suitable IObjField instance // // Yes, doing an switch on types in an OO system is often a code smell. // Does anyone have an aesthetically better means of implementing Duck-Typing in C# prior to C# 4.0 ? // switch (_type_.semantic_type) { case SemanticTypes.INT: default_value = new FieldInt(); break; case SemanticTypes.STRING: default_value = new FieldString(); break; case SemanticTypes.DECIMAL: default_value = new FieldDecimal(); break; case SemanticTypes.ID: default_value = new FieldID(); break; case SemanticTypes.LIST_INT: default_value = new FieldListInt(); break; case SemanticTypes.LIST_STRING: default_value = new FieldListString(); break; case SemanticTypes.LIST_DECIMAL: default_value = new FieldListDecimal(); break; case SemanticTypes.LIST_ID: default_value = new FieldListID(); break; default: Error.BadArg("Got unknown field type '{0}'", _type_); break; } // This method sets up an IObjField with the default C# value for the storage type // (0, "", 0.0M, or an empty list of one of these). // The additional constructors below (with additional args) are called // when a default field value (or a non-empty default list) is specified, // which is possibly the more common case. }
void warn_add_OBJ_field_mismatch_with_archetype_field(Obj obj, string field_name, FieldType obj_field_type) { warn_at(); Form1.stdout.print(" Field type mismatch with Archetype '{1}', ignoring OBJ field '{0}',\n" + " obj_field_type '{2}' != arch_field_type '{3}'\n", field_name, obj.archetype.tag, obj_field_type.ToString(), obj.archetype[field_name].type.ToString()); }
public void clear_field_data() { // Currently unused, might still be useful to add for more bullet-proofing. // Clear certain members, so the next parsed element starts with a blank slate. // // Strictly speaking, it is not _needful_ to clear this, but examining this struct // when debugging will benefit from having (just-used AND no-longer-needed) fields cleared. // // Some members are not cleared here, as an entity (such as Archetype or Obj) // may have other fields remaining to parse. // Also, the token_index is kept as the value may be useful when debugging. // // ...Another clear method to clear the higher-level information // (excepting token_index, which is never cleared until a new parse) might also be useful... //new_archetype = null; // Keep this //archetype_tag = null; // Keep this // //new_obj = null; // Keep this //parent_archetype = null; // Keep this //obj_tag = null; // Keep this //ID = 0; // Keep this // field_name = null; type_of_field = null; int_val = 0; string_val = null; decimal_val = 0; list_int = null; list_string = null; list_decimal = null; }
void print_debug_for_add_list_field(string field_name, FieldType type, List<int> list_int, List<string> list_string, List<decimal> list_decimal) { return; // Comment out to re-enable debug output. Goes well with the debug output in parse_OBJ_decl() Form1.stdout.print(" OBJ add_field(name={0}, type={1},[", field_name, type.ToString() ); if (list_int != null) { foreach (int ii in list_int ) { Form1.stdout.print("{0}, ", ii); } } if (list_string != null) { foreach (string ss in list_string ) { Form1.stdout.print("'{0}', ", ss); } } if (list_decimal != null) { foreach (decimal dd in list_decimal) { Form1.stdout.print("{0}M, ", dd); } } Form1.stdout.print("]\n"); }
void warn_add_OBJ_field_defaulting_to_basic_field_type(string field_name, string arch_tag, FieldType type) { warn_at(); Form1.stdout.print(" Archetype '{1}' does not define OBJ field '{0}', defaulting type to '{2}'\n", field_name, arch_tag, type.ToString()); }
public void add_field(string field_name, FieldType type, List<decimal> values) { // This serves LIST_DECIMAL and other semantic types sharing the LIST_DECIMAL storage type if (!(type.semantic_type == SemanticTypes.LIST_DECIMAL)) { Error.Throw("LIST_DECIMAL method called for semantic type {0}", type.semantic_type); } add_field(field_name, type); fields[field_name].default_value.dlist = values; }
public void add_field(string field_name, FieldType type) { IObjField field = null; // or perhaps: new FieldTempNull(this, field_name); switch (type.semantic_type) { case SemanticTypes.INT: field = new FieldInt(); break; case SemanticTypes.STRING: field = new FieldString(); break; case SemanticTypes.DECIMAL: field = new FieldDecimal(); break; case SemanticTypes.ID: field = new FieldID(); break; case SemanticTypes.LIST_INT: field = new FieldListInt(); break; case SemanticTypes.LIST_STRING: field = new FieldListString(); break; case SemanticTypes.LIST_DECIMAL: field = new FieldListDecimal(); break; case SemanticTypes.LIST_ID: field = new FieldListID(); break; default: Error.BadArg("Got unknown field type '{0}'", type); break; } fields[field_name] = field; }
public void add_field(string field_name, FieldType type, List<int> values) { // This serves LIST_INT and LIST_ID and other semantic types sharing the LIST_INT storage type if (!(type.semantic_type == SemanticTypes.LIST_INT || type.semantic_type == SemanticTypes.LIST_ID)) { Error.Throw("parse_LIST_INT method called for semantic type {0}", type.semantic_type); } if (type.semantic_type == SemanticTypes.ID) { foreach (int id in values) { // TODO: fix this // if (id is not valid) {Error.Throw("Called with invalid ID {0}", id); } } } add_field(field_name, type); fields[field_name].default_value.ilist = values; }
public void add_field(string field_name, FieldType type, decimal value) { if (!(type.semantic_type == SemanticTypes.DECIMAL)) { Error.Throw("DECIMAL method called for semantic type {0}", type.semantic_type); } add_field(field_name, type); fields[field_name].default_value.dv = value; }
public void add_field(string field_name, FieldType type, string value) { if (!(type.semantic_type == SemanticTypes.STRING)) { Error.Throw("STRING method called for semantic type {0}", type.semantic_type); } add_field(field_name, type); fields[field_name].default_value.sv = value; }
public void add_field(string field_name, FieldType type, int value) { if (!(type.semantic_type == SemanticTypes.INT || type.semantic_type == SemanticTypes.ID)) { Error.Throw("parse_INT method called for semantic type {0}", type.semantic_type); } add_field(field_name, type); fields[field_name].default_value.iv = value; }
public void add_field(string field_name, FieldType type) { ArchetypeField af = new ArchetypeField(field_name, type); fields[field_name] = af; }