TORCS  1.3.9
The Open Racing Car Simulator
params.cpp File Reference

Parameter handling API. More...

#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <math.h>
#include <xmlparse.h>
#include <tgf.h>
#include <assert.h>
#include <portability.h>
Include dependency graph for params.cpp:

Go to the source code of this file.

Classes

struct  within
 Structure to hold linked list of within options. More...
 
struct  param
 Parameter header structure, a parameter can either carry a numeric or a string value, numeric value is constraint by min and max, string value by options in within. More...
 
struct  section
 Section header structure. More...
 
struct  parmHeader
 Configuration header structure. More...
 
struct  parmOutput
 Ouput control structure used for serializing parameter set into XML. More...
 
struct  parmHandle
 Parameter set handle structure, multiple handles can reference the same parameter set. More...
 

Macros

#define LINE_SZ   1024
 
#define PARAM_CREATE   0x01
 
#define P_NUM   0
 
#define P_STR   1
 
#define PARM_MAGIC   0x20030815
 
#define PARM_HANDLE_FLAG_PRIVATE   0x01
 
#define PARM_HANDLE_FLAG_PARSE_ERROR   0x02
 

Functions

 GF_TAILQ_HEAD (withinHead, struct within)
 
 GF_TAILQ_HEAD (paramHead, struct param)
 
 GF_TAILQ_HEAD (sectionHead, struct section)
 
 GF_TAILQ_HEAD (parmHead, struct parmHandle)
 
static char * getFullName (const char *sectionName, const char *paramName)
 Helper function to get the full name of a parameter (full name: "sectionName/paramName"). More...
 
static struct paramgetParamByName (struct parmHeader *conf, const char *sectionName, const char *paramName, int flag)
 Helper function to get (or create) a parameter by name. More...
 
static void removeParamByName (struct parmHeader *conf, const char *sectionName, const char *paramName)
 Helper function to remove a parameter with given name paramName. More...
 
static void removeParam (struct parmHeader *conf, struct section *section, struct param *param)
 Helper function to remove given parameter. More...
 
static struct paramaddParam (struct parmHeader *conf, struct section *section, const char *paramName, const char *value)
 Helper function to add parameter, does not check for duplicated name. More...
 
static void removeSection (struct parmHeader *conf, struct section *section)
 Helper function to remove a section and its contents (subsections, elements). More...
 
static struct sectionaddSection (struct parmHeader *conf, const char *sectionName)
 Helper function to add a section to a parameter set. More...
 
static void parmClean (struct parmHeader *conf)
 Helper function to release the parameter set content. More...
 
static void parmReleaseHandle (struct parmHandle *parmHandle)
 Helper function to release the handle and eventually the referenced parameter set (if the reference counter falls to 0). More...
 
static void parmReleaseHeader (struct parmHeader *conf)
 Helper function to release the parameter set if the reference counter is 0. More...
 
static struct sectiongetParent (struct parmHeader *conf, const char *sectionName)
 Helper function to get (or create if not found) parent section of section given in sectionName. More...
 
static void cleanUnusedSection (struct parmHeader *conf, struct section *section)
 Helper function to clean up unused (empty) sections starting with given section. More...
 
void GfParmInit (void)
 Parameter set library API initialization, set up parameter set handle cache. More...
 
void GfParmShutdown (void)
 Parameter set library API shutdown, removes parameter set handle cache. More...
 
static struct parmHeadergetSharedHeader (const char *file, int mode)
 Helper function for looking up parameter sets in the cache. More...
 
static struct parmHeadercreateParmHeader (const char *file)
 Helper function to create header for parameter set handle. More...
 
static void addWithin (struct param *curParam, char *s1)
 Helper function to add "within" options to parameter curParam. More...
 
static int myStrcmp (const void *s1, const void *s2)
 
static tdble getValNumFromStr (const char *str)
 Helper function to parse number. More...
 
