indentation problem in the generated code
[deliverable/titan.core.git] / common / Quadruple.hh
CommitLineData
d44e3c4f 1/******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Raduly, Csaba
11 * Zalanyi, Balazs Andor
12 *
13 ******************************************************************************/
970ed795
EL
14#ifndef _Ttcn_Quadruple_HH
15#define _Ttcn_Quadruple_HH
16
17class QuadInterval;
18
19/** \class Quad
20 * \brief Represents a quadruple.
21 *
22 * The stored value can be accessed as an integer or as fields of the
23 * quadruple. The aim is to help the generation of the posix regular expression
24 * from TTCN-3 pattern of type universal charstring. This class can create the
25 * string representation needed by pattern matching functions.
26 *
27 * <b>The string representation:</b>
28 * Every field of the quadruple is converted to its hexadecimal representation
29 * but the regular 0..F interval is substituted with the continuous A..P
30 * interval. One quadruple is represented with 8 characters, each from A-P.
31 */
32class Quad {
33
34 union {
35 unsigned int value;
36#if defined(__sparc__) || defined(__sparc)
37 struct {
38 unsigned char group; /* big endian, MSB */
39 unsigned char plane;
40 unsigned char row;
41 unsigned char cell;
42 } comp;
43#else
44 struct {
45 unsigned char cell; /* little endian, LSB */
46 unsigned char row;
47 unsigned char plane;
48 unsigned char group;
49 } comp;
50#endif
51 } u;
52
53public:
54
55 /**
56 * Default constructor initializes the quadruple to \q{0,0,0,0}
57 */
58 Quad();
59 Quad(unsigned int value);
60 Quad(unsigned char group, unsigned char plane, unsigned char row,
61 unsigned char cell);
62 Quad(const Quad& rhs);
63
64 unsigned int get_value() const;
65
66 void set(unsigned char group, unsigned char plane, unsigned char row,
67 unsigned char cell);
68
69 /**
70 * Sets the given field of the quadruple.
71 * @param field 0 - group ... 3 - cell.
72 * @param c Value to set.
73 */
74 void set(int field, unsigned char c);
75
76 const Quad operator-(const Quad& rhs) const;
77 const Quad& operator=(const Quad& rhs);
78 bool operator==(unsigned int i) const;
79 bool operator==(const Quad& rhs) const;
80 bool operator<=(const Quad& rhs) const;
81 bool operator>=(const Quad& rhs) const;
82
83 bool operator<(const Quad& rhs) const;
84 bool operator<(const QuadInterval& rhs) const;
85
86 /**
87 * Getter function for easy access to fields.
88 * @param i Field selector: 0 - group ... 3 - cell
89 * @return Value of the field.
90 */
91 unsigned char operator[](int i) const;
92
93 /**
94 * Returns the hex representation of this quadruple. [A-P]{8}
95 * The string must be deallocated by the caller with Free()
96 */
97 char* get_hexrepr() const;
98
99 /**
100 * Returns the hex representation of \p value. [A-P]{8}
101 * The string must be deallocated by the caller with Free()
102 */
103 static char* get_hexrepr(unsigned int value);
104
105 /** Fills \p str with the hex representation.
106 * str[0] gets the upper half of the most significant byte (group)
107 * str[7] gets the lower half of the least significant byte (cell)
108 */
109 static void get_hexrepr(const Quad& q, char* const str);
110
111 /**
112 * Returns the hex representation of one field of the quadruple. [A-P]{2}
113 * The string must be deallocated by the caller with Free()
114 */
115 static char* char_hexrepr(unsigned char c);
116};
117
118/** \class QuadInterval
119 * \brief Represents an interval in a regular expression set.
120 *
121 * The interval is given with its lower and upper boundary. Boundaries are
122 * given as pointers to quadruples: \a lower and \a upper.
123 *
124 * To help creating more optimal regular expressions some basic operation is
125 * implemented: \a contains, \a has_intersection, \a join.
126 */
127class QuadInterval {
128 Quad lower;
129 Quad upper;
130
131 friend class Quad;
132
133public:
134 QuadInterval(Quad p_lower, Quad p_upper);
135
136 QuadInterval(const QuadInterval& rhs);
137
138 const Quad& get_lower() const;
139 const Quad& get_upper() const;
140
141 bool contains(const Quad& rhs) const;
142 bool contains(const QuadInterval& rhs) const;
143 bool has_intersection(const QuadInterval& rhs) const;
144 void join(const QuadInterval& rhs);
145
146 /**
147 * operator<()
148 * @param rhs A quadruple.
149 * @return true if value of \a rhs is larger than value of the upper boundary.
150 */
151 bool operator<(const Quad& rhs) const;
152 /**
153 * operator<()
154 * @param rhs A QuadInterval.
155 * @return true if \a rhs does not intersect with \a this and lower boundary
156 * of \a rhs is larger than upper boundary of \a this.
157 */
158 bool operator<(const QuadInterval& rhs) const;
159
160 unsigned int width() const;
161
162 /**
163 * Generate a posix regular expression for the interval.
164 * @return pointer to the string which should be freed by the caller.
165 */
166 char* generate_posix();
167
168private:
169 char* generate_hex_interval(unsigned char source, unsigned char dest);
170};
171
172/** \class QuadSet
173 * \brief Represents a set in a regular expression.
174 *
175 * Stores the quadruples and the intervals in the set and creates a posix
176 * regular expression.
177 */
178class QuadSet {
179
180 enum elemtype_t {
181 QSET_QUAD,
182 QSET_INTERVAL
183 };
184
185 /**
186 * Linked list storing the quadruples and intervals. This list is kept sorted
187 * to ease the POSIX regular expression generation in case of negated sets.
188 */
189 typedef struct _quadset_node_t {
190 union {
191 Quad* p_quad;
192 QuadInterval* p_interval;
193 } u;
194 _quadset_node_t* next;
195 elemtype_t etype;
196 } quadset_node_t;
197
198 quadset_node_t* set;
199 bool negate;
200
201 /// Copy constructor disabled
202 QuadSet(const QuadSet&);
203 /// Assignment disabled
204 QuadSet& operator=(const QuadSet&);
205public:
206 QuadSet();
207
208 bool add(Quad* p_quad);
209 void add(QuadInterval* interval);
210
211 void join(QuadSet* rhs);
212
213 void set_negate(bool neg);
214
215 bool has_quad(const Quad& q) const;
216 bool is_empty() const;
217
218 /**
219 * Generate a posix regular expression for the set.
220 * @return pointer to the string which should be freed by the caller.
221 */
222 char* generate_posix();
223
224 ~QuadSet();
225
226private:
227 void clean(quadset_node_t* start);
228
229 /**
230 * Generate the disjoint set of \a this.
231 */
232 void do_negate();
233
234 void add_negate_interval(const Quad& q1, const Quad& q2);
235 void join_if_possible(quadset_node_t* start);
236};
237
238#endif
This page took 0.034491 seconds and 5 git commands to generate.