bzr branch
http://suren.me/webbzr/alps/pcitool
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
1 |
#ifndef _PCILIB_UNIT_H
|
2 |
#define _PCILIB_UNIT_H
|
|
3 |
||
311
by Suren A. Chilingaryan
Implement enum view |
4 |
#include <uthash.h> |
5 |
||
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
6 |
#include <pcilib.h> |
7 |
||
8 |
#define PCILIB_UNIT_INVALID ((pcilib_unit_t)-1)
|
|
309
by Suren A. Chilingaryan
Base functions for views |
9 |
#define PCILIB_UNIT_TRANSFORM_INVALID ((pcilib_unit_transform_t)-1)
|
10 |
||
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
11 |
#define PCILIB_MAX_TRANSFORMS_PER_UNIT 16 /**< Limits number of supported transforms per unit */ |
12 |
||
310
by Suren A. Chilingaryan
Introduce hashes |
13 |
typedef struct pcilib_unit_context_s pcilib_unit_context_t; |
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
14 |
|
15 |
/**
|
|
16 |
* unit transformation routines
|
|
17 |
*/
|
|
18 |
typedef struct { |
|
309
by Suren A. Chilingaryan
Base functions for views |
19 |
char *unit; /**< Name of the resulting unit */ |
20 |
char *transform; /**< String, similar to view formula, explaining transform to this unit */ |
|
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
21 |
} pcilib_unit_transform_t; |
22 |
||
23 |
typedef struct { |
|
309
by Suren A. Chilingaryan
Base functions for views |
24 |
char *name; /**< Unit name */ |
25 |
pcilib_unit_transform_t transforms[PCILIB_MAX_TRANSFORMS_PER_UNIT + 1]; /**< Transforms to other units */ |
|
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
26 |
} pcilib_unit_description_t; |
27 |
||
311
by Suren A. Chilingaryan
Implement enum view |
28 |
struct pcilib_unit_context_s { |
29 |
const char *name; |
|
30 |
pcilib_unit_t unit; |
|
31 |
UT_hash_handle hh; |
|
32 |
};
|
|
33 |
||
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
34 |
#ifdef __cplusplus
|
35 |
extern "C" { |
|
36 |
#endif
|
|
37 |
||
315
by Suren A. Chilingaryan
Support properties of arbitrary type |
38 |
/**
|
39 |
* Use this function to add new unit definitions into the model. It is error to re-register
|
|
40 |
* already registered unit. The function will copy the context of unit description, but name,
|
|
41 |
* transform, and other strings in the structure are considered to have static duration
|
|
42 |
* and will not be copied. On error no new units are initalized.
|
|
324
by Suren A. Chilingaryan
Documentation update |
43 |
* @param[in,out] ctx - pcilib context
|
44 |
* @param[in] n - number of units to initialize. It is OK to pass 0 if protocols variable is NULL terminated (last member of protocols array have all members set to 0)
|
|
45 |
* @param[in] desc - unit descriptions
|
|
46 |
* @return - error or 0 on success
|
|
315
by Suren A. Chilingaryan
Support properties of arbitrary type |
47 |
*/
|
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
48 |
int pcilib_add_units(pcilib_t *ctx, size_t n, const pcilib_unit_description_t *desc); |
315
by Suren A. Chilingaryan
Support properties of arbitrary type |
49 |
|
50 |
/**
|
|
51 |
* Destroys data associated with units. This is an internal function and will
|
|
52 |
* be called during clean-up.
|
|
324
by Suren A. Chilingaryan
Documentation update |
53 |
* @param[in,out] ctx - pcilib context
|
54 |
* @param[in] start - specifies first unit to clean (used to clean only part of the units to keep the defined state if pcilib_add_units has failed)
|
|
315
by Suren A. Chilingaryan
Support properties of arbitrary type |
55 |
*/
|
56 |
void pcilib_clean_units(pcilib_t *ctx, pcilib_unit_t start); |
|
309
by Suren A. Chilingaryan
Base functions for views |
57 |
|
324
by Suren A. Chilingaryan
Documentation update |
58 |
/**
|
59 |
* Find unit id using supplied name.
|
|
60 |
* @param[in] ctx - pcilib context
|
|
61 |
* @param[in] unit - the requested unit name
|
|
62 |
* @return - unit id or PCILIB_UNIT_INVALID if error not found or error has occured
|
|
63 |
*/
|
|
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
64 |
pcilib_unit_t pcilib_find_unit_by_name(pcilib_t *ctx, const char *unit); |
324
by Suren A. Chilingaryan
Documentation update |
65 |
|
66 |
/**
|
|
67 |
* Find the required transform between two specified units.
|
|
68 |
* @param[in] ctx - pcilib context
|
|
69 |
* @param[in] from - the source unit
|
|
70 |
* @param[in] to - destination unit
|
|
71 |
* @return - the pointer to unit transform or NULL in case of error. If no transform required (i.e. \a from = \a to),
|
|
72 |
the function will return #pcilib_unit_transform_t structure with \a transform field set to NULL.
|
|
73 |
*/
|
|
309
by Suren A. Chilingaryan
Base functions for views |
74 |
pcilib_unit_transform_t *pcilib_find_transform_by_unit_names(pcilib_t *ctx, const char *from, const char *to); |
75 |
||
315
by Suren A. Chilingaryan
Support properties of arbitrary type |
76 |
/**
|
77 |
* Converts value to the requested units. It is error to convert values with unspecified units.
|
|
78 |
* This is internal function, use pcilib_value_convert_value_unit instead.
|
|
324
by Suren A. Chilingaryan
Documentation update |
79 |
* @param[in,out] ctx - pcilib context
|
80 |
* @param[in] trans - the requested unit transform
|
|
315
by Suren A. Chilingaryan
Support properties of arbitrary type |
81 |
* @param[in,out] value - the value to be converted (changed on success)
|
324
by Suren A. Chilingaryan
Documentation update |
82 |
* @return - error or 0 on success
|
315
by Suren A. Chilingaryan
Support properties of arbitrary type |
83 |
*/
|
84 |
int pcilib_transform_unit(pcilib_t *ctx, const pcilib_unit_transform_t *trans, pcilib_value_t *value); |
|
85 |
||
86 |
/**
|
|
87 |
* Converts value to the requested units. It is error to convert values with unspecified units.
|
|
88 |
* This is internal function, use pcilib_value_convert_value_unit instead.
|
|
324
by Suren A. Chilingaryan
Documentation update |
89 |
* @param[in,out] ctx - pcilib context
|
90 |
* @param[in] to - specifies the requested unit of the value
|
|
315
by Suren A. Chilingaryan
Support properties of arbitrary type |
91 |
* @param[in,out] value - the value to be converted (changed on success)
|
324
by Suren A. Chilingaryan
Documentation update |
92 |
* @return - error or 0 on success
|
315
by Suren A. Chilingaryan
Support properties of arbitrary type |
93 |
*/
|
309
by Suren A. Chilingaryan
Base functions for views |
94 |
int pcilib_transform_unit_by_name(pcilib_t *ctx, const char *to, pcilib_value_t *value); |
95 |
||
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
96 |
|
97 |
#ifdef __cplusplus
|
|
98 |
}
|
|
99 |
#endif
|
|
100 |
||
101 |
||
102 |
#endif /* _PCILIB_UNIT_H */ |