[GRASS-SVN] r49419 - in grass/trunk: include/defs lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Nov 29 06:05:53 EST 2011


Author: martinl
Date: 2011-11-29 03:05:53 -0800 (Tue, 29 Nov 2011)
New Revision: 49419

Added:
   grass/trunk/lib/vector/Vlib/handler.c
Modified:
   grass/trunk/include/defs/vector.h
Log:
vlib: Vect_set_error_handler_io() added


Modified: grass/trunk/include/defs/vector.h
===================================================================
--- grass/trunk/include/defs/vector.h	2011-11-29 10:01:37 UTC (rev 49418)
+++ grass/trunk/include/defs/vector.h	2011-11-29 11:05:53 UTC (rev 49419)
@@ -232,6 +232,7 @@
 void  Vect_remove_constraints(struct Map_info *);
 int Vect_rewind(struct Map_info *);
 int Vect_close(struct Map_info *);
+void Vect_set_error_handler_io(struct Map_info *, struct Map_info *);
 
 /* Read/write lines, nodes, areas */
 /* Level 1 and 2 */

Added: grass/trunk/lib/vector/Vlib/handler.c
===================================================================
--- grass/trunk/lib/vector/Vlib/handler.c	                        (rev 0)
+++ grass/trunk/lib/vector/Vlib/handler.c	2011-11-29 11:05:53 UTC (rev 49419)
@@ -0,0 +1,63 @@
+/*!
+  \file lib/vector/Vlib/handler.c
+
+  \brief Vector library - standard error handlers
+
+  Higher level functions for reading/writing/manipulating vectors.
+  
+  (C) 2011 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 Martin Landa <landa.martin gmail.com>
+*/
+
+#include <grass/gis.h>
+#include <grass/vector.h>
+
+struct handler_data_io {
+    struct Map_info *In;
+    struct Map_info *Out;
+};
+
+static struct handler_data_io *handler_io;
+
+static void error_handler_io(void *p)
+{
+    const char *name;
+    struct Map_info *In, *Out;
+    
+    In  = handler_io->In;
+    Out = handler_io->Out;
+    
+    if (In && In->open == VECT_OPEN_CODE)
+	Vect_close(In);
+    
+    if (Out && Out->open == VECT_OPEN_CODE) {
+	name = G_store(Out->name);
+	Vect_close(Out);
+	Vect_delete(name);
+    }
+}
+
+/*!
+  \brief Define standard error handler for input and output vector maps
+
+  This handler:
+   - close input vector map on error
+   - close and delete output vector map on error
+   
+   \param In  pointer in Map_info struct (input vector map) or NULL
+   \param Out pointer to Map_info struct (output vector map) or NULL
+*/
+void Vect_set_error_handler_io(struct Map_info *In, struct Map_info *Out)
+{
+    if (!handler_io)
+	handler_io = G_malloc(sizeof(struct handler_data_io));
+    
+    handler_io->In  = In;
+    handler_io->Out = Out;
+    
+    G_add_error_handler(error_handler_io, handler_io);
+}


Property changes on: grass/trunk/lib/vector/Vlib/handler.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:eol-style
   + native



More information about the grass-commit mailing list