Merge pull request #83 from eadrkir/master
[deliverable/titan.core.git] / core / Universal_charstring.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 * Baji, Laszlo
10 * Balasko, Jeno
11 * Baranyi, Botond
12 * Beres, Szabolcs
13 * Delic, Adam
14 * Forstner, Matyas
15 * Kovacs, Ferenc
16 * Raduly, Csaba
17 * Szabados, Kristof
18 * Szabo, Bence Janos
19 * Szabo, Janos Zoltan – initial implementation
20 * Szalai, Gabor
21 * Zalanyi, Balazs Andor
22 *
23 ******************************************************************************/
970ed795
EL
24#ifndef UNIVERSAL_CHARSTRING_HH
25#define UNIVERSAL_CHARSTRING_HH
26
27#include "Basetype.hh"
28#include "Template.hh"
29#include "Optional.hh"
30#include "Error.hh"
31#include "CharCoding.hh"
32
33#include <regex.h>
34#include "Charstring.hh"
35
36class CHARSTRING;
37class CHARSTRING_ELEMENT;
38class CHARSTRING_template;
39class UNIVERSAL_CHARSTRING_ELEMENT;
40class UNIVERSAL_CHARSTRING_template;
41class INTEGER;
42class Module_Param;
43
44extern boolean operator==(const universal_char& left_value,
45 const universal_char& right_value);
46extern boolean operator<(const universal_char& left_value,
47 const universal_char& right_value);
48
49/** Runtime class for Unicode character strings.
50 *
51 * This class implements the following string types:
52 * - TTCN-3 \c universal \c charstring
53 * - ASN.1
54 * - \c UTF8String
55 * - \c TeletexString
56 * - \c VideotexString
57 * - \c GraphicsString
58 * - \c GeneralString
59 * - \c UniversalString
60 * - \c BMPString
61 * - \c ObjectDescriptor
62 *
63 * Note: an object of this class is effectively immutable after creation.
64 *
65 * There is no terminating {0,0,0,0} at the end.
66 */
67class UNIVERSAL_CHARSTRING : public Base_Type {
68
69 friend class CHARSTRING;
70 friend class CHARSTRING_ELEMENT;
71 friend class UNIVERSAL_CHARSTRING_ELEMENT;
72 friend class TTCN_Buffer;
73 friend class UNIVERSAL_CHARSTRING_template;
74
75 friend UNIVERSAL_CHARSTRING oct2unichar(const OCTETSTRING& invalue,
76 const CHARSTRING& string_encoding);
77 friend UNIVERSAL_CHARSTRING oct2unichar(const OCTETSTRING& invalue);
78 friend UNIVERSAL_CHARSTRING replace(const UNIVERSAL_CHARSTRING& value,
79 int index, int len, const UNIVERSAL_CHARSTRING& repl);
80 friend UNIVERSAL_CHARSTRING regexp(const UNIVERSAL_CHARSTRING& instr,
81 const UNIVERSAL_CHARSTRING* expression_val,
82 const UNIVERSAL_CHARSTRING_template* expression_tmpl,
83 int groupno);
84
85 friend boolean operator==(const universal_char& uchar_value,
86 const UNIVERSAL_CHARSTRING& other_value);
87 friend UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value,
88 const UNIVERSAL_CHARSTRING& other_value);
89 friend boolean operator==(const char *string_value,
90 const UNIVERSAL_CHARSTRING& other_value);
91 friend UNIVERSAL_CHARSTRING operator+(const char *string_value,
92 const UNIVERSAL_CHARSTRING& other_value);
93 friend UNIVERSAL_CHARSTRING operator+(const char *string_value,
94 const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
95 friend UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value,
96 const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
97 friend boolean operator==(const char *string_value,
98 const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
99
100 /** Internal data type, no user serviceable parts inside */
101 struct universal_charstring_struct;
102 /** Internal data */
103 universal_charstring_struct *val_ptr;
104 /** Character string values are stored in an optimal way */
105 CHARSTRING cstr;
106 bool charstring;
107
108 void init_struct(int n_uchars);
109 void copy_value();
110 UNIVERSAL_CHARSTRING(int n_uchars, bool cstring = false);
3abe9331 111
112 /** An extended version of set_param(), which also accepts string patterns if
113 * the second parameter is set (needed by UNIVERSAL_CHARSTRING_template to
114 * concatenate string patterns).
115 * @return TRUE, if the module parameter was a string pattern, otherwise FALSE */
116 boolean set_param_internal(Module_Param& param, boolean allow_pattern);
970ed795
EL
117
118public:
119
120 /** Construct an empty string */
121 UNIVERSAL_CHARSTRING();
122 /** Construct a string containing a single character.
123 *
124 * @param uc_group Unicode group (most significant part)
125 * @param uc_plane Unicode plane
126 * @param uc_row Unicode row
127 * @param uc_cell Unicode cell (least significant)
128 *
129 */
130 UNIVERSAL_CHARSTRING(unsigned char uc_group, unsigned char uc_plane,
131 unsigned char uc_row, unsigned char uc_cell);
132 /** Construct a string containing a single character
133 *
134 * @param other_value
135 */
136 UNIVERSAL_CHARSTRING(const universal_char& other_value);
137 /** Construct a string from a given number of characters
138 *
139 * @param n_uchars
140 * @param uchars_ptr
141 */
142 UNIVERSAL_CHARSTRING(int n_uchars, const universal_char *uchars_ptr);
143 /** Construct a string from a C string
144 *
145 * @param chars_ptr pointer to the source string. A NULL pointer
146 * will result in an empty UNIVERSAL_CHARSTRING.
147 *
148 * All characters in the string will have group==plane==row==0
149 */
150 UNIVERSAL_CHARSTRING(const char *chars_ptr);
151 /** Construct a string from a known number of single-byte characters
152 *
153 * @param n_chars number of characters
154 * @param chars_ptr pointer to the source string.
155 *
156 * @pre if n_chars > 0, chars_ptr must point to a valid string,
157 * else an access violation will occur.
158 *
159 * All characters in the string will have group==plane==row==0
160 */
161 UNIVERSAL_CHARSTRING(int n_chars, const char *chars_ptr);
162 /** Construct a copy of another CHARSTRING
163 *
164 * @param other_value
165 */
166 UNIVERSAL_CHARSTRING(const CHARSTRING& other_value);
167 /** Construct a string containing a single CHARSTRING_ELEMENT
168 *
169 * @param other_value
170 */
171 UNIVERSAL_CHARSTRING(const CHARSTRING_ELEMENT& other_value);
172 /** Copy constructor
173 *
174 * @param other_value
175 */
176 UNIVERSAL_CHARSTRING(const UNIVERSAL_CHARSTRING& other_value);
177 /** Construct a string containing a single UNIVERSAL_CHARSTRING_ELEMENT
178 *
179 * @param other_value
180 */
181 UNIVERSAL_CHARSTRING(const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
182
183 ~UNIVERSAL_CHARSTRING();
184 void clean_up();
185
186 UNIVERSAL_CHARSTRING& operator=(const universal_char& other_value);
187 UNIVERSAL_CHARSTRING& operator=(const char* other_value);
188 UNIVERSAL_CHARSTRING& operator=(const CHARSTRING& other_value);
189 UNIVERSAL_CHARSTRING& operator=(const CHARSTRING_ELEMENT& other_value);
190 UNIVERSAL_CHARSTRING& operator=(const UNIVERSAL_CHARSTRING& other_value);
191 UNIVERSAL_CHARSTRING& operator=(const UNIVERSAL_CHARSTRING_ELEMENT&
192 other_value);
193
194 /** @name Comparison operators
195 * @{
196 */
197 boolean operator==(const universal_char& other_value) const;
198 boolean operator==(const char* other_value) const;
199 boolean operator==(const CHARSTRING& other_value) const;
200 boolean operator==(const CHARSTRING_ELEMENT& other_value) const;
201 boolean operator==(const UNIVERSAL_CHARSTRING& other_value) const;
202 boolean operator==(const UNIVERSAL_CHARSTRING_ELEMENT&
203 other_value) const;
204
205 boolean operator!=(const universal_char& other_value) const
206 { return !(*this == other_value); }
207 boolean operator!=(const char* other_value) const
208 { return !(*this == other_value); }
209 boolean operator!=(const CHARSTRING& other_value) const
210 { return !(*this == other_value); }
211 boolean operator!=(const CHARSTRING_ELEMENT& other_value) const
212 { return !(*this == other_value); }
213 boolean operator!=(const UNIVERSAL_CHARSTRING& other_value) const
214 { return !(*this == other_value); }
215 boolean operator!=(const UNIVERSAL_CHARSTRING_ELEMENT&
216 other_value) const { return !(*this == other_value); }
217 /** @} */
218
219 /** @name Concatenation
220 *
221 *
222 * @{
223 */
224 UNIVERSAL_CHARSTRING operator+(const universal_char& other_value) const;
225 UNIVERSAL_CHARSTRING operator+(const char* other_value) const;
226 UNIVERSAL_CHARSTRING operator+(const CHARSTRING& other_value) const;
227 UNIVERSAL_CHARSTRING operator+(const CHARSTRING_ELEMENT& other_value) const;
228 UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING& other_value) const;
229 UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING_ELEMENT&
230 other_value) const;
231 /** @} */
232
233 /** @name Rotation
234 * @{ */
235 UNIVERSAL_CHARSTRING operator<<=(int rotate_count) const;
236 UNIVERSAL_CHARSTRING operator<<=(const INTEGER& rotate_count) const;
237 UNIVERSAL_CHARSTRING operator>>=(int rotate_count) const;
238 UNIVERSAL_CHARSTRING operator>>=(const INTEGER& rotate_count) const;
239 /** @} */
240
241 /** @name Indexing
242 * @{ */
243 UNIVERSAL_CHARSTRING_ELEMENT operator[](int index_value);
244 UNIVERSAL_CHARSTRING_ELEMENT operator[](const INTEGER& index_value);
245 const UNIVERSAL_CHARSTRING_ELEMENT operator[](int index_value) const;
246 const UNIVERSAL_CHARSTRING_ELEMENT operator[]
247 (const INTEGER& index_value) const;
248 /** @} */
249
250 operator const universal_char*() const;
251
252 inline boolean is_bound() const {
253 if (charstring) return cstr.is_bound();
254 else return val_ptr != NULL; }
255 inline boolean is_value() const {
256 if (charstring) return cstr.is_value();
257 else return val_ptr != NULL; }
258 inline void must_bound(const char *err_msg) const
259 { if (charstring) cstr.must_bound(err_msg);
260 else if (val_ptr == NULL) TTCN_error("%s", err_msg); }
261
262 int lengthof() const;
263
264 void dump() const;
265
266private:
267 // convert this string to character string for pattern matching: ([A-P]{8})*
268 char* convert_to_regexp_form() const;
269
270 /* returns the CHARSTRING representation of this. Quadruples are converted
271 into the form: \q{group,plane,row,cell} */
272 CHARSTRING get_stringRepr_for_pattern() const;
273
274 void convert_cstr_to_uni();
275//checks if an valid BOM is at the head of the string. Returns the length of BOM
276 int check_BOM(CharCoding::CharCodingType expected_coding, unsigned int length,
277 const unsigned char* ostr);
278
279 /** Returns the universal charstring in the format a string would appear in C or TTCN-3 code.
280 * Inserts double quotation marks to the begining and end of the string and
281 * doubles the backlsashes in escaped characters.
282 * Used for JSON encoding.
283 *
284 * @param p_buf The buffer containing the universal charstring in UTF-8 encoding
285 *
286 * Example: "He said\nhis name was \"Al\"." -> "\"He said\\nhis name was \\\"Al\\\".\""
287 * Example2: char(0, 0, 1, 113) in TTCN-3 -> "\u0171"
288 * @note The returned character buffer needs to be freed after use. */
289 char* to_JSON_string(const TTCN_Buffer& p_buf) const;
290
291 /** Converts the universal charstring from JSON string format to normal format.
292 * The double quotation marks from the beginning and end of the JSON string are
293 * removed and double-escaped characters are changed to simple-escaped ones.
294 * JSON characters stored as \u + 4 hex digits are converted to the characters
295 * they represent.
296 * Returns false if any invalid characters were found, otherwise true.
297 * Used for JSON decoding.
298 *
299 * Example: "\"He said\\nhis name was \\\"Al\\\".\"" -> "He said\nhis name was \"Al\"."
300 * Example2: "\u0061" -> "a"
301 *
302 * @param check_quotes turn the checking of double quotes (mentioned above) on or off */
303 boolean from_JSON_string(boolean check_quotes);
304
305 /** Checks the coding of the characters in the received buffer, if they are
306 * encoded in UTF-8 this function will decode them.
307 * @return The universal charstring containing the decoded characters */
308 static UNIVERSAL_CHARSTRING from_UTF8_buffer(TTCN_Buffer& p_buff);
309
310public:
311
312#ifdef TITAN_RUNTIME_2
313 boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const UNIVERSAL_CHARSTRING*>(other_value)); }
314 void set_value(const Base_Type* other_value) { *this = *(static_cast<const UNIVERSAL_CHARSTRING*>(other_value)); }
315 Base_Type* clone() const { return new UNIVERSAL_CHARSTRING(*this); }
316 const TTCN_Typedescriptor_t* get_descriptor() const { return &UNIVERSAL_CHARSTRING_descr_; }
317#else
318 inline boolean is_present() const { return is_bound(); }
319#endif
320
321 void log() const;
322
323 /** Initializes this object with a module parameter value or concatenates a module
324 * parameter value to the end of this string.
325 * @note UFT-8 strings (whose characters were not in quadruple notation) will
326 * be decoded */
327 void set_param(Module_Param& param);
3abe9331 328 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
329
330 void encode_text(Text_Buf& text_buf) const;
331 void decode_text(Text_Buf& text_buf);
332
333 void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
334 TTCN_EncDec::coding_t p_coding, ...) const;
335 void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
336 TTCN_EncDec::coding_t p_coding, ...);
337
338 ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td,
339 unsigned p_coding) const;
340
341 boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td,
342 const ASN_BER_TLV_t& p_tlv, unsigned L_form);
343
d44e3c4f 344 /** Encodes the value according to the TTCN_Typedescriptor_t.
345 * It must be public because it can be called by other types during encoding.
346 * Returns the length of encoded data */
347 int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const;
348
349 /** Decodes the value according to the TTCN_Typedescriptor_t.
350 * It must be public because it can be called by other types during encoding.
351 * Returns the number of decoded bits */
352 int RAW_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, int, raw_order_t,
353 boolean no_err=FALSE, int sel_field=-1, boolean first_call=TRUE);
354
a38c6d4c 355 int TEXT_encode(const TTCN_Typedescriptor_t&,
356 TTCN_Buffer&) const;
357 int TEXT_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, Limit_Token_List&,
358 boolean no_err=FALSE, boolean first_call=TRUE);
af710487 359 int XER_encode(const XERdescriptor_t&, TTCN_Buffer&, unsigned int, int, embed_values_enc_struct_t*) const;
feade998 360 int XER_decode(const XERdescriptor_t&, XmlReaderWrap& reader, unsigned int, unsigned int, embed_values_dec_struct_t*);
970ed795
EL
361 /** Decodes UTF-8 into the internal representation (UCS4-BE)
362 *
363 * @param n_octets number of UTF-8 bytes (not characters)
364 * @param octets_ptr pointer to the bytes
365 *
366 * @pre the UNIVERSAL_CHARSTRING is unbound or clean_up() has been called
367 * (otherwise memory leak will occur)
368 */
369 void decode_utf8(int n_octets, const unsigned char *octets_ptr,
370 CharCoding::CharCodingType expected_coding = CharCoding::UTF_8, bool checkBOM = false);
371 void decode_utf16(int n_octets, const unsigned char *octets_ptr,
372 CharCoding::CharCodingType expected_coding);
373 void decode_utf32(int n_octets, const unsigned char *octets_ptr,
374 CharCoding::CharCodingType expected_coding);
375 /** Appends the content of this string to the supplied buffer, in UTF-8
376 *
377 * @param[out] buf buffer to receive the encoded result
378 */
379 void encode_utf8(TTCN_Buffer& buf, bool addBOM = false) const;
380 void encode_utf16(TTCN_Buffer& buf, CharCoding::CharCodingType expected_coding) const;
381 void encode_utf32(TTCN_Buffer& buf, CharCoding::CharCodingType expected_coding) const;
382
383 /** Encodes accordingly to the JSON encoding rules.
384 * The universal charstring will be encoded with UTF-8 before being added to
385 * the JSON code.
386 * Returns the length of the encoded data.
387 * @note Since JSON has its own set of escaped characters, the ones in the
388 * universal charstring need to be double-escaped. */
389 int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const;
390
391 /** Decodes accordingly to the JSON encoding rules.
392 * Returns the length of the decoded data. */
393 int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean);
394
395private:
396#ifdef TITAN_RUNTIME_2
397 virtual int encode_raw(TTCN_Buffer& p_buf) const;
3f84031e 398 /** Encodes this universal charstring with UTF-8 and adds the result to the end
399 * of a JSON buffer as raw data.
400 * Used during the negative testing of the JSON encoder.
401 * @return The number of bytes added. */
402 int JSON_encode_negtest_raw(JSON_Tokenizer&) const;
970ed795
EL
403#endif
404};
405
406class UNIVERSAL_CHARSTRING_ELEMENT {
407 friend class UNIVERSAL_CHARSTRING;
408 friend UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value,
409 const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
410 friend boolean operator==(const char *string_value,
411 const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
412 friend UNIVERSAL_CHARSTRING operator+(const char *string_value,
413 const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
414 friend UNIVERSAL_CHARSTRING CHARSTRING::operator+
415 (const UNIVERSAL_CHARSTRING_ELEMENT& other_value) const;
416
417 boolean bound_flag;
418 UNIVERSAL_CHARSTRING& str_val;
419 int uchar_pos;
420
421public:
422 UNIVERSAL_CHARSTRING_ELEMENT(boolean par_bound_flag,
423 UNIVERSAL_CHARSTRING& par_str_val, int par_uchar_pos);
424
425 UNIVERSAL_CHARSTRING_ELEMENT& operator=(const universal_char& other_value);
426 UNIVERSAL_CHARSTRING_ELEMENT& operator=(const char* other_value);
427 UNIVERSAL_CHARSTRING_ELEMENT& operator=(const CHARSTRING& other_value);
428 UNIVERSAL_CHARSTRING_ELEMENT& operator=
429 (const CHARSTRING_ELEMENT& other_value);
430 UNIVERSAL_CHARSTRING_ELEMENT& operator=
431 (const UNIVERSAL_CHARSTRING& other_value);
432 UNIVERSAL_CHARSTRING_ELEMENT& operator=
433 (const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
434
435 boolean operator==(const universal_char& other_value) const;
436 boolean operator==(const char* other_value) const;
437 boolean operator==(const CHARSTRING& other_value) const;
438 boolean operator==(const CHARSTRING_ELEMENT& other_value) const;
439 boolean operator==(const UNIVERSAL_CHARSTRING& other_value) const;
440 boolean operator==(const UNIVERSAL_CHARSTRING_ELEMENT&
441 other_value) const;
442
443 boolean operator!=(const universal_char& other_value) const
444 { return !(*this == other_value); }
445 boolean operator!=(const char* other_value) const
446 { return !(*this == other_value); }
447 boolean operator!=(const CHARSTRING& other_value) const
448 { return !(*this == other_value); }
449 boolean operator!=(const CHARSTRING_ELEMENT& other_value) const
450 { return !(*this == other_value); }
451 boolean operator!=(const UNIVERSAL_CHARSTRING& other_value) const
452 { return !(*this == other_value); }
453 boolean operator!=(const UNIVERSAL_CHARSTRING_ELEMENT&
454 other_value) const { return !(*this == other_value); }
455
456 UNIVERSAL_CHARSTRING operator+(const universal_char& other_value) const;
457 UNIVERSAL_CHARSTRING operator+(const char* other_value) const;
458 UNIVERSAL_CHARSTRING operator+(const CHARSTRING& other_value) const;
459 UNIVERSAL_CHARSTRING operator+(const CHARSTRING_ELEMENT& other_value) const;
460 UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING& other_value) const;
461 UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING_ELEMENT&
462 other_value) const;
463
464 inline boolean is_bound() const { return bound_flag; }
465 inline boolean is_present() const { return bound_flag; }
466 inline boolean is_value() const { return bound_flag; }
467 inline void must_bound(const char *err_msg) const
468 { if (!bound_flag) TTCN_error("%s", err_msg); }
469
470 const universal_char& get_uchar() const;
471 void log() const;
472};
473
474extern boolean operator==(const universal_char& uchar_value,
475 const UNIVERSAL_CHARSTRING& other_value);
476extern boolean operator==(const universal_char& uchar_value,
477 const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
478
479inline boolean operator!=(const universal_char& uchar_value,
480 const UNIVERSAL_CHARSTRING& other_value)
481{
482 return !(uchar_value == other_value);
483}
484
485inline boolean operator!=(const universal_char& uchar_value,
486 const UNIVERSAL_CHARSTRING_ELEMENT& other_value)
487{
488 return !(uchar_value == other_value);
489}
490
491inline boolean operator!=(const universal_char& uchar_value,
492 const universal_char& other_value)
493{
494 return !(uchar_value == other_value);
495}
496
497extern UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value,
498 const UNIVERSAL_CHARSTRING& other_value);
499extern UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value,
500 const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
501
502extern boolean operator==(const char *string_value,
503 const UNIVERSAL_CHARSTRING& other_value);
504extern boolean operator==(const char *string_value,
505 const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
506
507inline boolean operator!=(const char *string_value,
508 const UNIVERSAL_CHARSTRING& other_value)
509{
510 return !(string_value == other_value);
511}
512
513inline boolean operator!=(const char *string_value,
514 const UNIVERSAL_CHARSTRING_ELEMENT& other_value)
515{
516 return !(string_value == other_value);
517}
518
519extern UNIVERSAL_CHARSTRING operator+(const char *string_value,
520 const UNIVERSAL_CHARSTRING& other_value);
521extern UNIVERSAL_CHARSTRING operator+(const char *string_value,
522 const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
523
524
28352dbd
BB
525struct unichar_decmatch_struct;
526
970ed795
EL
527class UNIVERSAL_CHARSTRING_template : public Restricted_Length_Template {
528private:
529 UNIVERSAL_CHARSTRING single_value;
530 CHARSTRING* pattern_string;
531 union {
532 struct {
533 unsigned int n_values;
534 UNIVERSAL_CHARSTRING_template *list_value;
535 } value_list;
536 struct {
537 boolean min_is_set, max_is_set;
538 universal_char min_value, max_value;
539 } value_range;
540 mutable struct {
541 boolean regexp_init;
542 regex_t posix_regexp;
543 } pattern_value;
28352dbd 544 unichar_decmatch_struct* dec_match;
970ed795
EL
545 };
546
547 void copy_template(const CHARSTRING_template& other_value);
548 void copy_template(const UNIVERSAL_CHARSTRING_template& other_value);
549
550public:
551 UNIVERSAL_CHARSTRING_template();
552 UNIVERSAL_CHARSTRING_template(template_sel other_value);
553 UNIVERSAL_CHARSTRING_template(const CHARSTRING& other_value);
554 UNIVERSAL_CHARSTRING_template(const UNIVERSAL_CHARSTRING& other_value);
555 UNIVERSAL_CHARSTRING_template(const CHARSTRING_ELEMENT& other_value);
556 UNIVERSAL_CHARSTRING_template
557 (const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
558 UNIVERSAL_CHARSTRING_template(const OPTIONAL<CHARSTRING>& other_value);
559 UNIVERSAL_CHARSTRING_template
560 (const OPTIONAL<UNIVERSAL_CHARSTRING>& other_value);
561 UNIVERSAL_CHARSTRING_template
562 (const CHARSTRING_template& other_value);
563 UNIVERSAL_CHARSTRING_template
564 (const UNIVERSAL_CHARSTRING_template& other_value);
565 UNIVERSAL_CHARSTRING_template(template_sel p_sel, const CHARSTRING& p_str);
566
567 ~UNIVERSAL_CHARSTRING_template();
568 void clean_up();
569
570 UNIVERSAL_CHARSTRING_template& operator=(template_sel other_value);
571 UNIVERSAL_CHARSTRING_template& operator=(const CHARSTRING& other_value);
572 UNIVERSAL_CHARSTRING_template& operator=
573 (const UNIVERSAL_CHARSTRING& other_value);
574 UNIVERSAL_CHARSTRING_template& operator=
575 (const CHARSTRING_ELEMENT& other_value);
576 UNIVERSAL_CHARSTRING_template& operator=
577 (const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
578 UNIVERSAL_CHARSTRING_template& operator=
579 (const OPTIONAL<CHARSTRING>& other_value);
580 UNIVERSAL_CHARSTRING_template& operator=
581 (const OPTIONAL<UNIVERSAL_CHARSTRING>& other_value);
582 UNIVERSAL_CHARSTRING_template& operator=
583 (const CHARSTRING_template& other_value);
584 UNIVERSAL_CHARSTRING_template& operator=
585 (const UNIVERSAL_CHARSTRING_template& other_value);
586
587 UNIVERSAL_CHARSTRING_ELEMENT operator[](int index_value);
588 UNIVERSAL_CHARSTRING_ELEMENT operator[](const INTEGER& index_value);
589 const UNIVERSAL_CHARSTRING_ELEMENT operator[](int index_value) const;
590 const UNIVERSAL_CHARSTRING_ELEMENT operator[]
591 (const INTEGER& index_value) const;
592
3abe9331 593 boolean match(const UNIVERSAL_CHARSTRING& other_value, boolean legacy = FALSE) const;
970ed795
EL
594 const UNIVERSAL_CHARSTRING& valueof() const;
595
596 int lengthof() const;
597
598 void set_type(template_sel template_type, unsigned int list_length = 0);
599 UNIVERSAL_CHARSTRING_template& list_item(unsigned int list_index);
600
601 void set_min(const UNIVERSAL_CHARSTRING& min_value);
602 void set_max(const UNIVERSAL_CHARSTRING& max_value);
28352dbd
BB
603
604 void set_decmatch(Dec_Match_Interface* new_instance, const char* coding_str = NULL);
970ed795
EL
605
606 void log() const;
3abe9331 607 void log_match(const UNIVERSAL_CHARSTRING& match_value, boolean legacy = FALSE) const;
970ed795
EL
608
609 void set_param(Module_Param& param);
3abe9331 610 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
611
612 void encode_text(Text_Buf& text_buf) const;
613 void decode_text(Text_Buf& text_buf);
614
3abe9331 615 boolean is_present(boolean legacy = FALSE) const;
616 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
617
618#ifdef TITAN_RUNTIME_2
619 void valueofv(Base_Type* value) const { *(static_cast<UNIVERSAL_CHARSTRING*>(value)) = valueof(); }
620 void set_value(template_sel other_value) { *this = other_value; }
621 void copy_value(const Base_Type* other_value) { *this = *(static_cast<const UNIVERSAL_CHARSTRING*>(other_value)); }
622 Base_Template* clone() const { return new UNIVERSAL_CHARSTRING_template(*this); }
623 const TTCN_Typedescriptor_t* get_descriptor() const { return &UNIVERSAL_CHARSTRING_descr_; }
3abe9331 624 boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const UNIVERSAL_CHARSTRING*>(other_value)), legacy); }
625 void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const UNIVERSAL_CHARSTRING*>(match_value)), legacy); }
970ed795 626#else
3abe9331 627 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
628#endif
629
630 const CHARSTRING& get_single_value() const;
631};
632
633typedef UNIVERSAL_CHARSTRING BMPString;
634typedef UNIVERSAL_CHARSTRING UniversalString;
635typedef UNIVERSAL_CHARSTRING UTF8String;
636typedef UNIVERSAL_CHARSTRING TeletexString;
637typedef TeletexString T61String;
638typedef UNIVERSAL_CHARSTRING VideotexString;
639typedef UNIVERSAL_CHARSTRING GraphicString;
640typedef UNIVERSAL_CHARSTRING GeneralString;
641
642typedef UNIVERSAL_CHARSTRING_template BMPString_template;
643typedef UNIVERSAL_CHARSTRING_template UniversalString_template;
644typedef UNIVERSAL_CHARSTRING_template UTF8String_template;
645typedef UNIVERSAL_CHARSTRING_template TeletexString_template;
646typedef TeletexString_template T61String_template;
647typedef UNIVERSAL_CHARSTRING_template VideotexString_template;
648typedef UNIVERSAL_CHARSTRING_template GraphicString_template;
649typedef UNIVERSAL_CHARSTRING_template GeneralString_template;
650
651typedef GraphicString ObjectDescriptor;
652typedef GraphicString_template ObjectDescriptor_template;
653
654OCTETSTRING TTCN_TeletexString_2_ISO2022(const TeletexString& p_s);
655TeletexString TTCN_ISO2022_2_TeletexString(const OCTETSTRING& p_os);
656OCTETSTRING TTCN_VideotexString_2_ISO2022(const VideotexString& p_s);
657VideotexString TTCN_ISO2022_2_VideotexString(const OCTETSTRING& p_os);
658OCTETSTRING TTCN_GraphicString_2_ISO2022(const GraphicString& p_s);
659GraphicString TTCN_ISO2022_2_GraphicString(const OCTETSTRING& p_os);
660OCTETSTRING TTCN_GeneralString_2_ISO2022(const GeneralString& p_s);
661GeneralString TTCN_ISO2022_2_GeneralString(const OCTETSTRING& p_os);
662
663#endif
This page took 0.05438 seconds and 5 git commands to generate.