Libcroco
cr-term.h
Go to the documentation of this file.
1 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
2 
3 /*
4  * This file is part of The Croco Library
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2.1 of the GNU Lesser General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  *
20  * Author: Dodji Seketeli
21  * See COPYRIGHTS file for copyright information.
22  */
23 
24 #include <stdio.h>
25 #include <glib.h>
26 #include "cr-utils.h"
27 #include "cr-rgb.h"
28 #include "cr-num.h"
29 #include "cr-string.h"
30 
31 #ifndef __CR_TERM_H__
32 #define __CR_TERM_H__
33 
34 G_BEGIN_DECLS
35 
36 /**
37  *@file
38  *Declaration of the #CRTem class.
39  */
40 
42 {
52 } ;
53 
54 
56 {
61 } ;
62 
64 {
65  NO_OP = 0,
68 } ;
69 
70 struct _CRTerm ;
71 typedef struct _CRTerm CRTerm ;
72 
73 /**
74  *An abstraction of a css2 term as
75  *defined in the CSS2 spec in appendix D.1:
76  *term ::=
77  *[ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S*
78  *| ANGLE S* | TIME S* | FREQ S* | function ]
79  * | STRING S* | IDENT S* | URI S* | RGB S*
80  *| UNICODERANGE S* | hexcolor
81  */
82 struct _CRTerm
83 {
84  /**
85  *The type of the term.
86  */
88 
89  /**
90  *The unary operator associated to
91  *the current term.
92  */
94 
95  /**
96  *The operator associated to the current term.
97  */
99 
100 
101  /**
102  *The content of the term.
103  *Depending of the type of the term,
104  *this holds either a number, a percentage ...
105  */
106  union
107  {
110  CRRgb * rgb ;
111  } content ;
112 
113  /**
114  *If the term is of type UNICODERANGE,
115  *this field holds the upper bound of the range.
116  *if the term is of type FUNCTION, this holds
117  *an instance of CRTerm that represents
118  * the expression which is the argument of the function.
119  */
120  union
121  {
123  } ext_content ;
124 
125  /**
126  *A spare pointer, just in case.
127  *Can be used by the application.
128  */
129  gpointer app_data ;
130 
131  glong ref_count ;
132 
133  /**
134  *A pointer to the next term,
135  *just in case this term is part of
136  *an expression.
137  */
139 
140  /**
141  *A pointer to the previous
142  *term.
143  */
146 } ;
147 
148 CRTerm * cr_term_parse_expression_from_buf (const guchar *a_buf,
149  enum CREncoding a_encoding) ;
150 CRTerm * cr_term_new (void) ;
151 
152 enum CRStatus cr_term_set_number (CRTerm *a_this, CRNum *a_num) ;
153 
154 enum CRStatus cr_term_set_function (CRTerm *a_this,
155  CRString *a_func_name,
156  CRTerm *a_func_param) ;
157 
158 enum CRStatus cr_term_set_string (CRTerm *a_this, CRString *a_str) ;
159 
160 enum CRStatus cr_term_set_ident (CRTerm *a_this, CRString *a_str) ;
161 
162 enum CRStatus cr_term_set_uri (CRTerm *a_this, CRString *a_str) ;
163 
164 enum CRStatus cr_term_set_rgb (CRTerm *a_this, CRRgb *a_rgb) ;
165 
166 enum CRStatus cr_term_set_hash (CRTerm *a_this, CRString *a_str) ;
167 
168 CRTerm * cr_term_append_term (CRTerm *a_this, CRTerm *a_new_term) ;
169 
170 CRTerm * cr_term_prepend_term (CRTerm *a_this, CRTerm *a_new_term) ;
171 
172 guchar * cr_term_to_string (CRTerm const *a_this) ;
173 
174 guchar * cr_term_one_to_string (CRTerm const * a_this) ;
175 
176 void cr_term_dump (CRTerm const *a_this, FILE *a_fp) ;
177 
178 int cr_term_nr_values (CRTerm const *a_this) ;
179 
180 CRTerm * cr_term_get_from_list (CRTerm *a_this, int itemnr) ;
181 
182 void cr_term_ref (CRTerm *a_this) ;
183 
184 gboolean cr_term_unref (CRTerm *a_this) ;
185 
186 void cr_term_destroy (CRTerm * a_term) ;
187 
188 G_END_DECLS
189 
190 #endif /*__CR_TERM_H__*/
cr_term_set_uri
enum CRStatus cr_term_set_uri(CRTerm *a_this, CRString *a_str)
Definition: cr-term.c:191
TERM_FUNCTION
@ TERM_FUNCTION
Definition: cr-term.h:45
TERM_STRING
@ TERM_STRING
Definition: cr-term.h:46
_CRTerm::the_operator
enum Operator the_operator
The operator associated to the current term.
Definition: cr-term.h:98
COMMA
@ COMMA
Definition: cr-term.h:67
TERM_RGB
@ TERM_RGB
Definition: cr-term.h:49
_CRTerm::type
enum CRTermType type
The type of the term.
Definition: cr-term.h:87
CRTermType
CRTermType
Definition: cr-term.h:41
cr_term_append_term
CRTerm * cr_term_append_term(CRTerm *a_this, CRTerm *a_new_term)
Appends a new term to the current list of CRTerm.
Definition: cr-term.c:235
UnaryOperator
UnaryOperator
Definition: cr-term.h:55
_CRTerm::str
CRString * str
Definition: cr-term.h:109
cr_term_set_number
enum CRStatus cr_term_set_number(CRTerm *a_this, CRNum *a_num)
Definition: cr-term.c:141
cr_term_get_from_list
CRTerm * cr_term_get_from_list(CRTerm *a_this, int itemnr)
Use an index to get a CRTerm from the expression.
Definition: cr-term.c:719
PLUS_UOP
@ PLUS_UOP
Definition: cr-term.h:58
TERM_IDENT
@ TERM_IDENT
Definition: cr-term.h:47
NO_UNARY_UOP
@ NO_UNARY_UOP
Definition: cr-term.h:57
cr_term_set_ident
enum CRStatus cr_term_set_ident(CRTerm *a_this, CRString *a_str)
Definition: cr-term.c:179
cr_term_set_string
enum CRStatus cr_term_set_string(CRTerm *a_this, CRString *a_str)
Definition: cr-term.c:167
CRString
typedefG_BEGIN_DECLS struct _CRString CRString
Definition: cr-string.h:37
EMPTY_UNARY_UOP
@ EMPTY_UNARY_UOP
Definition: cr-term.h:60
_CRTerm::ref_count
glong ref_count
Definition: cr-term.h:131
_CRTerm::location
CRParsingLocation location
Definition: cr-term.h:145
_CRNum
An abstraction of a number (num) as defined in the css2 spec.
Definition: cr-num.h:90
cr-string.h
_CRTerm::ext_content
union _CRTerm::@3 ext_content
If the term is of type UNICODERANGE, this field holds the upper bound of the range.
cr_term_prepend_term
CRTerm * cr_term_prepend_term(CRTerm *a_this, CRTerm *a_new_term)
Prepends a term to the list of terms represented by a_this.
Definition: cr-term.c:261
_CRTerm::next
CRTerm * next
A pointer to the next term, just in case this term is part of an expression.
Definition: cr-term.h:138
cr_term_set_hash
enum CRStatus cr_term_set_hash(CRTerm *a_this, CRString *a_str)
Definition: cr-term.c:215
_CRParsingLocation
Definition: cr-parsing-location.h:39
DIVIDE
@ DIVIDE
Definition: cr-term.h:66
cr_term_one_to_string
guchar * cr_term_one_to_string(CRTerm const *a_this)
Definition: cr-term.c:475
cr-num.h
_CRTerm::unary_op
enum UnaryOperator unary_op
The unary operator associated to the current term.
Definition: cr-term.h:93
TERM_HASH
@ TERM_HASH
Definition: cr-term.h:51
NO_OP
@ NO_OP
Definition: cr-term.h:65
Operator
Operator
Definition: cr-term.h:63
TERM_NO_TYPE
@ TERM_NO_TYPE
Definition: cr-term.h:43
TERM_URI
@ TERM_URI
Definition: cr-term.h:48
CRRgb
typedefG_BEGIN_DECLS struct _CRRgb CRRgb
Definition: cr-rgb.h:34
_CRTerm::app_data
gpointer app_data
A spare pointer, just in case.
Definition: cr-term.h:129
cr_term_ref
void cr_term_ref(CRTerm *a_this)
Increments the reference counter of the current instance of CRTerm.
Definition: cr-term.c:738
cr_term_unref
gboolean cr_term_unref(CRTerm *a_this)
Decrements the ref count of the current instance of CRTerm.
Definition: cr-term.c:753
CREncoding
CREncoding
Encoding values.
Definition: cr-utils.h:84
cr_term_dump
void cr_term_dump(CRTerm const *a_this, FILE *a_fp)
Dumps the expression (a list of terms connected by operators) to a file.
Definition: cr-term.c:679
cr_term_set_rgb
enum CRStatus cr_term_set_rgb(CRTerm *a_this, CRRgb *a_rgb)
Definition: cr-term.c:203
_CRTerm::num
CRNum * num
Definition: cr-term.h:108
_CRTerm
An abstraction of a css2 term as defined in the CSS2 spec in appendix D.1: term ::= [ NUMBER S* | PER...
Definition: cr-term.h:82
_CRTerm::func_param
CRTerm * func_param
Definition: cr-term.h:122
_CRTerm::content
union _CRTerm::@2 content
The content of the term.
CRStatus
CRStatus
The status type returned by the methods of the croco library.
Definition: cr-utils.h:43
MINUS_UOP
@ MINUS_UOP
Definition: cr-term.h:59
cr-utils.h
TERM_NUMBER
@ TERM_NUMBER
Definition: cr-term.h:44
cr_term_new
CRTerm * cr_term_new(void)
Instanciate a CRTerm.
Definition: cr-term.c:85
cr_term_nr_values
int cr_term_nr_values(CRTerm const *a_this)
Return the number of terms in the expression.
Definition: cr-term.c:699
_CRTerm::rgb
CRRgb * rgb
Definition: cr-term.h:110
_CRTerm::prev
CRTerm * prev
A pointer to the previous term.
Definition: cr-term.h:144
TERM_UNICODERANGE
@ TERM_UNICODERANGE
Definition: cr-term.h:50
cr_term_parse_expression_from_buf
CRTerm * cr_term_parse_expression_from_buf(const guchar *a_buf, enum CREncoding a_encoding)
Parses an expresion as defined by the css2 spec and builds the expression as a list of terms.
Definition: cr-term.c:106
cr_term_set_function
enum CRStatus cr_term_set_function(CRTerm *a_this, CRString *a_func_name, CRTerm *a_func_param)
Definition: cr-term.c:153
cr-rgb.h
cr_term_destroy
void cr_term_destroy(CRTerm *a_term)
The destructor of the the CRTerm class.
Definition: cr-term.c:775
cr_term_to_string
guchar * cr_term_to_string(CRTerm const *a_this)
Serializes the expression represented by the chained instances of #CRterm.
Definition: cr-term.c:279