variable.c
Go to the documentation of this file.
1 #include "variable.h"
2 
3 #include "error.h"
4 #include "defines.h"
5 
6 #include <stdlib.h>
7 #include <string.h>
8 
9 
20 void NewVariable(unsigned int type,char *name,Tvariable *v)
21 {
22  v->type=type;
24 
25  NEW(v->name,strlen(name)+1,char);
26  strcpy(v->name,name);
27 
28  NewInterval(-INF,INF,&(v->is)); /*default range for the variable*/
29 }
30 
31 void CopyVariable(Tvariable *v_dst,Tvariable *v_src)
32 {
33  v_dst->type=v_src->type;
34  v_dst->topology=v_src->topology;
35 
36  NEW(v_dst->name,strlen(v_src->name)+1,char);
37  strcpy(v_dst->name,v_src->name);
38 
39  CopyInterval(&(v_dst->is),&(v_src->is));
40 }
41 
42 void SetVariableTopology(unsigned int t,Tvariable *v)
43 {
44  if ((t!=TOPOLOGY_R)&&(t!=TOPOLOGY_S))
45  Error("Undefined topology in SetVariableTopology");
46 
47  v->topology=t;
48 }
49 
51 {
52  if ((v->topology==TOPOLOGY_S)&&(IntervalSize(&(v->is))<(M_2PI-ZERO)))
53  return(TOPOLOGY_R);
54  else
55  return(v->topology);
56 }
57 
58 unsigned int GetVariableType(Tvariable *v)
59 {
60  return(v->type);
61 }
62 
64 {
65  return(v->name);
66 }
67 
69 {
70  CopyInterval(&(v->is),i);
71 }
72 
74 {
75  return(&(v->is));
76 }
77 
78 void PrintVariable(FILE *f,Tvariable *v)
79 {
81  if (v->topology==TOPOLOGY_S)
82  {
83  fprintf(f," ~ ");
84  PrintSymbolInterval(f,&(v->is));
85  }
86  else
87  {
88  fprintf(f," : ");
89  PrintInterval(f,&(v->is));
90  }
91 }
92 
94 {
95  free(v->name);
96 }
unsigned int type
Definition: variable.h:86
void PrintVariable(FILE *f, Tvariable *v)
Prints a variable.
Definition: variable.c:78
unsigned int GetVariableType(Tvariable *v)
Gets the variable type.
Definition: variable.c:58
Tinterval * GetVariableInterval(Tvariable *v)
Gets the range of valid values for the variable.
Definition: variable.c:73
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
void SetVariableInterval(Tinterval *i, Tvariable *v)
Sets the new range for the variable.
Definition: variable.c:68
Tinterval is
Definition: variable.h:91
void Error(const char *s)
General error function.
Definition: error.c:80
#define TOPOLOGY_R
One of the possible topologies.
Definition: defines.h:122
#define ZERO
Floating point operations giving a value below this constant (in absolute value) are considered 0...
Definition: defines.h:37
void CopyInterval(Tinterval *i_dst, Tinterval *i_org)
Copy constructor.
Definition: interval.c:59
void DeleteVariable(Tvariable *v)
Destructor.
Definition: variable.c:93
Error and warning functions.
void CopyVariable(Tvariable *v_dst, Tvariable *v_src)
Copy constructor.
Definition: variable.c:31
#define PRINT_VARIABLE_NAME(f, name)
Prints a variable name into a file.
Definition: defines.h:427
Definitions of constants and macros used in several parts of the cuik library.
#define M_2PI
2*Pi.
Definition: defines.h:100
unsigned int GetVariableTopology(Tvariable *v)
Gets the topology of the variable.
Definition: variable.c:50
char * GetVariableName(Tvariable *v)
Gets the variable name.
Definition: variable.c:63
Data associated with each variable in the problem.
Definition: variable.h:84
void NewVariable(unsigned int type, char *name, Tvariable *v)
Constructor.
Definition: variable.c:20
void PrintInterval(FILE *f, Tinterval *i)
Prints an interval.
Definition: interval.c:1006
Definition of the Tvariable type and the associated functions.
void PrintSymbolInterval(FILE *f, Tinterval *i)
Prints an angular interval.
Definition: interval.c:991
char * name
Definition: variable.h:90
unsigned int topology
Definition: variable.h:89
void SetVariableTopology(unsigned int t, Tvariable *v)
Sets the topology of the variable.
Definition: variable.c:42
void NewInterval(double lower, double upper, Tinterval *i)
Constructor.
Definition: interval.c:47
#define INF
Infinite.
Definition: defines.h:70
Defines a interval.
Definition: interval.h:33
double IntervalSize(Tinterval *i)
Gets the uppser limit.
Definition: interval.c:96
#define TOPOLOGY_S
One of the possible topologies.
Definition: defines.h:139