PageRenderTime 50ms CodeModel.GetById 29ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 1ms

/tools/fbusgen/coder.h

http://ftk.googlecode.com/
C++ Header | 172 lines | 118 code | 25 blank | 29 comment | 24 complexity | 8201d1886283a669da01ed1f590bc06c MD5 | raw file
  1/*
  2 * File:    coder.h
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   interface for code generator.
  5 *
  6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
  7 *
  8 * Licensed under the Academic Free License version 2.1
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 23 */
 24
 25/*
 26 * History:
 27 * ================================================================
 28 * 2010-07-31 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31
 32#ifndef CODER_H
 33#define CODER_H
 34
 35#include "glib.h"
 36#include <stdio.h>
 37#include <sys/stat.h>
 38#include <sys/types.h>
 39#include <ctype.h>
 40#include <assert.h>
 41#include <stdlib.h>
 42#include <string.h>
 43#include <libIDL/IDL.h>
 44
 45struct _Coder;
 46typedef struct _Coder Coder;
 47
 48typedef gboolean (*CoderOnInterface)(Coder* thiz, const char* name, const char* parent);
 49typedef gboolean (*CoderOnFunction)(Coder* thiz, struct _IDL_OP_DCL f);
 50typedef gboolean (*CoderOnConst)(Coder* thiz, struct _IDL_CONST_DCL c);
 51typedef gboolean (*CoderOnStruct)(Coder* thiz, struct _IDL_TYPE_STRUCT s);
 52typedef gboolean (*CoderOnEnum)(Coder* thiz, struct _IDL_TYPE_ENUM e);
 53typedef gboolean (*CoderOnUnion)(Coder* thiz, struct _IDL_TYPE_UNION u);
 54typedef void     (*CoderDestroy)(Coder* thiz);
 55
 56struct _Coder
 57{
 58	
 59	CoderOnInterface  on_interface;
 60	CoderOnFunction   on_function;
 61	CoderOnStruct     on_struct;
 62	CoderOnConst      on_const;
 63	CoderOnUnion      on_union;
 64	CoderOnEnum       on_enum;
 65	CoderDestroy      destroy;
 66
 67	char priv[1];
 68};
 69
 70static inline gboolean coder_on_interface(Coder* thiz, const char* name, const char* parent)
 71{
 72	g_return_val_if_fail(thiz != NULL && name != NULL, FALSE);
 73
 74	if(thiz->on_interface != NULL)
 75	{
 76		return thiz->on_interface(thiz, name, parent);
 77	}
 78	else
 79	{
 80		return FALSE;
 81	}
 82}
 83
 84static inline gboolean coder_on_function(Coder* thiz, struct _IDL_OP_DCL f)
 85{
 86	g_return_val_if_fail(thiz != NULL, FALSE);
 87
 88	if(thiz->on_function != NULL)
 89	{
 90		return thiz->on_function(thiz, f);
 91	}
 92	else
 93	{
 94		return FALSE;
 95	}
 96}
 97
 98static inline gboolean coder_on_const(Coder* thiz, struct _IDL_CONST_DCL c)
 99{
100	g_return_val_if_fail(thiz != NULL, FALSE);
101	
102	if(thiz->on_const != NULL)
103	{
104		return thiz->on_const(thiz, c);
105	}
106	else
107	{
108		return FALSE;
109	}
110}
111
112static inline gboolean coder_on_struct(Coder* thiz, struct _IDL_TYPE_STRUCT s)
113{
114	g_return_val_if_fail(thiz != NULL, FALSE);
115	
116	if(thiz->on_struct != NULL)
117	{
118		return thiz->on_struct(thiz, s);
119	}
120	else
121	{
122		return FALSE;
123	}
124}
125
126static inline gboolean coder_on_enum(Coder* thiz, struct _IDL_TYPE_ENUM e)
127{
128	g_return_val_if_fail(thiz != NULL, FALSE);
129	
130	if(thiz->on_enum != NULL)
131	{
132		return thiz->on_enum(thiz, e);
133	}
134	else
135	{
136		return FALSE;
137	}
138}
139
140static inline gboolean coder_on_union(Coder* thiz, struct _IDL_TYPE_UNION u)
141{
142	g_return_val_if_fail(thiz != NULL, FALSE);
143	
144	if(thiz->on_union != NULL)
145	{
146		return thiz->on_union(thiz, u);
147	}
148	else
149	{
150		return FALSE;
151	}
152}
153
154static inline void     coder_destroy(Coder* thiz)
155{
156	if(thiz != NULL && thiz->destroy != NULL)
157	{
158		thiz->destroy(thiz);
159	}
160
161	return;
162}
163
164typedef Coder* (*CoderCreate)(const char* name);
165
166char* coder_name_to_upper(const char* src, char* dst, int skip);
167char* coder_name_to_lower(const char* src, char* dst);
168const char* coder_to_upper(char* src);
169const char* coder_to_lower(char* src);
170void coder_write_header(FILE* fp);
171
172#endif/*CODER_H*/