GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-602118adcc
vector/Vlib/rewind.c
Go to the documentation of this file.
1 /*!
2  \file lib/vector/Vlib/rewind.c
3 
4  \brief Vector library - rewind data
5 
6  Higher level functions for reading/writing/manipulating vectors.
7 
8  (C) 2001-2009, 2011-2012 by the GRASS Development Team
9 
10  This program is free software under the GNU General Public License
11  (>=v2). Read the file COPYING that comes with GRASS for details.
12 
13  \author Original author CERL, probably Dave Gerdes or Mike Higgins.
14  \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
15  \author Level 3 by Martin Landa <landa.martin gmail.com>
16  */
17 
18 #include <grass/vector.h>
19 #include <grass/glocale.h>
20 
21 static int rew_dummy(struct Map_info *Map UNUSED)
22 {
23  return -1;
24 }
25 
26 #if !defined HAVE_OGR || !defined HAVE_POSTGRES
27 static int format(struct Map_info *Map UNUSED)
28 {
29  G_fatal_error(_("Requested format is not compiled in this version"));
30  return 0;
31 }
32 #endif
33 
34 static int (*Rewind_array[][4])(struct Map_info *) = {
35  {rew_dummy, V1_rewind_nat, V2_rewind_nat, rew_dummy}
36 #ifdef HAVE_OGR
37  ,
38  {rew_dummy, V1_rewind_ogr, V2_rewind_ogr, rew_dummy},
39  {rew_dummy, V1_rewind_ogr, V2_rewind_ogr, rew_dummy}
40 #else
41  ,
42  {rew_dummy, format, format, rew_dummy},
43  {rew_dummy, format, format, rew_dummy}
44 #endif
45 #ifdef HAVE_POSTGRES
46  ,
48 #else
49  ,
50  {rew_dummy, format, format, rew_dummy}
51 #endif
52 };
53 
54 /*!
55  \brief Rewind vector map to cause reads to start at beginning
56 
57  \param Map pointer to Map_info structure
58 
59  \return 0 on success
60  \return -1 on error
61  */
62 int Vect_rewind(struct Map_info *Map)
63 {
64  if (!VECT_OPEN(Map))
65  return -1;
66 
67  G_debug(1, "Vect_Rewind(): name = %s level = %d", Map->name, Map->level);
68 
69  return (*Rewind_array[Map->format][Map->level])(Map);
70 }
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
int V2_rewind_ogr(struct Map_info *)
Rewind vector map (OGR layer) to cause reads to start at beginning on topological level (level 2)
Definition: rewind_ogr.c:61
int V2_rewind_nat(struct Map_info *)
Rewind vector map to cause reads to start at beginning on topological level (level 2) - native format...
Definition: rewind_nat.c:40
int V1_rewind_nat(struct Map_info *)
Rewind vector map to cause reads to start at beginning on non-topological level (level 1) - native fo...
Definition: rewind_nat.c:27
int V1_rewind_pg(struct Map_info *)
Rewind vector map (PostGIS layer) to cause reads to start at beginning (level 1)
Definition: rewind_pg.c:34
int V1_rewind_ogr(struct Map_info *)
Rewind vector map (OGR layer) to cause reads to start at beginning (level 1)
Definition: rewind_ogr.c:32
int V2_rewind_pg(struct Map_info *)
Rewind vector map (PostGIS layer) to cause reads to start at beginning on topological level (level 2)
Definition: rewind_pg.c:70
#define VECT_OPEN(Map)
Check if vector map is open.
Definition: dig_defines.h:137
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
Definition: gis.h:47
#define _(str)
Definition: glocale.h:10
Vector map info.
Definition: dig_structs.h:1243
int level
Topology level.
Definition: dig_structs.h:1297
char * name
Map name (for 4.0)
Definition: dig_structs.h:1316
int format
Map format (native, ogr, postgis)
Definition: dig_structs.h:1255
int Vect_rewind(struct Map_info *Map)
Rewind vector map to cause reads to start at beginning.