GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vector/Vlib/cats.c File Reference
#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/Vect.h>
#include <grass/glocale.h>
Include dependency graph for vector/Vlib/cats.c:

Go to the source code of this file.

Functions

struct line_cats * Vect__new_cats_struct ()
 Creates and initializes line_cats structure (lower level fn) More...
 
struct line_cats * Vect_new_cats_struct ()
 Creates and initializes line_cats structure. More...
 
int Vect_destroy_cats_struct (struct line_cats *p)
 Frees all memory associated with line_cats structure, including the struct itself. More...
 
int Vect_cat_set (struct line_cats *Cats, int field, int cat)
 Add new field/cat to category structure if doesn't exist yet. More...
 
int Vect_cat_get (struct line_cats *Cats, int field, int *cat)
 Get first found category of given field. More...
 
int Vect_field_cat_get (struct line_cats *Cats, int field, struct ilist *cats)
 Get list of categories of given field. More...
 
int Vect_cat_del (struct line_cats *Cats, int field)
 Delete all categories of given layer. More...
 
int Vect_field_cat_del (struct line_cats *Cats, int field, int cat)
 Delete field/cat from line_cats structure. More...
 
int Vect_reset_cats (struct line_cats *Cats)
 Reset category structure to make sure cats structure is clean to be re-used. More...
 
struct cat_list * Vect_new_cat_list ()
 Allocate memory for cat_list structure. More...
 
int Vect_destroy_cat_list (struct cat_list *p)
 Frees allocated cat_list memory. More...
 
int Vect_str_to_cat_list (const char *str, struct cat_list *list)
 Convert string of categories and cat ranges separated by commas to cat_list. More...
 
int Vect_array_to_cat_list (int *vals, int nvals, struct cat_list *list)
 Convert ordered array of integers to cat_list structure. More...
 
int Vect_cat_in_cat_list (int cat, struct cat_list *list)
 Check if category number is in list. More...
 
int Vect_cat_in_array (int cat, int *array, int ncats)
 Check if category is in ordered array of integers. More...
 

Function Documentation

struct line_cats * Vect__new_cats_struct ( )

Creates and initializes line_cats structure (lower level fn)

This structure is used for reading and writing vector cats. The library routines handle all memory allocation.

Returns
struct line_cats *

Definition at line 60 of file vector/Vlib/cats.c.

Referenced by Vect_new_cats_struct().

int Vect_array_to_cat_list ( int vals,
int  nvals,
struct cat_list *  list 
)

Convert ordered array of integers to cat_list structure.

Parameters
[in]valsarray of integers
[in]nvalsnumber of values
[out]listresult cat_list structure
Returns
number of ranges

Definition at line 435 of file vector/Vlib/cats.c.

References G_debug(), int, and tools::range.

int Vect_cat_del ( struct line_cats *  Cats,
int  field 
)

Delete all categories of given layer.

Parameters
[in]Catsline_cats structure
[in]fieldlayer number
Returns
1 deleted
0 layer does not exist

Definition at line 223 of file vector/Vlib/cats.c.

References n.

Referenced by wxdigit.IVDigit::DeleteSelectedLines().

int Vect_cat_get ( struct line_cats *  Cats,
int  field,
int cat 
)

Get first found category of given field.

'cat' is set to first category found or -1 if field was not found

Parameters
[in]Catsline_cats structure
[in]fieldlayer number
[in]catpointer to variable where cat will be written
Returns
1 found
0 layer does not exist

Definition at line 159 of file vector/Vlib/cats.c.

References n.

Referenced by G_site_get(), IL_vector_input_data_2d(), NetA_get_node_costs(), NetA_initialise_varray(), Vect_get_line_cat(), Vect_net_build_graph(), and Vect_set_varray_from_cat_list().

int Vect_cat_in_array ( int  cat,
int array,
int  ncats 
)

Check if category is in ordered array of integers.

Parameters
[in]catcategory number
[in]arrayordered array of integers
[in]ncatsnumber of categories in array
Returns
TRUE if cat is in list
FALSE if it is not

Definition at line 496 of file vector/Vlib/cats.c.

References FALSE, NULL, and TRUE.

