Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.colors.out: added parson wrapper #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/Make/Docs.make
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ docs_dirs = \
lib/raster3d \
lib/gis \
lib/gmath \
lib/gparson \
lib/gpde \
lib/proj \
lib/ogsf \
Expand Down
2 changes: 2 additions & 0 deletions include/Make/Grass.make
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ libs = \
RASTER3D:g3d \
GIS:gis \
GMATH:gmath \
GPARSON:gparson \
GPDE:gpde \
GPROJ:gproj \
GRAPH:dgl \
Expand Down Expand Up @@ -199,6 +200,7 @@ FORMDEPS = $(DBMILIB) $(GISLIB)
RASTER3DDEPS = $(RASTERLIB) $(GISLIB)
GISDEPS = $(DATETIMELIB) $(ZLIBLIBPATH) $(ZLIB) $(BZIP2LIBPATH) $(BZIP2LIB) $(ZSTDLIBPATH) $(ZSTDLIB) $(INTLLIB) $(REGEXLIBPATH) $(REGEXLIB) $(ICONVLIB) $(PTHREADLIBPATH) $(PTHREADLIB) $(MATHLIB)
GMATHDEPS = $(GISLIB) $(FFTWLIB) $(LAPACKLIB) $(BLASLIB) $(CCMATHLIB) $(OPENMP_CFLAGS) $(OPENMP_LIBPATH) $(OPENMP_LIB)
GPARSONDEPS = $(PARSONLIB)
GPDEDEPS = $(RASTER3DLIB) $(RASTERLIB) $(GISLIB) $(GMATHLIB) $(OPENMP_LIBPATH) $(OPENMP_LIB) $(MATHLIB)
GPROJDEPS = $(GISLIB) $(GDALLIBS) $(PROJLIB) $(MATHLIB)
HTMLDRIVERDEPS = $(DRIVERLIB) $(GISLIB) $(MATHLIB)
Expand Down
52 changes: 52 additions & 0 deletions include/grass/defs/gparson.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef GRASS_GPARSONDEFS_H
#define GRASS_GPARSONDEFS_H

#include <grass/parson.h>

/* *************************************************************** */
/* ***** WRAPPER FOR PARSON FUNCTIONS USED IN GRASS ************** */
/* *************************************************************** */

/* Serialization Functions */
extern char *G_json_serialize_to_string_pretty(const JSON_Value *);
extern void G_json_free_serialized_string(char *);

/* JSON Value Creation and Freeing */
extern JSON_Value *G_json_value_init_object(void);
extern JSON_Value *G_json_value_init_array(void);
extern void G_json_value_free(JSON_Value *);

/* JSON Object Access Functions */
extern JSON_Object *G_json_value_get_object(const JSON_Value *);
extern JSON_Object *G_json_object(const JSON_Value *);
extern JSON_Object *G_json_object_get_object(const JSON_Object *, const char *);
extern JSON_Array *G_json_object_get_array(const JSON_Object *, const char *);
extern JSON_Value *G_json_object_get_value(const JSON_Object *, const char *);
extern const char *G_json_object_get_string(const JSON_Object *, const char *);
extern double G_json_object_get_number(const JSON_Object *, const char *);
extern int G_json_object_get_boolean(const JSON_Object *, const char *);
extern JSON_Value *G_json_object_get_wrapping_value(const JSON_Object *);

/* JSON Object Modification Functions */
extern JSON_Status G_json_object_set_value(JSON_Object *, const char *,
JSON_Value *);
extern JSON_Status G_json_object_set_string(JSON_Object *, const char *,
const char *);
extern JSON_Status G_json_object_set_number(JSON_Object *, const char *,
double);
extern JSON_Status G_json_object_set_boolean(JSON_Object *, const char *, int);
extern JSON_Status G_json_object_set_null(JSON_Object *, const char *);

