[GRASS5] g51 Vect_set/get_header
Eric G. Miller
egm2 at jps.net
Mon Apr 29 22:06:34 EDT 2002
On Mon, Apr 29, 2002 at 06:02:05PM +0200, Radim Blazek wrote:
> Hi,
>
> in g51 vector library, i would like to replace direct access to
> Map_info structure and replace fuctions like V2_num_lines()
> by one or few funcitons. I see two possibilities:
> 1.
> int Vect_get_header( struct Map_info Map, int item, char *cval,
> int *ival, double *dval)
>
> - *val would be pointers to variables where the value should be saved
>
> 2.
> char Vect_get_header_c( struct Map_info Map, int item)
> int Vect_get_header_i( struct Map_info Map, int item)
> double Vect_get_header_d( struct Map_info Map, int item)
>
> - all return value (pointer to value)
>
> item is code for header field (GV_HEAD_SCALE, GV_NUM_LINES, ...)
>
> What should i use? Or do you know about anything better?
I personally don't like either. They don't increase generality much,
and require you to look at the arguments to figure out what the function
is supposed to do. Maybe a "property" structure containing
a union would be more general?
enum map_header_enum {GV_HEAD_SCALE, GV_NUM_LINES, ...);
enum header_field_type (HFT_CONST_CPTR, HFT_INT, ...);
struct map_header_prop {
enum map_header_enum header_field;
enum header_field_type field_type;
union {
const char *cptr;
int i;
double d;
/* other ? ... */
} data;
};
int Vect_header_get_prop (struct Map_Info *Map,
enum map_header_enum which,
struct map_header_prop *prop);
Though, I'm not sure what wrong with just having a bunch of functions
to get/set things and then hide the details of the Map_info struct
via a typedef. Then:
/* Vect.h */
/* Error codes */
#define VERR_NONE 0x0000
#define VERR_EMEM 0x0001
#define VERR_EINVAL 0x0002
#define VERR_ERANGE 0x0004
/* ... */
typedef struct Map_info * Map_info_ptr;
int Vect_log_errors (FILE *, int, const char *);
int Vect_open_old (Map_info_ptr *, const char *, const char *);
int Vect_close (Map_info_ptr *);
int Vect_get_num_lines(Map_info_ptr);
const char * Vect_get_organization(Map_info_ptr);
int Vect_set_organization(Map_info_ptr, const char *);
...
/* Vect_P.h */
struct Map_info {
/* ... */
};
void * dig_alloc_space (...);
...
--
Eric G. Miller <egm2 at jps.net>
More information about the grass-dev
mailing list