static void xmlStartElement (void *userData, const char *name, const char **atts)
 Helper function to process opening XML elements. More...
 
static void xmlEndElement (void *userData, const XML_Char *name)
 Helper function to process closing XML elements. More...
 
static int xmlExternalEntityRefHandler (XML_Parser mainparser, const XML_Char *openEntityNames, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId)
 Helper function to handle external XML entities (XML referencing over multiple files/URI's). More...
 
static int parseXml (struct parmHandle *parmHandle, char *buf, int len, int done)
 Helper function to parse one line of XML. More...
 
static int parserXmlInit (struct parmHandle *parmHandle)
 Helper function to set up XML parser in parmHandle. More...
 
void * GfParmReadBuf (char *buffer)
 Read parameter set from memory buffer and return handle to parameter set. More...
 
void * GfParmReadFile (const char *file, int mode)
 Read parameter set from file and return handle to parameter set. More...
 
static char * handleEntities (char *buf, const int BUFSIZE, const char *val)
 Helper function to convert the input line given in val into proper XML notation, the output goes into buf. More...
 
static void createIndent (char *buf, const int BUFSIZE, const int blanks)
 Helper function for indentation in the XML. More...
 
static void createIn (char *buf, const int BUFSIZE, withinHead *head)
 Helper function to support the serialization into the XML of the "within" attribute. More...
 
static int xmlGetOuputLine (struct parmHandle *parmHandle, char *buffer, int size)
 Helper function to output one line of XML generated from the given parameter set. More...
 
int GfParmWriteBuf (void *handle, char *buf, int size)
 Write a parameter set into a memory buffer. More...
 
void GfParmSetDTD (void *parmHandle, char *dtd, char *header)
 Set the dtd path and header. More...
 
int GfParmWriteFile (const char *file, void *parmHandle, const char *name)
 Write parameter set into file. More...
 
int GfParmCreateDirectory (const char *file, void *parmHandle)
 Create directory for parameter set handle if it does not yet exist. More...
 
void GfParmRemove (void *parmHandle, char *sectionName, char *paramName)
 Remove a parameter from a parameter set. More...
 
void GfParmClean (void *parmHandle)
 Clean all the parameters of a parameter set. More...
 
void GfParmReleaseHandle (void *parmHandle)
 Release given parameter set handle parmHandle. More...
 
static void evalUnit (char *unit, tdble *dest, int flg)
 Support function to multiply or divide dest with unit conversion factor. More...
 
tdble GfParmUnit2SI (const char *unit, tdble val)
 Convert a value given in unit to SI. More...
 
tdble GfParmSI2Unit (const char *unit, tdble val)
 Convert a value from SI to given unit. More...
 
char * GfParmGetName (void *handle)
 Get the name property of the parameter set handle. More...
 
char * GfParmGetFileName (void *handle)
 Get the filename property of the parameter set handle. More...
 
int GfParmGetEltNb (void *handle, const char *path)
 Count the number of subsections in a section in the parameter set handle. More...
 
int GfParmListSeekFirst (void *handle, const char *path)
 Go the the first subsection element in the parameter set handle. More...
 
int GfParmListSeekNext (void *handle, const char *path)
 Go the the next subsection element in the parameter set handle. More...
 
int GfParmListClean (void *handle, const char *path)
 Remove all the subsections in a section in the parameter set handle. More...
 
char * GfParmListGetCurEltName (void *handle, const char *path)
 Get current subsection name of the parameter set handle during subsection iteration. More...
 
const char * GfParmGetStr (void *parmHandle, const char *path, const char *key, const char *deflt)
 Get a string parameter from the parameter set handle. More...
 
const char * GfParmGetCurStr (void *handle, const char *path, const char *key, const char *deflt)
 Get a string parameter from the parameter set handle based on subsection iteration. More...
 
tdble GfParmGetNum (void *handle, const char *path, const char *key, const char *unit, tdble deflt)
 Get a numerical parameter from the parameter set handle. More...
 
tdble GfParmGetCurNum (void *handle, const char *path, const char *key, const char *unit, tdble deflt)
 Get a numerical parameter from the parameter set handle based on subsection iteration. More...
 
int GfParmSetStr (void *handle, const char *path, const char *key, const char *val)
 Set a string parameter in the parameter set handle. More...
 
int GfParmSetCurStr (void *handle, const char *path, const char *key, const char *val)
 Set a string parameter in the parameter set handle based on subsection iteration. More...
 
int GfParmSetNum (void *handle, const char *path, const char *key, const char *unit, tdble val)
 Set a numerical parameter in the parameter set handle. More...
 
int GfParmSetNumEx (void *handle, const char *path, const char *key, const char *unit, tdble val, tdble min, tdble max)
 Set a numerical parameter in the parameter set handle including min and max. More...
 
int GfParmSetCurNum (void *handle, const char *path, const char *key, const char *unit, tdble val)
 Set a numerical parameter in the parameter set handle based on subsection iteration. More...
 
int GfParmCheckHandle (void *ref, void *tgt)
 Check the values in the parameter set tgt against the min/max/within definitions in the ref parameter set. More...
 
static void insertParamMerge (struct parmHandle *parmHandle, char *path, struct param *paramRef, struct param *param)
 Helper function to merge a parameter into a parameter set. More...
 
static void insertParam (struct parmHandle *parmHandle, char *path, struct param *param)
 Helper function to insert a parameter into a parameter set. More...
 
void * GfParmMergeHandles (void *ref, void *tgt, int mode)
 Merge two parameter sets into a new one, either containing parameters from ref, tgt or from both sets, the ref and tgt sets are not changed. More...
 
int GfParmGetNumBoundaries (void *handle, const char *path, const char *key, tdble *min, tdble *max)
 Get the min and max of a numerical parameter from the parameter set handle. More...
 

Variables

static struct parmHead parmHandleList
 

Detailed Description

Parameter handling API.

Author
Bernhard Wymann, Eric Espie
Version
$Id$

Definition in file params.cpp.

Macro Definition Documentation

◆ LINE_SZ

#define LINE_SZ   1024

Definition at line 42 of file params.cpp.

◆ P_NUM

#define P_NUM   0

Definition at line 45 of file params.cpp.

◆ P_STR

#define P_STR   1

Definition at line 46 of file params.cpp.

◆ PARAM_CREATE

#define PARAM_CREATE   0x01

Definition at line 43 of file params.cpp.

◆ PARM_HANDLE_FLAG_PARSE_ERROR

#define PARM_HANDLE_FLAG_PARSE_ERROR   0x02

Definition at line 110 of file params.cpp.

◆ PARM_HANDLE_FLAG_PRIVATE

#define PARM_HANDLE_FLAG_PRIVATE   0x01

Definition at line 109 of file params.cpp.

◆ PARM_MAGIC

#define PARM_MAGIC   0x20030815

Definition at line 94 of file params.cpp.

Function Documentation

◆ GF_TAILQ_HEAD() [1/4]

GF_TAILQ_HEAD ( withinHead  ,
struct within   
)

◆ GF_TAILQ_HEAD() [2/4]

GF_TAILQ_HEAD ( paramHead  ,
struct param   
)

◆ GF_TAILQ_HEAD() [3/4]

GF_TAILQ_HEAD ( sectionHead  ,
struct section   
)

◆ GF_TAILQ_HEAD() [4/4]

GF_TAILQ_HEAD ( parmHead  ,
struct parmHandle   
)

◆ myStrcmp()

static int myStrcmp ( const void *  s1,
const void *  s2 
)
static

Definition at line 662 of file params.cpp.

Variable Documentation

◆ parmHandleList

struct parmHead parmHandleList
static

Definition at line 139 of file params.cpp.