int Vect_cat_in_cat_list ( int  cat,
struct cat_list *  list 
)

Check if category number is in list.

Parameters
[in]catcategory number
[in]listcat_list structure
Returns
TRUE if cat is in list
FALSE if it is not

Definition at line 475 of file vector/Vlib/cats.c.

References FALSE, max, and TRUE.

Referenced by Vect_set_varray_from_cat_list().

int Vect_cat_set ( struct line_cats *  Cats,
int  field,
int  cat 
)

Add new field/cat to category structure if doesn't exist yet.

Parameters
[in]Catsline_cats structure
[in]fieldlayer number
[in]catcategory number
Returns
number of categories
0 if no space for new category in structure, n_cats would be > GV_NCATS_MAX
-1 on out of memory
-2 if field out of range: 1 - GV_FIELD_MAX or cat out of range: 1 - GV_CAT_MAX

Definition at line 108 of file vector/Vlib/cats.c.

References cat, dig_alloc_cats(), G_fatal_error(), and n.

Referenced by wxdigit.IVDigit::CopyCats(), wxdigit.IVDigit::DeleteSelectedLines(), G_site_put(), IL_check_at_points_2d(), wxdigit.IVDigit::InitCats(), wxdigit.IVDigit::SetLineCats(), V1_read_next_line_ogr(), V2_read_line_ogr(), Vect_clean_small_angles_at_nodes(), Vect_overlay_and(), Vect_remove_duplicates(), and Vedit_modify_cats().

int Vect_destroy_cat_list ( struct cat_list *  p)

Frees allocated cat_list memory.

Parameters
[in]pline_cats structure
Returns
0

Definition at line 334 of file vector/Vlib/cats.c.

References G_free().

Referenced by Vect_set_varray_from_cat_string().

int Vect_field_cat_del ( struct line_cats *  Cats,
int  field,
int  cat 
)

Delete field/cat from line_cats structure.

Parameters
[in]Catsline_cats structure
[in]fieldlayer number
[in]catcategory to be deleted or -1 to delete all cats of given field
Returns
1 deleted
0 field/category number does not exist

Definition at line 259 of file vector/Vlib/cats.c.

References n.

Referenced by wxdigit.IVDigit::SetLineCats(), and Vedit_modify_cats().

int Vect_field_cat_get ( struct line_cats *  Cats,
int  field,
struct ilist *  cats 
)

Get list of categories of given field.

Parameters
Catsline_cats structure
fieldlayer number
[out]catspointer to list where cats will be written
Returns
number of found categories
-1 on invalid field

Definition at line 193 of file vector/Vlib/cats.c.

References n, Vect_list_append(), and Vect_reset_list().

struct cat_list* Vect_new_cat_list ( )

Allocate memory for cat_list structure.

Returns
poiter to allocated structure
NULL on out of memory

Definition at line 308 of file vector/Vlib/cats.c.

References NULL.

Referenced by Vect_set_varray_from_cat_string().

int Vect_reset_cats ( struct line_cats *  Cats)

Reset category structure to make sure cats structure is clean to be re-used.

I.e. it has no cats associated with it. Cats must have previously been created with Vect_new_cats_struct()

Parameters
[out]Catsline_cats structure
Returns
0

Definition at line 295 of file vector/Vlib/cats.c.

Referenced by G_site_put(), IL_check_at_points_2d(), wxdigit.IVDigit::InitCats(), V1_read_next_line_ogr(), V2_read_line_ogr(), Vect_break_polygons(), Vect_clean_small_angles_at_nodes(), Vect_get_area_cat(), Vect_get_area_cats(), and Vect_overlay_and().

int Vect_str_to_cat_list ( const char *  str,
struct cat_list *  list 
)

Convert string of categories and cat ranges separated by commas to cat_list.

Examples of string: 2,3,5-9,20. str - input string

Parameters
[in]strcat list string
[out]listresult cat_list structure
Returns
number of errors in ranges

Definition at line 358 of file vector/Vlib/cats.c.

References buf, err, G_debug(), G_warning(), int, l, max, min, NULL, and dialogs::s.

Referenced by Vect_set_varray_from_cat_string().