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
11 * Zalanyi, Balazs Andor
13 ******************************************************************************/
14 #ifndef _Ttcn_Quadruple_HH
15 #define _Ttcn_Quadruple_HH
20 * \brief Represents a quadruple.
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.
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.
36 #if defined(__sparc__) || defined(__sparc)
38 unsigned char group; /* big endian, MSB */
45 unsigned char cell; /* little endian, LSB */
56 * Default constructor initializes the quadruple to \q{0,0,0,0}
59 Quad(unsigned int value);
60 Quad(unsigned char group, unsigned char plane, unsigned char row,
62 Quad(const Quad& rhs);
64 unsigned int get_value() const;
66 void set(unsigned char group, unsigned char plane, unsigned char row,
70 * Sets the given field of the quadruple.
71 * @param field 0 - group ... 3 - cell.
72 * @param c Value to set.
74 void set(int field, unsigned char c);
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;
83 bool operator<(const Quad& rhs) const;
84 bool operator<(const QuadInterval& rhs) const;
87 * Getter function for easy access to fields.
88 * @param i Field selector: 0 - group ... 3 - cell
89 * @return Value of the field.
91 unsigned char operator[](int i) const;
94 * Returns the hex representation of this quadruple. [A-P]{8}
95 * The string must be deallocated by the caller with Free()
97 char* get_hexrepr() const;
100 * Returns the hex representation of \p value. [A-P]{8}
101 * The string must be deallocated by the caller with Free()
103 static char* get_hexrepr(unsigned int value);
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)
109 static void get_hexrepr(const Quad& q, char* const str);
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()
115 static char* char_hexrepr(unsigned char c);
118 /** \class QuadInterval
119 * \brief Represents an interval in a regular expression set.
121 * The interval is given with its lower and upper boundary. Boundaries are
122 * given as pointers to quadruples: \a lower and \a upper.
124 * To help creating more optimal regular expressions some basic operation is
125 * implemented: \a contains, \a has_intersection, \a join.
134 QuadInterval(Quad p_lower, Quad p_upper);
136 QuadInterval(const QuadInterval& rhs);
138 const Quad& get_lower() const;
139 const Quad& get_upper() const;
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);
148 * @param rhs A quadruple.
149 * @return true if value of \a rhs is larger than value of the upper boundary.
151 bool operator<(const Quad& rhs) const;
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.
158 bool operator<(const QuadInterval& rhs) const;
160 unsigned int width() const;
163 * Generate a posix regular expression for the interval.
164 * @return pointer to the string which should be freed by the caller.
166 char* generate_posix();
169 char* generate_hex_interval(unsigned char source, unsigned char dest);
173 * \brief Represents a set in a regular expression.
175 * Stores the quadruples and the intervals in the set and creates a posix
176 * regular expression.
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.
189 typedef struct _quadset_node_t {
192 QuadInterval* p_interval;
194 _quadset_node_t* next;
201 /// Copy constructor disabled
202 QuadSet(const QuadSet&);
203 /// Assignment disabled
204 QuadSet& operator=(const QuadSet&);
208 bool add(Quad* p_quad);
209 void add(QuadInterval* interval);
211 void join(QuadSet* rhs);
213 void set_negate(bool neg);
215 bool has_quad(const Quad& q) const;
216 bool is_empty() const;
219 * Generate a posix regular expression for the set.
220 * @return pointer to the string which should be freed by the caller.
222 char* generate_posix();
227 void clean(quadset_node_t* start);
230 * Generate the disjoint set of \a this.
234 void add_negate_interval(const Quad& q1, const Quad& q2);
235 void join_if_possible(quadset_node_t* start);