Institut de Robòtica i Informàtica Industrial
KRD Group

The CuikSuite Project

constants.h File Reference

Definition of a table of Tconstants. More...

#include "boolean.h"
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  Tconstant
 A constant. More...
struct  Tconstants
 A table of constants. More...

Defines

#define INIT_NUM_CONSTANTS   10
 Initial room for constants.

Functions

void InitConstants (Tconstants *cts)
 Initializes a constant set.
unsigned int NConstants (Tconstants *cts)
 Number of constants.
unsigned int AddConstant (char *name, double v, Tconstants *cts)
 Add a constant.
unsigned int GetConstantWithName (char *name, Tconstants *cts)
 Retrives a constant from the set.
double GetConstantValue (unsigned int n, Tconstants *cts)
 Retrives a the value of a constant.
void PrintConstants (FILE *f, Tconstants *cts)
 Prints a set of constants.
void DeleteConstants (Tconstants *cts)
 Destructor.

Detailed Description

Definition of a table of constants that are pairs (identifier,value) used when processing input files (for instance .cuik files). The definition of constants are useful to facilitate the writting of the equations.

See also:
Tconstant, Tconstants, constants.c.

Definition in file constants.h.


Define Documentation

#define INIT_NUM_CONSTANTS   10

Initial room for constants.It will be enlarged if necessary.

See also:
Tconstants

Definition at line 26 of file constants.h.

Referenced by InitConstants().


Function Documentation

void InitConstants ( Tconstants cts  ) 

Creates a new set of constants.

Parameters:
cts Pointer to the set of constants to be initialized

Definition at line 21 of file constants.c.

References Tconstants::cts, INIT_NUM_CONSTANTS, Tconstants::max_constants, Tconstants::n, and NEW.

unsigned int NConstants ( Tconstants cts  ) 

Returns the number of constants currently in the set.

Parameters:
cts Pointer to the set of constants.
Returns:
The number of constants held in the set.

Definition at line 33 of file constants.c.

References Tconstants::n.

unsigned int AddConstant ( char *  name,
double  v,
Tconstants cts 
)

Adds a new constnat to the set. It does not test whether or not there is another constant with the same name. This must be tested before using AddConstant calling the function 'GetConstantWithName'

Parameters:
name Name of the constant.
v Value of the new constant.
cts Pointer to the set of constants.
Returns:
The position at which the constant is added (i.e., the numerical identifier for the constant).
See also:
GetConstantWithName

Definition at line 43 of file constants.c.

References Tconstants::cts, Tconstants::max_constants, MEM_DUP, Tconstants::n, Tconstant::name, NEW, and Tconstant::vs.

unsigned int GetConstantWithName ( char *  name,
Tconstants cts 
)

Determines the numerical identifier for a constant with a given name. It can be used also to check if a constant is included in the set or not.

Parameters:
name Name of the constant to retrive.
cts Pointer to the set of constants.
Returns:
The numerical identifier for the constant and NO_UINT if there is no constant in the set with the given name.

Definition at line 66 of file constants.c.

References Tconstants::cts, FALSE, Tconstant::name, NO_UINT, and TRUE.

double GetConstantValue ( unsigned int  n,
Tconstants cts 
)

Returns the value of a constant, given the numerical identifier of this constant.

Parameters:
n Numerical identifier of the constant whose value we want to retrive.
cts Pointer to the set of constants.
Returns:
The value of the constat or 0 if there is no constant with the given numerical identifier.

Definition at line 91 of file constants.c.

References Tconstants::cts, Error(), and Tconstant::vs.

Here is the call graph for this function:

void PrintConstants ( FILE *  f,
Tconstants cts 
)

Prints a set of constants into a stream, that can be stdout.

Parameters:
f The stream where to print the constant set.
cts Pointer to the set of constants to be printed.

Definition at line 104 of file constants.c.

References Tconstants::cts, Tconstants::n, Tconstant::name, and Tconstant::vs.

void DeleteConstants ( Tconstants cts  ) 

Deletes a set of constants.

Parameters:
cts Pointer to the set of constants to be deleted.

Definition at line 115 of file constants.c.

References Tconstants::cts, Tconstants::n, and Tconstant::name.