ddc
lex_token.h
Go to the documentation of this file.
1 /*
2 www.sourceforge.net/projects/tinyxpath
3 Copyright (c) 2002-2004 Yves Berquin (yvesb@users.sourceforge.net)
4 
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any
7 damages arising from the use of this software.
8 
9 Permission is granted to anyone to use this software for any
10 purpose, including commercial applications, and to alter it and
11 redistribute it freely, subject to the following restrictions:
12 
13 1. The origin of this software must not be misrepresented; you must
14 not claim that you wrote the original software. If you use this
15 software in a product, an acknowledgment in the product documentation
16 would be appreciated but is not required.
17 
18 2. Altered source versions must be plainly marked as such, and
19 must not be misrepresented as being the original software.
20 
21 3. This notice may not be removed or altered from any source
22 distribution.
23 */
24 #ifndef __TINYLEXTOKEN_H
25 #define __TINYLEXTOKEN_H
26 
27 #include <stdio.h>
28 #include <string.h>
29 
30 #include "lex_util.h"
31 
32 namespace TinyXPath
33 {
34 
38 class lex_token
39 {
41  char * cp_value;
46 public :
48  lex_token (lexico l_in_enum, const _byte_ * bp_in_value, unsigned u_in_size)
49  {
50  l_enum = l_in_enum;
51  cp_value = new char [u_in_size + 1];
52  if (u_in_size)
53  memcpy (cp_value, bp_in_value, u_in_size);
54  cp_value [u_in_size] = 0;
55  ltp_next = NULL;
56  ltp_prev = NULL;
57  }
59  void v_set_next (lex_token * ltp_in_next)
60  {
61  ltp_next = ltp_in_next;
62  }
64  void v_set_prev (lex_token * ltp_in_prev)
65  {
66  ltp_prev = ltp_in_prev;
67  }
70  {
71  if (cp_value)
72  delete [] cp_value;
73  }
74 
77  {
78  return ltp_next;
79  }
80 
83  {
84  return ltp_prev;
85  }
86 
88  lex_token * ltp_get_next (int i_nb)
89  {
90  lex_token * ltp_ret;
91  int i;
92 
93  ltp_ret = this;
94  for (i = 0; i < i_nb; i++)
95  {
96  if (! ltp_ret)
97  return NULL;
98  ltp_ret = ltp_ret -> ltp_get_next ();
99  if (! ltp_ret || ! ltp_ret -> o_is_valid ())
100  return NULL;
101  }
102  return ltp_ret;
103  }
104 
107  {
108  return l_enum;
109  }
110 
112  void v_set (lexico lex_in, const char * cp_repre)
113  {
114  unsigned u_length;
115 
116  l_enum = lex_in;
117  delete [] cp_value;
118  u_length = strlen (cp_repre);
119  cp_value = new char [u_length + 1];
120  strcpy (cp_value, cp_repre);
121  }
122 
124  const char * cp_get_literal ()
125  {
126  return cp_value;
127  }
128 
130  bool o_is_valid () const {return (l_enum != lex_null);}
131 } ;
132 
133 }
134 
135 #endif
136 
137 /*--- emacs style variables ---
138  * Local Variables:
139  * mode: C++
140  * c-file-style: "ellemtel"
141  * c-basic-offset: 4
142  * tab-width: 8
143  * indent-tabs-mode: nil
144  * End:
145  */
lex_token * ltp_prev
Definition: lex_token.h:45
lex_token * ltp_next
pointer to next element
Definition: lex_token.h:45
const char * cp_get_literal()
return the string value of a lexical element
Definition: lex_token.h:124
Definition: action_store.cpp:32
void v_set(lexico lex_in, const char *cp_repre)
Set the string value of a lexical element.
Definition: lex_token.h:112
lex_token * ltp_get_prev() const
get next in list
Definition: lex_token.h:82
Definition: lex_util.h:50
char * cp_value
Representation.
Definition: lex_token.h:41
unsigned char _byte_
Definition: lex_util.h:44
Definition: lex_token.h:38
~ lex_token()
destructor. doesn&#39;t destroys next in list
Definition: lex_token.h:69
lexico
Lexical XPath elements.
Definition: lex_util.h:47
lex_token(lexico l_in_enum, const _byte_ *bp_in_value, unsigned u_in_size)
constructor
Definition: lex_token.h:48
lexico l_enum
lexical value
Definition: lex_token.h:43
lexico lex_get_value() const
return the value of a lexical element
Definition: lex_token.h:106
void v_set_next(lex_token *ltp_in_next)
set the next element in list
Definition: lex_token.h:59
void v_set_prev(lex_token *ltp_in_prev)
set the previous element in list
Definition: lex_token.h:64
lex_token * ltp_get_next(int i_nb)
Return the next i-th element in the list.
Definition: lex_token.h:88
bool o_is_valid() const
check if the lexical element is valid
Definition: lex_token.h:130
lex_token * ltp_get_next() const
get next in list
Definition: lex_token.h:76