/* JSON Array Functions */
extern JSON_Array *G_json_array(const JSON_Value *);
extern JSON_Value *G_json_array_get_value(const JSON_Array *, size_t);
extern const char *G_json_array_get_string(const JSON_Array *, size_t);
extern double G_json_array_get_number(const JSON_Array *, size_t);
extern int G_json_array_get_boolean(const JSON_Array *, size_t);
extern JSON_Status G_json_array_append_value(JSON_Array *, JSON_Value *);
extern JSON_Status G_json_array_append_string(JSON_Array *, const char *);
extern JSON_Status G_json_array_append_number(JSON_Array *, double);
extern JSON_Status G_json_array_append_boolean(JSON_Array *, int);
extern JSON_Status G_json_array_append_null(JSON_Array *);

#endif /* GRASS_GPARSONDEFS_H */
23 changes: 23 additions & 0 deletions include/grass/gparson.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/******************************************************************************
* gparson.h
* Top level header file for gparson units

* This file is part of GRASS GIS. It is free software. You can
* redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.

******************************************************************************/

#ifndef GRASS_GPARSON_H
#define GRASS_GPARSON_H

#include <grass/defs/gparson.h>

#endif /* GRASS_GPARSON_H */
1 change: 1 addition & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SUBDIRS = \
proj \
raster \
gmath \
gparson \
linkm \
driver \
pngdriver \
Expand Down
11 changes: 11 additions & 0 deletions lib/gparson/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MODULE_TOPDIR = ../..

LIB = GPARSON

include $(MODULE_TOPDIR)/include/Make/Lib.make
include $(MODULE_TOPDIR)/include/Make/Doxygen.make

default: lib

#doxygen:
DOXNAME=gparson
177 changes: 177 additions & 0 deletions lib/gparson/parson_grass_wrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*****************************************************************************
*
* MODULE: Grass json output interface
*
* PURPOSE: parson library function wrapper
* part of the gparson library
*
* COPYRIGHT: (C) 2010 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.
*
*****************************************************************************/

#if defined(HAVE_PARSON)
#include <parson.h>
#else
#include <grass/parson.h>
#endif

/* *************************************************************** */
/* ***** WRAPPER FOR PARSON FUNCTIONS USED IN GRASS ************** */
/* *************************************************************** */

/* Serialization Functions */
char *G_json_serialize_to_string_pretty(const JSON_Value *value)
{
return json_serialize_to_string_pretty(value);
}

void G_json_free_serialized_string(char *string)
{
json_free_serialized_string(string);
}

/* JSON Object Access Functions */
JSON_Value *G_json_object_get_value(const JSON_Object *object, const char *name)
{
return json_object_get_value(object, name);
}

const char *G_json_object_get_string(const JSON_Object *object,
const char *name)
{
return json_object_get_string(object, name);
}

JSON_Object *G_json_object_get_object(const JSON_Object *object,
const char *name)
{
return json_object_get_object(object, name);
}

JSON_Array *G_json_object_get_array(const JSON_Object *object, const char *name)
{
return json_object_get_array(object, name);
}

double G_json_object_get_number(const JSON_Object *object, const char *name)
{
return json_object_get_number(object, name);
}

int G_json_object_get_boolean(const JSON_Object *object, const char *name)
{
return json_object_get_boolean(object, name);
}

JSON_Value *G_json_object_get_wrapping_value(const JSON_Object *object)
{
return json_object_get_wrapping_value(object);
}

/* JSON Object Modification Functions */
JSON_Status G_json_object_set_value(JSON_Object *object, const char *name,
JSON_Value *value)
{
return json_object_set_value(object, name, value);
}

JSON_Status G_json_object_set_string(JSON_Object *object, const char *name,
const char *string)
{
return json_object_set_string(object, name, string);
}

JSON_Status G_json_object_set_number(JSON_Object *object, const char *name,
double number)
{
return json_object_set_number(object, name, number);
}

JSON_Status G_json_object_set_boolean(JSON_Object *object, const char *name,
int boolean)
{
return json_object_set_boolean(object, name, boolean);
}

JSON_Status G_json_object_set_null(JSON_Object *object, const char *name)
{
return json_object_set_null(object, name);
}

