1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 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 #ifndef _Ttcn_Quadruple_HH
9 #define _Ttcn_Quadruple_HH
14 * \brief Represents a quadruple.
16 * The stored value can be accessed as an integer or as fields of the
17 * quadruple. The aim is to help the generation of the posix regular expression
18 * from TTCN-3 pattern of type universal charstring. This class can create the
19 * string representation needed by pattern matching functions.
21 * <b>The string representation:</b>
22 * Every field of the quadruple is converted to its hexadecimal representation
23 * but the regular 0..F interval is substituted with the continuous A..P
24 * interval. One quadruple is represented with 8 characters, each from A-P.
30 #if defined(__sparc__) || defined(__sparc)
32 unsigned char group; /* big endian, MSB */
39 unsigned char cell; /* little endian, LSB */
50 * Default constructor initializes the quadruple to \q{0,0,0,0}
53 Quad(unsigned int value);
54 Quad(unsigned char group, unsigned char plane, unsigned char row,
56 Quad(const Quad& rhs);
58 unsigned int get_value() const;
60 void set(unsigned char group, unsigned char plane, unsigned char row,
64 * Sets the given field of the quadruple.
65 * @param field 0 - group ... 3 - cell.
66 * @param c Value to set.
68 void set(int field, unsigned char c);
70 const Quad operator-(const Quad& rhs) const;
71 const Quad& operator=(const Quad& rhs);
72 bool operator==(unsigned int i) const;
73 bool operator==(const Quad& rhs) const;
74 bool operator<=(const Quad& rhs) const;
75 bool operator>=(const Quad& rhs) const;
77 bool operator<(const Quad& rhs) const;
78 bool operator<(const QuadInterval& rhs) const;
81 * Getter function for easy access to fields.
82 * @param i Field selector: 0 - group ... 3 - cell
83 * @return Value of the field.
85 unsigned char operator[](int i) const;
88 * Returns the hex representation of this quadruple. [A-P]{8}
89 * The string must be deallocated by the caller with Free()
91 char* get_hexrepr() const;
94 * Returns the hex representation of \p value. [A-P]{8}
95 * The string must be deallocated by the caller with Free()
97 static char* get_hexrepr(unsigned int value);
99 /** Fills \p str with the hex representation.
100 * str[0] gets the upper half of the most significant byte (group)
101 * str[7] gets the lower half of the least significant byte (cell)
103 static void get_hexrepr(const Quad& q, char* const str);
106 * Returns the hex representation of one field of the quadruple. [A-P]{2}
107 * The string must be deallocated by the caller with Free()
109 static char* char_hexrepr(unsigned char c);
112 /** \class QuadInterval
113 * \brief Represents an interval in a regular expression set.
115 * The interval is given with its lower and upper boundary. Boundaries are
116 * given as pointers to quadruples: \a lower and \a upper.
118 * To help creating more optimal regular expressions some basic operation is
119 * implemented: \a contains, \a has_intersection, \a join.
128 QuadInterval(Quad p_lower, Quad p_upper);
130 QuadInterval(const QuadInterval& rhs);
132 const Quad& get_lower() const;
133 const Quad& get_upper() const;
135 bool contains(const Quad& rhs) const;
136 bool contains(const QuadInterval& rhs) const;
137 bool has_intersection(const QuadInterval& rhs) const;
138 void join(const QuadInterval& rhs);
142 * @param rhs A quadruple.
143 * @return true if value of \a rhs is larger than value of the upper boundary.
145 bool operator<(const Quad& rhs) const;
148 * @param rhs A QuadInterval.
149 * @return true if \a rhs does not intersect with \a this and lower boundary
150 * of \a rhs is larger than upper boundary of \a this.
152 bool operator<(const QuadInterval& rhs) const;
154 unsigned int width() const;
157 * Generate a posix regular expression for the interval.
158 * @return pointer to the string which should be freed by the caller.
160 char* generate_posix();
163 char* generate_hex_interval(unsigned char source, unsigned char dest);
167 * \brief Represents a set in a regular expression.
169 * Stores the quadruples and the intervals in the set and creates a posix
170 * regular expression.
180 * Linked list storing the quadruples and intervals. This list is kept sorted
181 * to ease the POSIX regular expression generation in case of negated sets.
183 typedef struct _quadset_node_t {
186 QuadInterval* p_interval;
188 _quadset_node_t* next;
195 /// Copy constructor disabled
196 QuadSet(const QuadSet&);
197 /// Assignment disabled
198 QuadSet& operator=(const QuadSet&);
202 bool add(Quad* p_quad);
203 void add(QuadInterval* interval);
205 void join(QuadSet* rhs);
207 void set_negate(bool neg);
209 bool has_quad(const Quad& q) const;
210 bool is_empty() const;
213 * Generate a posix regular expression for the set.
214 * @return pointer to the string which should be freed by the caller.
216 char* generate_posix();
221 void clean(quadset_node_t* start);
224 * Generate the disjoint set of \a this.
228 void add_negate_interval(const Quad& q1, const Quad& q2);
229 void join_if_possible(quadset_node_t* start);