|
libtcod
|
Public Member Functions | |
| TCODParserStruct * | addFlag (const char *propname) |
| Use this function to add a flag property to a structure type. | |
| TCODParserStruct * | addProperty (const char *propname, TCOD_value_type_t type, bool mandatory) |
| Use this function to add a standard property to a structure type. | |
| TCODParserStruct * | addValueList (const char *propname, const char **value_list, bool mandatory) |
| A value-list property is a string property for which we define the list of allowed values. | |
| TCODParserStruct * | addListProperty (const char *propname, TCOD_value_type_t type, bool mandatory) |
| Use this function to add a list property to a structure type. | |
| TCODParserStruct * | addStructure (TCODParserStruct *sub_entity) |
| A structure can contain others structures. | |
| const char * | getName () const |
| You can retrieve the name of the structure type with these functions. | |
| bool | isPropertyMandatory (const char *propname) const |
| You can know if a property is mandatory : | |
| TCOD_value_type_t | getPropertyType (const char *propname) const |
| You get the type of a property : In the case of a list property, the value returned is a bitwise or of TCOD_TYPE_LIST and the list element's type. | |
Public Attributes | |
| TCOD_parser_struct_t | data |
| TCODParserStruct * TCODParserStruct::addFlag | ( | const char * | propname | ) |
Use this function to add a flag property to a structure type.
A flag is a simplified boolean property. It cannot be mandatory: either it's present and it's true, or it's absent and it's false.
Note that in the C++ version, the function returns its parent object, allowing for chaining.
| str | In the C version, the structure handler, returned by TCOD_parser_new_struct. |
| name | The name of the flag (in the example, this would be "abstract"). |
| TCODParserStruct * TCODParserStruct::addListProperty | ( | const char * | propname, |
| TCOD_value_type_t | type, | ||
| bool | mandatory ) |
Use this function to add a list property to a structure type.
Note that in the C++ version, the function returns its parent object, allowing for chaining.
| str | In the C version, the structure handler, returned by TCOD_parser_new_struct. |
| name | The name of the property (in the example, this would be "cost" or "damages" or ...). |
| type | The type of the list elements. It must be a standard type (see this). It cannot be TCOD_TYPE_LIST. |
| mandatory | Is this property mandatory ? If true and the property is not defined in the file, the parser will raise an error. |
itemTypeStruct->addListProperty("intList",TCOD_TYPE_INT,true) ->addListProperty("floatList",TCOD_TYPE_FLOAT,true) ->addListProperty("stringList",TCOD_TYPE_STRING,true);
TCOD_struct_add_list_property(item_type_struct, "intList", TCOD_TYPE_INT, true); TCOD_struct_add_list_property(item_type_struct, "floatList", TCOD_TYPE_FLOAT, true); TCOD_struct_add_list_property(item_type_struct, "stringList", TCOD_TYPE_STRING, true);
libtcod.struct_add_list_property(item_type_struct, "intList", libtcod.TYPE_INT, True) libtcod.struct_add_list_property(item_type_struct, "floatList", libtcod.TYPE_FLOAT, True) libtcod.struct_add_list_property(item_type_struct, "stringList", libtcod.TYPE_STRING, True)
| TCODParserStruct * TCODParserStruct::addProperty | ( | const char * | propname, |
| TCOD_value_type_t | type, | ||
| bool | mandatory ) |
Use this function to add a standard property to a structure type.
Check standard property types here.
Note that in the C++ version, the function returns its parent object, allowing for chaining.
| str | In the C version, the structure handler, returned by TCOD_parser_new_struct. |
| name | The name of the property (in the example, this would be "cost" or "damage" or ...). |
| type | The type of the property. It can be a standard type (see this). |
| mandatory | Is this property mandatory? If true and the property is not defined in the file, the parser will raise an error. |
itemTypeStruct->addProperty("cost",TCOD_TYPE_INT,true) ->addProperty("weight",TCOD_TYPE_FLOAT,true) ->addProperty("deal_damage",TCOD_TYPE_BOOL,true) ->addProperty("damaged_color",TCOD_TYPE_COLOR,true);
TCOD_struct_add_property(item_type_struct, "cost", TCOD_TYPE_INT, true); TCOD_struct_add_property(item_type_struct, "damages", TCOD_TYPE_DICE, true); TCOD_struct_add_property(item_type_struct, "color", TCOD_TYPE_COLOR, true); TCOD_struct_add_property(item_type_struct, "damaged_color", TCOD_TYPE_COLOR, true);
libtcod.struct_add_property(item_type_struct, "cost", libtcod.TYPE_INT, True) libtcod.struct_add_property(item_type_struct, "damages", libtcod.TYPE_DICE, True) libtcod.struct_add_property(item_type_struct, "color", libtcod.TYPE_COLOR, True) libtcod.struct_add_property(item_type_struct, "damaged_color", libtcod.TYPE_COLOR, True)
| TCODParserStruct * TCODParserStruct::addStructure | ( | TCODParserStruct * | sub_entity | ) |
A structure can contain others structures.
You can tell the parser which structures are allowed inside one structure type with this function.
Note that in the C++ version, the function returns its parent object, allowing for chaining.
| str | In the C version, the structure handler, returned by TCOD_parser_new_struct. |
| sub_structure | The structure type that can be embedded. |
The item_type structure can contain itself itemTypeStruct->addStructure(itemTypeStruct);
| TCODParserStruct * TCODParserStruct::addValueList | ( | const char * | propname, |
| const char ** | value_list, | ||
| bool | mandatory ) |
A value-list property is a string property for which we define the list of allowed values.
The parser will raise an error if the file contains an unauthorized value for this property. The first value-list property that you add to a structure type will have the TCOD_TYPE_VALUELIST00 type. The next TCOD_TYPE_VALUELIST01. You can define up to 16 value list property for each structure type. The last one has the type TCOD_TYPE_VALUELIST15. You must provide a value list as a NULL terminated array of strings.
Note that in the C++ version, the function returns its parent object, allowing for chaining.
| str | In the C version, the structure handler, returned by TCOD_parser_new_struct. |
| name | The name of the property (in the example, this would be "damage_type"). |
| value_list | The list of allowed strings. |
| mandatory | Is this property mandatory ? If true and the property is not defined in the file, the parser will raise an error. |
static const char *damageTypes[] = { "slash", "pierce", "bludgeon", NULL }; // note the ending NULL itemTypeStruct->addValueList("damage_type", damageTypes, true);
static const char *damage_types[] = { "slash", "pierce", "bludgeon", NULL }; TCOD_struct_add_value_list(item_type_struct, "damage_type", damage_types, true);
damage_types = [ "slash", "pierce", "bludgeon" ] libtcod.struct_add_value_list(item_type_struct, "damage_type", damage_types, True)
| const char * TCODParserStruct::getName | ( | ) | const |
You can retrieve the name of the structure type with these functions.
Warning ! Do not confuse the structure type's name with the structure's name :
Here, the structure type's name is "item_type", the structure name is "sword". Obviously, the structure name cannot be retrieved from the TCODParserStruct object because it's only known at "runtime" (while parsing the file).
| str | In the C version, the structure handler, returned by TCOD_parser_new_struct. |
| TCOD_value_type_t TCODParserStruct::getPropertyType | ( | const char * | propname | ) | const |
You get the type of a property : In the case of a list property, the value returned is a bitwise or of TCOD_TYPE_LIST and the list element's type.
For example, for a list of int, it will return TCOD_TYPE_LIST | TCOD_TYPE_INT.
| str | In the C version, the structure handler, returned by TCOD_parser_new_struct. |
| name | The name of the property, as defined when you called addProperty or addValueList or addListProperty. |
TCOD_value_type_t costType = itemTypeStruct->getPropertyType("cost"); // returns TCOD_TYPE_INT TCOD_value_type_t intListType = itemTypeStruct->getPropertyType("intList"); // returns TCOD_TYPE_LIST|TCOD_TYPE_INT
| bool TCODParserStruct::isPropertyMandatory | ( | const char * | propname | ) | const |
You can know if a property is mandatory :
| str | In the C version, the structure handler, returned by TCOD_parser_new_struct. |
| name | The name of the property, as defined when you called addProperty or addValueList or addListProperty. |