grass  7.8.6
About: GRASS (Geographic Resources Analysis Support System) is a raster- and vector-based GIS, image processing system, graphics production system and spatial modeling system.
  Fossies Dox: grass-7.8.6.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

gsds.c File Reference

OGSF library - dataset loading and management (lower level functions) More...

#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/glocale.h>
#include <grass/ogsf.h>
Include dependency graph for gsds.c:

Go to the source code of this file.

Macros

#define LUCKY   33
 
#define BLOC   20
 
#define MAX_DS   100
 

Functions

static int init_gsds (void)
 Initialize gsds. More...
 
static int check_numsets (void)
 Check numsets. More...
 
static datasetget_dataset (int id)
 Get dataset. More...
 
static int get_type (dataset *ds)
 Get type. More...
 
int gsds_findh (const char *name, IFLAG *changes, IFLAG *types, int begin)
 Get handle to gsds.
More...
 
int gsds_newh (const char *name)
 Get handle to gsds. More...
 
typbuffgsds_get_typbuff (int id, IFLAG change_flag)
 Get data buffer. More...
 
char * gsds_get_name (int id)
 Get name. More...
 
int gsds_free_datah (int id)
 Free allocated dataset. More...
 
int gsds_free_data_buff (int id, int typ)
 Free allocated buffer. More...
 
size_t free_data_buffs (dataset *ds, int typ)
 Free data buffer. More...
 
size_t gsds_alloc_typbuff (int id, int *dims, int ndims, int type)
 Allocates correct buffer according to type, keeps track of total mem. More...
 
int gsds_get_changed (int id)
 ADD. More...
 
int gsds_set_changed (int id, IFLAG reason)
 ADD. More...
 
int gsds_get_type (int id)
 ADD. More...
 

Variables

static datasetData [100]
 
static dataset Ds [100]
 
static int Numsets = 0
 
static int Cur_id = 33
 
static int Cur_max
 
static size_t Tot_mem = 0
 

Detailed Description

OGSF library - dataset loading and management (lower level functions)

GRASS OpenGL gsurf OGSF Library

The idea here is to treat datasets as separate objects, which SHOULD:

  • allow easier reuse of data for different attributes.
  • allow a mechanism for changing data and have changes reflected in each attribute using that data.
  • allow a mechanism to automatically update data when the data source is changed.
  • allow easier weaning from GRASS.
  • allow easier use of shared memory between processes.

These structures are defined in gstypes.h:

typedef struct{ float *fb; int *ib; short *sb; char *cb; struct BM *bm; } typbuff;

How about adding a transform func here, so GET_MAPATT would do an on-the-fly transformation? Or even a transform func LIST!

typedef struct{ int data_id; int dims[MAXDIMS]; int ndims; int numbytes; char unique_name[80]; typbuff databuff; int changed; int need_reload; } dataset;

(C) 1999-2008 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Bill Brown UI GMS Lab
Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)

Definition in file gsds.c.

Macro Definition Documentation

◆ BLOC

#define BLOC   20

Definition at line 64 of file gsds.c.

◆ LUCKY

#define LUCKY   33

Definition at line 63 of file gsds.c.

◆ MAX_DS

#define MAX_DS   100

Definition at line 65 of file gsds.c.

Function Documentation

◆ check_numsets()

static int check_numsets ( void  )
static

Check numsets.

Returns
0 numset < cur_max

Definition at line 103 of file gsds.c.

References _, Cur_max, G_fatal_error(), and Numsets.

Referenced by gsds_newh().

◆ free_data_buffs()

size_t free_data_buffs ( dataset ds,
int  typ 
)

Free data buffer.

Parameters
dspointer to dataset struct
typdata type
Returns
freed size

Definition at line 393 of file gsds.c.

References ATTY_CHAR, ATTY_FLOAT, ATTY_INT, ATTY_MASK, ATTY_NULL, ATTY_SHORT, BM_destroy(), BM_get_map_size(), ds, G_debug(), NULL, and Tot_mem.

Referenced by gsds_free_data_buff(), and gsds_free_datah().

◆ get_dataset()

static dataset * get_dataset ( int  id)
static

Get dataset.

Parameters
iddata id
Returns
pointer to dataset struct
NULL dataset not found

Definition at line 123 of file gsds.c.

References Data, NULL, and Numsets.

Referenced by gsds_alloc_typbuff(), gsds_get_changed(), gsds_get_typbuff(), gsds_get_type(), and gsds_set_changed().

◆ get_type()

static int get_type ( dataset ds)
static

Get type.

Parameters
dspointer to dataset struct
Returns
type code
-1 unsupported type

Definition at line 144 of file gsds.c.

References ATTY_CHAR, ATTY_FLOAT, ATTY_INT, ATTY_MASK, ATTY_SHORT, and ds.

Referenced by gsds_findh(), and gsds_get_type().

◆ gsds_alloc_typbuff()

