Debian Codegraph @

src/tinyxpath/lex_token.h

raw symbols SCIP
1 /*
2 www.sourceforge.net/projects/tinyxpath
3 Copyright (c) 2002-2004 Yves Berquin ([email protected])
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 <cstdio>
28 #include <string>
29 #include <cstring> // Added by neoneurone on 27th november, 2007
30
31 #include "lex_util.h"
32
33 namespace TinyXPath
34 {
35
36 /**
37 A lexical token stream, part of a single linked list
38 */
39 class lex_token
40 {
41 /// Representation
42 char * cp_value;
43 /// lexical value
44 lexico l_enum;
45 /// pointer to next element
46 lex_token * ltp_next, * ltp_prev;
47 public :
48 /// constructor
49 lex_token (lexico l_in_enum, const _byte_ * bp_in_value, unsigned u_in_size)
50 {
51 l_enum = l_in_enum;
52 cp_value = new char [u_in_size + 1];
53 if (u_in_size)
54 memcpy (cp_value, bp_in_value, u_in_size);
55 cp_value [u_in_size] = 0;
56 ltp_next = NULL;
57 ltp_prev = NULL;
58 }
59 /// set the next element in list
60 void v_set_next (lex_token * ltp_in_next)
61 {
62 ltp_next = ltp_in_next;
63 }
64 /// set the previous element in list
65 void v_set_prev (lex_token * ltp_in_prev)
66 {
67 ltp_prev = ltp_in_prev;
68 }
69 /// destructor. doesn't destroys next in list
70 ~ lex_token ()
71 {
72 if (cp_value)
73 delete [] cp_value;
74 }
75
76 /// get next in list
77 lex_token * ltp_get_next () const
78 {
79 return ltp_next;
80 }
81
82 /// get next in list
83 lex_token * ltp_get_prev () const
84 {
85 return ltp_prev;
86 }
87
88 /// Return the next i-th element in the list
89 lex_token * ltp_get_next (int i_nb)
90 {
91 lex_token * ltp_ret;
92 int i;
93
94 ltp_ret = this;
95 for (i = 0; i < i_nb; i++)
96 {
97 if (! ltp_ret)
98 return NULL;
99 ltp_ret = ltp_ret -> ltp_get_next ();
100 if (! ltp_ret || ! ltp_ret -> o_is_valid ())
101 return NULL;
102 }
103 return ltp_ret;
104 }
105
106 /// return the value of a lexical element
107 lexico lex_get_value () const
108 {
109 return l_enum;
110 }
111
112 /// Set the string value of a lexical element
113 void v_set (lexico lex_in, const char * cp_repre)
114 {
115 unsigned u_length;
116
117 l_enum = lex_in;
118 delete [] cp_value;
119 u_length = strlen (cp_repre);
120 cp_value = new char [u_length + 1];
121 strcpy (cp_value, cp_repre);
122 }
123
124 /// return the string value of a lexical element
125 const char * cp_get_literal ()
126 {
127 return cp_value;
128 }
129
130 /// check if the lexical element is valid
131 bool o_is_valid () const {return (l_enum != lex_null);}
132 } ;
133
134 }
135
136 #endif