Unity 1.0
Parser for unit strings
unity.h
Go to the documentation of this file.
00001 /* GENERATED by Makefile.in */
00002 /* DO NOT EDIT */
00003 #ifndef UNITY_H_LOADED
00004 #define UNITY_H_LOADED 1
00005 /* From known-syntaxes.h */
00006 #ifndef KNOWN_SYNTAXES_H
00007 #define KNOWN_SYNTAXES_H 1
00008 
00012 typedef enum {
00022     UNITY_SYNTAX_FITS,
00030     UNITY_SYNTAX_OGIP,
00040     UNITY_SYNTAX_CDS,
00054     UNITY_SYNTAX_VOUNITS,
00061     UNITY_SYNTAX_LATEX,
00068     UNITY_SYNTAX_DEBUG,
00072     UNITY_SYNTAX_NONE,
00073 } UnitySyntax;
00074 
00075 #if 0
00076 /* XXX DELETE */
00077 #ifdef UNITY_INTERNAL
00078 /* Number of syntaxes */
00079 #define U_NSYNTAXES 6
00080 #endif
00081 #endif
00082 
00083 #endif /* KNOWN_SYNTAXES_H */
00084 
00085 /* From function-definitions.h ... */
00086 #ifndef FUNCTION_DEFINITIONS_H
00087 #define FUNCTION_DEFINITIONS_H 1
00088 
00089 
00090 /* The functions exported by this module are the only ones which need
00091  * access to the data structures dumped into this file, which are
00092  * potentially subject to change.  The implementation of this header
00093  * file is generated by ../grammar/ParseFunctions.java, using the
00094  * function-definitions.c.template file in that directory.
00095  *
00096  * The structure elements with leading underscores are intended to be internal to
00097  * this function-definition.c module.
00098  */
00099 
00103 struct function_definition {
00105     const char* description;
00107     const char* latex_form; 
00108 };
00109 typedef struct function_definition FunctionDef;
00110 
00111 const FunctionDef* unity_get_functiondef_from_string(const char* abbrev, UnitySyntax syntax);
00112 const char* unity_get_function_abbreviation(const FunctionDef* def, UnitySyntax syntax);
00113 
00114 #endif /* FUNCTION_DEFINITIONS_H */
00115 /* ...end function-definitions.h */
00116 
00117 /* From unit-definitions.h ... */
00118 #ifndef UNIT_DEFINITIONS_H
00119 #define UNIT_DEFINITIONS_H 1
00120 
00121 
00122 /* The functions exported by this module are the only ones which need
00123  * access to the data structures dumped into this file, which are
00124  * potentially subject to change.  The implementation of this header
00125  * file is generated by ../grammar/ParseUnits.java, using the
00126  * unit-definitions.c.template file in that directory.
00127  *
00128  * The structure elements with leading underscores are intended to be internal to
00129  * this unit-definition.c module.
00130 */
00131 
00138 typedef struct {
00139     const char* uri;            /* the name for this unit, as a URI */
00140     int _idx;                   /* the internal index for this unit, in the list of unit_definition entries */
00141     const char* name; /* the name of the unit, such as 'Metre' -- not the abbreviation 'm' */
00142     const char* type; /* type such as 'length', as a URI */
00143     const char* dimension; /* the dimensions of this unit, as a string, eg "M L-2" */
00144     const char* description; /* for example 'Hz = s-1', NULL if no notes present */
00145     const char* latex_form; /* an abbrev suitable for LaTeX, if different from a preferred syntax */
00146 } UnitDef;
00147 
00148 //typedef struct unit_definition UnitDef;
00149 
00150 #if UNITY_INTERNAL
00151 /* A unit_representation indicates how a particular unit may be used in a particular syntax. */
00152 struct unit_representation {
00153     const char* symbol;         /* a symbol for this unit, in one syntax */
00154     int _unit_index;            /* the index in the array of unit_definition entries */
00155     int si_prefixes_p;          /* true if this unit may be given SI prefixes */
00156     int binary_prefixes_p;      /* true if this unit may be given binary prefixes */
00157     int is_deprecated_p;        /* true if this unit is deprecated */
00158     int is_preferred_p;         /* true if this unit is the preferred unit amongst some alternatives */
00159 };
00160 typedef struct unit_representation UnitRep;
00161 UnitRep* u_get_unit_representation(const UnitDef*, UnitySyntax syntax);
00162 UnitRep* u_get_unit_representation_any(const UnitDef*);
00163 #endif
00164 
00165 const UnitDef* unity_get_unitdef_from_string(const char* abbrev, UnitySyntax syntax);
00166 const char* unity_get_syntax_name(UnitySyntax syntax);
00167 const char* unity_get_unit_uri(const UnitDef*);
00168 const char* unity_get_unit_name(const UnitDef*);
00169 const char* unity_get_unit_type(const UnitDef*);
00170 const char* unity_get_unit_dimension(const UnitDef*);
00171 const char* unity_get_unit_description(const UnitDef*);
00172 const char* unity_get_unit_latex_form(const UnitDef*);
00173 #endif /* UNIT_DEFINITIONS_H */
00174 /* ...end unit-definitions.h */
00175 
00176 /* From unitylib.h ... */
00177 #ifndef UNITYLIB_H_LOADED
00178 #define UNITYLIB_H_LOADED 1
00179 
00188 typedef struct {
00193     float log_factor;
00197     const struct unit_struct* unit_sequence;
00198 
00199     /* a sorted version of the unit_sequence */
00200     struct unit_struct** sorted_unit_sequence;
00201     int nunits;
00202 } UnitExpression;
00203 
00210 typedef struct {
00213     const struct function_definition* definition;
00216     const char* name;
00218     //const struct unit_struct* operand;
00219     UnitExpression operand;
00220 } FunctionApplication;
00221 
00225 typedef struct {
00230     int prefix_power;           /* -24 to +24 */
00235     char base10_p;
00241     const UnitDef* base_unit_def;
00246     char* base_unit_string;     /* eg Hz or aangstrom */
00247 } SimpleUnit;
00248 
00252 typedef enum {
00254     simple_unit_type,
00256     function_application_type
00257 } UnitTypes;
00258 
00274 struct unit_struct {
00279     float power;
00285     UnitTypes type;
00286     union {
00288         SimpleUnit u;
00290         FunctionApplication f;
00291     };
00293     struct unit_struct *next;
00294 
00300     char is_quoted_unit;
00301 };
00302 
00303 
00305 typedef struct unit_struct Unit;
00306 
00307 const UnitExpression* unity_parse_string(const char* unit_string, const UnitySyntax syntax);
00308 
00309 /* The function unity_parse_error is declared (and documented) here,
00310    and defined in lex.lex */
00321 const char* unity_parse_error(void);
00322 
00323 const char** unity_parser_names(void);
00324 
00325 UnitySyntax unity_identify_parser(const char* parser_name);
00326 const char* unity_parser_name(const UnitySyntax parser_id);
00327 void unity_free_expression(const UnitExpression* u);
00328 const char* unity_version_string();
00329 int unity_version_number();
00330 
00331 /* Selecting units (convenience functions, since the UnitExpression struct is open */
00332 const Unit* unity_get_unit_by_index(const UnitExpression*, int i);
00333 const UnitDef* unity_get_unitdef_from_unit(const Unit*);
00334 const FunctionDef* unity_get_functiondef_from_unit(const Unit*);
00335 
00336 /* Checking units */
00338 #define UNITY_CHECK_RECOGNISED 1
00339 
00340 #define UNITY_CHECK_RECOMMENDED 2
00341 
00342 #define UNITY_CHECK_CONSTRAINTS 4
00343 
00348 #define UNITY_CHECK_ALL UNITY_CHECK_RECOGNISED | UNITY_CHECK_RECOMMENDED | UNITY_CHECK_CONSTRAINTS
00349 int unity_check_unit(const Unit* u, const UnitySyntax syntax, const int flags);
00350 int unity_check_expression(const UnitExpression* ue, const UnitySyntax syntax, const int flags);
00351 int unity_equal_unit_p(const Unit*, const Unit*);
00352 int unity_equal_expression_p(const UnitExpression*, const UnitExpression*);
00353 
00354 #ifdef UNITY_INTERNAL
00355 /* Internal functions */
00356 Unit* u_new_unit(const char* unitString, const float power, const UnitySyntax syntax);
00357 Unit* u_quoted_unit(const char* pfx, const char* unitString,
00358                     const float power, UnitySyntax syntax);
00359 Unit* u_power_of_unit(Unit* u0, const float power);
00360 Unit* u_function_application(const char* functionName,
00361                              const Unit* unit_sequence,
00362                              const UnitySyntax syntax);
00363 Unit* u_unit_append(Unit* u1, const Unit* u2);
00364 void u_receive_result(float, const Unit* unit_sequence);
00365 int u_prefix_to_power(const char pfx);
00366 Unit* u_divide_units(Unit* num, Unit* den);
00367 Unit* u_unit_reciprocal(Unit* u);
00368 void u_free_unit(const Unit* u);
00369 Unit** u_get_sorted_unit_sequence(UnitExpression*, int*);
00370 #endif
00371 
00372 #endif
00373 /* ...end unitylib.h */
00374 
00375 /* From writers.h ... */
00376 #ifndef WRITERS_H_LOADED
00377 #define WRITERS_H_LOADED 1
00378 
00379 #include <stdio.h>
00380 
00381 #ifdef UNITY_INTERNAL
00382 typedef struct {
00383     int nwritten;
00384     int len;
00385     char* buf;
00386 } Buf;
00387 typedef Buf* (*writef_ptr) (Buf*, const UnitExpression*);
00388 #endif
00389 
00390 char* unity_write_formatted(char* buf, int buflen, const UnitExpression*, UnitySyntax);
00391 const char** unity_formatter_names(void);
00392 
00393 #endif
00394 /* ...end writers.h */
00395 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines