Skip to content

Commit

Permalink
appmodel: add Transformation objects
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed May 16, 2024
1 parent 462fa33 commit 8ede165
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/appmodel/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ modules_appmodel_libappmodel_la_SOURCES = \
modules/appmodel/app-parser-generator.h \
modules/appmodel/application.c \
modules/appmodel/application.h \
modules/appmodel/transformation.c \
modules/appmodel/transformation.h \
modules/appmodel/appmodel-grammar.y

modules_appmodel_libappmodel_la_CPPFLAGS = \
Expand Down
92 changes: 92 additions & 0 deletions modules/appmodel/transformation.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2023 Balázs Scheidler <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/

#include "transformation.h"

/* TransformationStep: a named filterx expression */

TransformationStep *
transformation_step_new(const gchar *name, const gchar *expr)
{
TransformationStep *self = g_new0(TransformationStep, 1);
self->name = g_strdup(name);
self->expr = g_strdup(expr);
return self;
}

void
transformation_step_free(TransformationStep *self)
{
g_free(self->name);
g_free(self->expr);
}

/* TransformationBlock: named list of steps */

void
transformation_block_add_step(TransformationBlock *self, const gchar *name, const gchar *expr)
{
self->steps = g_list_append(self->steps, transformation_step_new(name, expr));
}

TransformationBlock *
transformation_block_new(const gchar *name)
{
TransformationBlock *self = g_new0(TransformationBlock, 1);
self->name = g_strdup(name);
return self;
}

void
transformation_block_free(TransformationBlock *self)
{
g_free(self->name);
g_list_free_full(self->steps, (GDestroyNotify) transformation_step_free);
g_free(self);
}

/* Transformation */
/* list of blocks */

void
transformation_add_block(Transformation *self, TransformationBlock *block)
{
self->blocks = g_list_append(self->blocks, block);
}

static void
transformation_free(AppModelObject *s)
{
Transformation *self = (Transformation *) s;

g_list_free_full(self->blocks, (GDestroyNotify) transformation_block_free);
}

Transformation *
transformation_new(const gchar *app, const gchar *flavour)
{
Transformation *self = g_new0(Transformation, 1);

appmodel_object_init_instance(&self->super, TRANSFORMATION_TYPE_NAME, app, flavour);
self->super.free_fn = transformation_free;
return self;
}
59 changes: 59 additions & 0 deletions modules/appmodel/transformation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2023 Balázs Scheidler <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/

#ifndef APPMODEL_TRANSFORMATION_H_INCLUDED
#define APPMODEL_TRANSFORMATION_H_INCLUDED

#include "appmodel-context.h"

#define TRANSFORMATION_TYPE_NAME "transformation"

typedef struct _TransformationStep
{
gchar *name;
gchar *expr;
} TransformationStep;

TransformationStep *transformation_step_new(const gchar *name, const gchar *expr);
void transformation_step_free(TransformationStep *self);


typedef struct _TransformationBlock
{
gchar *name;
GList *steps;
} TransformationBlock;

void transformation_block_add_step(TransformationBlock *self, const gchar *name, const gchar *step);
TransformationBlock *transformation_block_new(const gchar *name);
void transformation_block_free(TransformationBlock *self);

typedef struct _Transformation
{
AppModelObject super;
GList *blocks;
} Transformation;

void transformation_add_block(Transformation *self, TransformationBlock *block);
Transformation *transformation_new(const gchar *app, const gchar *name);

#endif

0 comments on commit 8ede165

Please sign in to comment.