size_t gsds_alloc_typbuff ( int  id,
int *  dims,
int  ndims,
int  type 
)

Allocates correct buffer according to type, keeps track of total mem.

Todo:
add ATTY_CONST
Parameters
iddataset id
dimsarray of dimensions
ndimsnumber of dimensions
typedata type
Returns
amount of allocated memory

Definition at line 482 of file gsds.c.

References ATTY_CHAR, ATTY_FLOAT, ATTY_INT, ATTY_MASK, ATTY_NULL, ATTY_SHORT, BM_create(), BM_get_map_size(), ds, G_debug(), get_dataset(), NULL, Tot_mem, and type.

Referenced by gs_malloc_att_buff().

◆ gsds_findh()

int gsds_findh ( const char *  name,
IFLAG changes,
IFLAG types,
int  begin 
)

Get handle to gsds.

Successive calls will continue search until "begin" is set
(problem here is, unique_name no longer uniquely identifies dataset, since changes may be made; but unique_name should still be useful for reloading dataset) changes & types are set to actual for dataset if found.

Parameters
name
changes,typesacceptable changes & types, flags may be or'd not changed is assumed to always be acceptable
beginflag to indicate search from beginning
Returns
data id
-1 not found

Definition at line 188 of file gsds.c.

References dataset::changed, Data, get_type(), name, and Numsets.

Referenced by GS_load_att_map().

◆ gsds_free_data_buff()

int gsds_free_data_buff ( int  id,
int  typ 
)

Free allocated buffer.

Parameters
iddataset id
typdata type
Returns
0 not found
1 found

Definition at line 369 of file gsds.c.

References Data, free_data_buffs(), and Numsets.

Referenced by GS_load_att_map().

◆ gsds_free_datah()

int gsds_free_datah ( int  id)

Free allocated dataset.

Parameters
id
Returns
0 not found
1 found

Definition at line 329 of file gsds.c.

References ATTY_ANY, Data, dataset::data_id, free_data_buffs(), G_debug(), G_free(), NULL, Numsets, and dataset::unique_name.

Referenced by gs_free_unshared_buffs(), and gs_set_att_src().

◆ gsds_get_changed()

int gsds_get_changed ( int  id)

ADD.

Parameters
id
Returns
-1 on error

Definition at line 615 of file gsds.c.

References ds, and get_dataset().

Referenced by Gs_update_attrange().

◆ gsds_get_name()

char * gsds_get_name ( int  id)

Get name.

Parameters
id
Returns
name
NULL on failure

Definition at line 303 of file gsds.c.

References Data, GPATH_MAX, NULL, Numsets, and dataset::unique_name.

Referenced by GS_get_att(), and GS_get_cat_at_xy().

◆ gsds_get_typbuff()

typbuff * gsds_get_typbuff ( int  id,
IFLAG  change_flag 
)

Get data buffer.

Doesn't prevent writing a buff thats's been gotten with change_flag == 0 (could return a copy, but willing to trust calling func for now)

Parameters
iddataset id
change_flagset changed flag
Returns
pointer to typbuff struct
NULL on failure

Definition at line 281 of file gsds.c.

References ds, get_dataset(), and NULL.

Referenced by gs_get_att_typbuff(), and Gs_update_attrange().

◆ gsds_get_type()

int gsds_get_type ( int  id)

ADD.

Parameters
id
Returns

Definition at line 653 of file gsds.c.

References ds, get_dataset(), and get_type().

◆ gsds_newh()

int gsds_newh ( const char *  name)

Get handle to gsds.

Parameters
nameraster map name
Returns
-1 on failure
data id

Definition at line 219 of file gsds.c.

References check_numsets(), Cur_id, Data, first, G_store(), init_gsds(), MAXDIMS, name, NULL, and Numsets.

Referenced by GS_load_att_map().

◆ gsds_set_changed()

int gsds_set_changed ( int  id,
IFLAG  reason 
)

ADD.

Parameters
id
reason
Returns
-1 on error

Definition at line 635 of file gsds.c.

References ds, and get_dataset().

Referenced by GS_load_att_map().

◆ init_gsds()

static int init_gsds ( void  )
static

Initialize gsds.

Definition at line 84 of file gsds.c.

References Cur_max, Data, Ds, and MAX_DS.

Referenced by gsds_newh().

Variable Documentation

◆ Cur_id

int Cur_id = 33
static

Definition at line 77 of file gsds.c.

Referenced by gsds_newh().

◆ Cur_max

int Cur_max
static

Definition at line 78 of file gsds.c.

Referenced by check_numsets(), and init_gsds().

◆ Data

◆ Ds

dataset Ds[100]
static

◆ Numsets

int Numsets = 0
static

◆ Tot_mem

size_t Tot_mem = 0
static

Definition at line 79 of file gsds.c.

Referenced by free_data_buffs(), gsds_alloc_typbuff(), Gv_load_vect(), and sub_Vectmem().