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 
21 void NewVariable(unsigned int type,char *name,Tvariable *v)
22 {
23  v->type=type;
25 
26  NEW(v->name,strlen(name)+1,char);
27  strcpy(v->name,name);
28 
29  NewInterval(-INF,INF,&(v->is)); /*default range for the variable*/
30 }
31 
32 
33 void CopyVariable(Tvariable *v_dst,Tvariable *v_src)
34 {
35  v_dst->type=v_src->type;
36  v_dst->topology=v_src->topology;
37 
38  NEW(v_dst->name,strlen(v_src->name)+1,char);
39  strcpy(v_dst->name,v_src->name);
40 
41  CopyInterval(&(v_dst->is),&(v_src->is));
42 }
43 
44 void SetVariableTopology(unsigned int t,Tvariable *v)
45 {
46  if ((t!=TOPOLOGY_R)&&(t!=TOPOLOGY_S))
47  Error("Undefined topology in SetVariableTopology");
48 
49  v->topology=t;
50 }
51 
53 {
54  if ((v->topology==TOPOLOGY_S)&&(IntervalSize(&(v->is))<(M_2PI-ZERO)))
55  return(TOPOLOGY_R);
56  else
57  return(v->topology);
58 }
59 
60 unsigned int GetVariableType(Tvariable *v)
61 {
62  return(v->type);
63 }
64 
66 {
67  return(v->name);
68 }
69 
71 {
72  CopyInterval(&(v->is),i);
73 }
74 
76 {
77  return(&(v->is));
78 }
79 
80 void PrintVariable(FILE *f,Tvariable *v)
81 {
83  if (v->topology==TOPOLOGY_S)
84  {
85  fprintf(f," ~ ");
86  PrintSymbolInterval(f,&(v->is));
87  }
88  else
89  {
90  fprintf(f," : ");
91  PrintInterval(f,&(v->is));
92  }
93 }
94 
96 {
97  free(v->name);
98 }
unsigned int type
Definition: variable.h:86
void PrintVariable(FILE *f, Tvariable *v)
Prints a variable.
Definition: variable.c:80
unsigned int GetVariableType(Tvariable *v)
Gets the variable type.
Definition: variable.c:60
Tinterval * GetVariableInterval(Tvariable *v)
Gets the range of valid values for the variable.
Definition: variable.c:75
#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:70
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:95
Error and warning functions.
void CopyVariable(Tvariable *v_dst, Tvariable *v_src)
Copy constructor.
Definition: variable.c:33
#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:52
char * GetVariableName(Tvariable *v)
Gets the variable name.
Definition: variable.c:65
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:21
void PrintInterval(FILE *f, Tinterval *i)
Prints an interval.
Definition: interval.c:1001
Definition of the Tvariable type and the associated functions.
void PrintSymbolInterval(FILE *f, Tinterval *i)
Prints an angular interval.
Definition: interval.c:986
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:44
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