/* JSON Array Functions */
JSON_Status G_json_array_append_value(JSON_Array *array, JSON_Value *value)
{
return json_array_append_value(array, value);
}

JSON_Status G_json_array_append_string(JSON_Array *array, const char *string)
{
return json_array_append_string(array, string);
}

JSON_Status G_json_array_append_number(JSON_Array *array, double number)
{
return json_array_append_number(array, number);
}

JSON_Status G_json_array_append_boolean(JSON_Array *array, int boolean)
{
return json_array_append_boolean(array, boolean);
}

JSON_Status G_json_array_append_null(JSON_Array *array)
{
return json_array_append_null(array);
}

/* JSON Value Creation and Freeing */
JSON_Value *G_json_value_init_object(void)
{
return json_value_init_object();
}

JSON_Object *G_json_value_get_object(const JSON_Value *value)
{
return json_value_get_object(value);
}

JSON_Object *G_json_object(const JSON_Value *value)
{
return json_object(value);
}

JSON_Array *G_json_array(const JSON_Value *value)
{
return json_array(value);
}

JSON_Value *G_json_array_get_value(const JSON_Array *array, size_t index)
{
return json_array_get_value(array, index);
}
const char *G_json_array_get_string(const JSON_Array *array, size_t index)
{
return json_array_get_string(array, index);
}
double G_json_array_get_number(const JSON_Array *array, size_t index)
{
return json_array_get_number(array, index);
}
int G_json_array_get_boolean(const JSON_Array *array, size_t index)
{
return json_array_get_boolean(array, index);
}

JSON_Value *G_json_value_init_array(void)
{
return json_value_init_array();
}

void G_json_value_free(JSON_Value *value)
{
json_value_free(value);
}
10 changes: 10 additions & 0 deletions lib/gparson/test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MODULE_TOPDIR = ../../..

PGM=test.gparson.lib

LIBES = $(PARSONLIB) $(GPARSONLIB) $(GISLIB)
DEPENDENCIES = $(PARSONDEP) $(GPARSONDEP) $(GISDEP)

include $(MODULE_TOPDIR)/include/Make/Module.make

default: cmd
3 changes: 3 additions & 0 deletions lib/gparson/test/test.gparson.lib.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


Take a look at the module command line help for more information.
23 changes: 23 additions & 0 deletions lib/gparson/test/test_gparson_lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*****************************************************************************
*
* MODULE: Grass gparson Library
*
* PURPOSE: Unit tests
*
* COPYRIGHT: (C) 2000 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.
*
*****************************************************************************/

#ifndef _TEST_GPARSON_LIB_H_
#define _TEST_GPARSON_LIB_H_

#include <grass/gparson.h>

/* parson wrapper tests */
int unit_test_parson_wrapper(void);

#endif
55 changes: 55 additions & 0 deletions lib/gparson/test/test_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/****************************************************************************
*
* MODULE: test.gparson.lib
*
*
* PURPOSE: Unit tests for the gparson library
*
* COPYRIGHT: (C) 2007 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.
*
*****************************************************************************/

#include <stdlib.h>
#include <grass/gis.h>
#include <grass/glocale.h>
#include <grass/gparson.h>
#include "test_gparson_lib.h"
#include "grass/gparson.h"

/* ************************************************************************* */

/* ************************************************************************* */
/* ************************************************************************* */

/* ************************************************************************* */
int main(int argc, char *argv[])
{
struct GModule *module;
int returnstat = 0;

/* Initialize GRASS */
G_gisinit(argv[0]);

module = G_define_module();
G_add_keyword(_("gparson"));
G_add_keyword(_("unit test"));
module->description = _("Performs unit tests "
"for the gparson library");

if (G_parser(argc, argv))
exit(EXIT_FAILURE);

/*Run the unit tests */
returnstat += unit_test_parson_wrapper();

if (returnstat != 0)
G_warning("Errors detected while testing the gparson lib");
else
G_message("\n-- gparson lib tests finished successfully --");

return (returnstat);
}
Loading
Loading