35#ifndef TCOD_PARSER_HPP_
36#define TCOD_PARSER_HPP_
160 std::swap(data, rhs.data);
185 TCOD_value_type_t newCustomType(TCOD_parser_custom_t custom_type_parser);
217 void error(
const char *msg, ...);
219 bool hasProperty(
const char *name)
const;
220 bool getBoolProperty(
const char *name)
const;
221 int getIntProperty(
const char *name)
const;
222 int getCharProperty(
const char *name)
const;
223 float getFloatProperty(
const char *name)
const;
224 TCODColor getColorProperty(
const char *name)
const;
225 TCOD_dice_t getDiceProperty(
const char *name)
const;
226 const char * getStringProperty(
const char *name)
const;
227 void * getCustomProperty(
const char *name)
const;
228 TCOD_list_t getListProperty(
const char *name, TCOD_value_type_t type)
const;
231 TCOD_parser_t data{};
235#pragma warning(disable: 4251)
237 std::vector<std::unique_ptr<TCODParserStruct>> defs;
241 friend bool new_struct(TCOD_parser_struct_t def,
const char* name)
noexcept;
242 friend bool end_struct(TCOD_parser_struct_t def,
const char* name)
noexcept;
410 TCOD_parser_struct_t data;
632 virtual void error(
const char *msg) = 0;
For basic config files, you don't have to write a listener.
Definition parser.hpp:529
virtual bool parserEndStruct(TCODParser *parser, const TCODParserStruct *str, const char *name)=0
This callback is called each time the parser find the end of a structure declaration in the file.
virtual bool parserProperty(TCODParser *parser, const char *propname, TCOD_value_type_t type, TCOD_value_t value)=0
This callback is called each time the parser find a new property in the file.
virtual bool parserNewStruct(TCODParser *parser, const TCODParserStruct *str, const char *name)=0
This callback is called each time the parser find a new structure declaration in the file.
virtual void error(const char *msg)=0
There are two kind of errors : Errors that are detected by the parser itself (malformed file,...
virtual bool parserFlag(TCODParser *parser, const char *name)=0
This callback is called each time the parser find a new flag in the file.
Definition parser.hpp:141
TCODParserStruct * newStructure(const char *name)
TCODParser()
Use this function to create a generic parser.
~TCODParser()
Once you've done with the file parsing, you can release the resources used by the parser :
void run(const char *filename, ITCODParserListener *listener=NULL)
Once you defined all the structure types and created your listener, you can start the actual parsing ...
Definition parser.hpp:246
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.
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 o...
TCODParserStruct * addStructure(TCODParserStruct *sub_entity)
A structure can contain others structures.
TCODParserStruct * addProperty(const char *propname, TCOD_value_type_t type, bool mandatory)
Use this function to add a standard property to a structure type.
const char * getName() const
You can retrieve the name of the structure type with these functions.
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 * addFlag(const char *propname)
Use this function to add a flag property to a structure type.
Deprecated TCODList class.
Definition mersenne_types.h:45