Libcroco
cr-term.h
Go to the documentation of this file.
00001 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
00002 
00003 /*
00004  * This file is part of The Croco Library
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of version 2.1 of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00018  * USA
00019  * 
00020  * Author: Dodji Seketeli
00021  * See COPYRIGHTS file for copyright information.
00022  */
00023 
00024 #include <stdio.h>
00025 #include <glib.h>
00026 #include "cr-utils.h"
00027 #include "cr-rgb.h"
00028 #include "cr-num.h"
00029 #include "cr-string.h"
00030 
00031 #ifndef __CR_TERM_H__
00032 #define __CR_TERM_H__
00033 
00034 G_BEGIN_DECLS
00035 
00036 /**
00037  *@file
00038  *Declaration of the #CRTem class.
00039  */
00040 
00041 enum CRTermType
00042 {
00043         TERM_NO_TYPE = 0,
00044         TERM_NUMBER,
00045         TERM_FUNCTION,
00046         TERM_STRING,
00047         TERM_IDENT,
00048         TERM_URI,
00049         TERM_RGB,
00050         TERM_UNICODERANGE,
00051         TERM_HASH
00052 } ;
00053 
00054 
00055 enum UnaryOperator
00056 {
00057         NO_UNARY_UOP = 0,
00058         PLUS_UOP,
00059         MINUS_UOP,
00060         EMPTY_UNARY_UOP
00061 } ;
00062 
00063 enum Operator
00064 {
00065         NO_OP = 0,
00066         DIVIDE,
00067         COMMA           
00068 } ;
00069 
00070 struct _CRTerm ;
00071 typedef struct _CRTerm CRTerm ;
00072 
00073 /**
00074  *An abstraction of a css2 term as
00075  *defined in the CSS2 spec in appendix D.1:
00076  *term ::=
00077  *[ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* 
00078  *| ANGLE S* | TIME S* | FREQ S* | function ]
00079  * | STRING S* | IDENT S* | URI S* | RGB S* 
00080  *| UNICODERANGE S* | hexcolor
00081  */
00082 struct _CRTerm
00083 {
00084         /**
00085          *The type of the term.
00086          */
00087         enum CRTermType type ;
00088                 
00089         /**
00090          *The unary operator associated to
00091          *the current term.
00092          */
00093         enum UnaryOperator unary_op ;
00094 
00095         /**
00096          *The operator associated to the current term.
00097          */
00098         enum Operator the_operator ;
00099 
00100 
00101         /**
00102          *The content of the term.
00103          *Depending of the type of the term,
00104          *this holds either a number, a percentage ...
00105          */
00106         union
00107         {
00108                 CRNum *num ;
00109                 CRString * str ;
00110                 CRRgb * rgb ;
00111         } content ;
00112 
00113         /**
00114          *If the term is of type UNICODERANGE, 
00115          *this field holds the upper bound of the range.
00116          *if the term is of type FUNCTION, this holds
00117          *an instance of CRTerm that represents
00118          * the expression which is the argument of the function.
00119          */
00120         union
00121         {
00122                 CRTerm *func_param ;                        
00123         } ext_content ;
00124 
00125         /**
00126          *A spare pointer, just in case.
00127          *Can be used by the application.
00128          */
00129         gpointer app_data ;
00130 
00131         glong ref_count ;
00132 
00133         /**
00134          *A pointer to the next term, 
00135          *just in case this term is part of
00136          *an expression.
00137          */
00138         CRTerm *next ;
00139 
00140         /**
00141          *A pointer to the previous
00142          *term.
00143          */
00144         CRTerm *prev ;
00145         CRParsingLocation location ;
00146 } ;
00147 
00148 CRTerm * cr_term_parse_expression_from_buf (const guchar *a_buf, 
00149                                             enum CREncoding a_encoding) ;
00150 CRTerm * cr_term_new (void) ;
00151 
00152 enum CRStatus cr_term_set_number (CRTerm *a_this, CRNum *a_num) ;
00153         
00154 enum CRStatus cr_term_set_function (CRTerm *a_this, 
00155                                     CRString *a_func_name,
00156                                     CRTerm *a_func_param) ;
00157 
00158 enum CRStatus cr_term_set_string (CRTerm *a_this, CRString *a_str) ;
00159 
00160 enum CRStatus cr_term_set_ident (CRTerm *a_this, CRString *a_str) ;
00161 
00162 enum CRStatus cr_term_set_uri (CRTerm *a_this, CRString *a_str) ;
00163         
00164 enum CRStatus cr_term_set_rgb (CRTerm *a_this, CRRgb *a_rgb) ;
00165         
00166 enum CRStatus cr_term_set_hash (CRTerm *a_this, CRString *a_str) ;
00167         
00168 CRTerm * cr_term_append_term (CRTerm *a_this, CRTerm *a_new_term) ;
00169 
00170 CRTerm * cr_term_prepend_term (CRTerm *a_this, CRTerm *a_new_term) ;
00171 
00172 guchar * cr_term_to_string (CRTerm const *a_this) ;
00173 
00174 guchar * cr_term_one_to_string (CRTerm const * a_this) ;
00175 
00176 void cr_term_dump (CRTerm const *a_this, FILE *a_fp) ;
00177 
00178 int cr_term_nr_values (CRTerm const *a_this) ;
00179 
00180 CRTerm * cr_term_get_from_list (CRTerm *a_this, int itemnr) ;
00181 
00182 void cr_term_ref (CRTerm *a_this) ;
00183 
00184 gboolean cr_term_unref (CRTerm *a_this) ;
00185 
00186 void cr_term_destroy (CRTerm * a_term) ;
00187 
00188 G_END_DECLS
00189 
00190 #endif /*__CR_TERM_H__*/