Charstring.hh 22.2 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
/******************************************************************************
Adam Knapp's avatar
Adam Knapp committed
2
 * Copyright (c) 2000-2021 Ericsson Telecom AB
Elemer Lelik's avatar
Elemer Lelik committed
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v2.0
Elemer Lelik's avatar
Elemer Lelik committed
5
 * which accompanies this distribution, and is available at
6
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
Elemer Lelik's avatar
Elemer Lelik committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * Contributors:
 *   Balasko, Jeno
 *   Baranyi, Botond
 *   Beres, Szabolcs
 *   Delic, Adam
 *   Forstner, Matyas
 *   Kovacs, Ferenc
 *   Raduly, Csaba
 *   Szabados, Kristof
 *   Szabo, Bence Janos
 *   Szabo, Janos Zoltan – initial implementation
 *   Szalai, Gabor
 *   Tatarka, Gabor
 *   Zalanyi, Balazs Andor
 *   Pandi, Krisztian
 *
 ******************************************************************************/
Elemer Lelik's avatar
Elemer Lelik committed
25
26
27
28
29
30
31
32
33
#ifndef CHARSTRING_HH
#define CHARSTRING_HH

#include <sys/types.h>
#include <regex.h>

#include "Types.h"
#include "Basetype.hh"
#include "Template.hh"
34
#include "Param_Types.hh"
Elemer Lelik's avatar
Elemer Lelik committed
35
36
37
38
39
40
41
42

class INTEGER;
class BITSTRING;
class HEXSTRING;
class OCTETSTRING;
class CHARSTRING_ELEMENT;
class UNIVERSAL_CHARSTRING;
class UNIVERSAL_CHARSTRING_ELEMENT;
43
#ifdef TITAN_RUNTIME_2
44
class UNIVERSAL_CHARSTRING_template;
45
#endif
Elemer Lelik's avatar
Elemer Lelik committed
46

47
48
class RAW_Force_Omit;

Elemer Lelik's avatar
Elemer Lelik committed
49
50
class Module_Param;

51
52
53
template<typename T>
class OPTIONAL;

Elemer Lelik's avatar
Elemer Lelik committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/** Runtime class for character strings.
 *
 * Memory is reserved for the terminating null character
 * (not counted in the length).
 *
 * This class implements the following string types:
 *
 * - TTCN-3 \c charstring
 * - ASN.1 restricted character strings:
 *    - \c NumericString
 *    - \c PrintableString
 *    - \c IA5String
 *    - \c VisibleString.
 * - ASN.1 time types:
 *    - \c UTCTime
 *    - \c GeneralizedTime
 *
 */
class CHARSTRING : public Base_Type {

  friend class CHARSTRING_ELEMENT;
  friend class UNIVERSAL_CHARSTRING;
  friend class UNIVERSAL_CHARSTRING_ELEMENT;
  friend class TTCN_Buffer;
Elemer Lelik's avatar
Elemer Lelik committed
78
  friend class CHARSTRING_template;
Elemer Lelik's avatar
Elemer Lelik committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

  friend boolean operator==(const char* string_value,
                            const CHARSTRING& other_value);
  friend CHARSTRING operator+(const char* string_value,
                              const CHARSTRING& other_value);
  friend CHARSTRING operator+(const char* string_value,
                              const CHARSTRING_ELEMENT& other_value);

  friend CHARSTRING bit2str(const BITSTRING& value);
  friend CHARSTRING hex2str(const HEXSTRING& value);
  friend CHARSTRING oct2str(const OCTETSTRING& value);
  friend CHARSTRING unichar2char(const UNIVERSAL_CHARSTRING& value);
  friend CHARSTRING replace(const CHARSTRING& value, int index, int len,
		                    const CHARSTRING& repl);
  friend UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value,
    const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
  friend UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value,
    const UNIVERSAL_CHARSTRING& other_value);
  friend boolean operator==(const universal_char& uchar_value,
    const UNIVERSAL_CHARSTRING& other_value);
  friend boolean operator==(const char *string_value,
    const UNIVERSAL_CHARSTRING_ELEMENT& other_value);
  friend UNIVERSAL_CHARSTRING operator+(const char *string_value,
    const UNIVERSAL_CHARSTRING& other_value);
  friend UNIVERSAL_CHARSTRING operator+(const char *string_value,
    const UNIVERSAL_CHARSTRING_ELEMENT& other_value);

  struct charstring_struct;
  charstring_struct *val_ptr;

  void init_struct(int n_chars);
  void copy_value();
  CHARSTRING(int n_chars);
  
Elemer Lelik's avatar
Elemer Lelik committed
113
114
115
116
  /** An extended version of set_param(), which also accepts string patterns if
    * the second parameter is set (needed by CHARSTRING_template to concatenate
    * string patterns). 
    * @return TRUE, if the module parameter was a string pattern, otherwise FALSE */
117
118
  boolean set_param_internal(Module_Param& param, boolean allow_pattern,
    boolean* is_nocase_pattern = NULL);
Elemer Lelik's avatar
Elemer Lelik committed
119
  
Elemer Lelik's avatar
Elemer Lelik committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
public:
  /** Construct an unbound CHARSTRING object */
  CHARSTRING();
  /** Construct a CHARSTRING of length 1 */
  CHARSTRING(char other_value);
  /** Construct a CHARSTRING from the given C string.
   * @param chars_ptr may be NULL, resulting in an empty CHARSTRING */
  CHARSTRING(const char* chars_ptr);
  /** Construct a CHARSTRING of a given length.
   *
   * CHARSTRING(0,NULL) is the most efficient way to a bound, empty string.
   *
   * @param n_chars number of characters
   * @param chars_ptr pointer to string (does not need to be 0-terminated)
   * @pre at least \p n_chars are readable from \p chars_ptr */
  CHARSTRING(int n_chars, const char* chars_ptr);
  /** Copy constructor */
  CHARSTRING(const CHARSTRING& other_value);
  /** Construct a CHARSTRING of length one */
  CHARSTRING(const CHARSTRING_ELEMENT& other_value);
140
141
  /** Construct a CHARSTRING from a UNIVERSAL_CHARSTRING */
  CHARSTRING(const UNIVERSAL_CHARSTRING& other_value);
Elemer Lelik's avatar
Elemer Lelik committed
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

  /** Destructor. Simply calls clean_up() */
  ~CHARSTRING();
  void clean_up();

  CHARSTRING& operator=(const char* other_value);
  CHARSTRING& operator=(const CHARSTRING& other_value);
  CHARSTRING& operator=(const CHARSTRING_ELEMENT& other_value);
  CHARSTRING& operator=(const UNIVERSAL_CHARSTRING& other_value);

  boolean operator==(const char* other_value) const;
  boolean operator==(const CHARSTRING& other_value) const;
  boolean operator==(const CHARSTRING_ELEMENT& other_value) const;
  boolean operator==(const UNIVERSAL_CHARSTRING& other_value) const;
  boolean operator==(const UNIVERSAL_CHARSTRING_ELEMENT& other_value) const;

  inline boolean operator!=(const char* other_value) const
  { return !(*this == other_value); }
  inline boolean operator!=(const CHARSTRING& other_value) const
  { return !(*this == other_value); }
  inline boolean operator!=(const CHARSTRING_ELEMENT& other_value) const
  { return !(*this == other_value); }
164
165
166
167
  inline boolean operator!=(const UNIVERSAL_CHARSTRING& other_value) const
  { return !(*this == other_value); }
  inline boolean operator!=(const UNIVERSAL_CHARSTRING_ELEMENT& other_value) const
  { return !(*this == other_value); }
Elemer Lelik's avatar
Elemer Lelik committed
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

  CHARSTRING operator+(const char* other_value) const;
  CHARSTRING operator+(const CHARSTRING& other_value) const;
  CHARSTRING operator+(const CHARSTRING_ELEMENT& other_value) const;
  UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING& other_value) const;
  UNIVERSAL_CHARSTRING operator+
    (const UNIVERSAL_CHARSTRING_ELEMENT& other_value) const;

  CHARSTRING& operator+=(char other_value);
  CHARSTRING& operator+=(const char *other_value);
  CHARSTRING& operator+=(const CHARSTRING& other_value);
  CHARSTRING& operator+=(const CHARSTRING_ELEMENT& other_value);

  CHARSTRING operator<<=(int rotate_count) const;
  CHARSTRING operator<<=(const INTEGER& rotate_count) const;
  CHARSTRING operator>>=(int rotate_count) const;
  CHARSTRING operator>>=(const INTEGER& rotate_count) const;

  CHARSTRING_ELEMENT operator[](int index_value);
  CHARSTRING_ELEMENT operator[](const INTEGER& index_value);
  const CHARSTRING_ELEMENT operator[](int index_value) const;
  const CHARSTRING_ELEMENT operator[](const INTEGER& index_value) const;

  operator const char*() const;

  inline boolean is_bound() const { return val_ptr != NULL; }
  inline boolean is_value() const { return val_ptr != NULL; }
  inline void must_bound(const char *err_msg) const
    { if (val_ptr == NULL) TTCN_error("%s", err_msg); }

  int lengthof() const;

  void log() const;

#ifdef TITAN_RUNTIME_2
  boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const CHARSTRING*>(other_value)); }
  void set_value(const Base_Type* other_value) { *this = *(static_cast<const CHARSTRING*>(other_value)); }
  Base_Type* clone() const { return new CHARSTRING(*this); }
  const TTCN_Typedescriptor_t* get_descriptor() const { return &CHARSTRING_descr_; }
207
  Module_Param* get_param(Module_Param_Name& param_name) const;
Elemer Lelik's avatar
Elemer Lelik committed
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#else
  inline boolean is_present() const { return is_bound(); }
#endif

  /** Initializes this object with a module parameter value or concatenates a module
    * parameter value to the end of this string.
    * @note UFT-8 strings will be decoded. If the decoding results in multi-octet
    * characters an error will be thrown. */
  void set_param(Module_Param& param);

  void encode_text(Text_Buf& text_buf) const;
  void decode_text(Text_Buf& text_buf);

  void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
222
              int p_coding, ...) const;
Elemer Lelik's avatar
Elemer Lelik committed
223
224

  void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
225
              int p_coding, ...);
Elemer Lelik's avatar
Elemer Lelik committed
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242

  ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td,
                                unsigned p_coding) const;

  boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td,
                         const ASN_BER_TLV_t& p_tlv, unsigned L_form);

  /** Encodes the value of the variable according to the
    * TTCN_Typedescriptor_t. It must be public because called by
    * another types during encoding. Returns the length of encoded
    * data */
  int RAW_encode(const TTCN_Typedescriptor_t&, RAW_enc_tree&) const;
  /** Decodes the value of the variable according to the
    * TTCN_Typedescriptor_t. It must be public because called by
    * another types during encoding. Returns the number of decoded
    * bits */
  int RAW_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, int, raw_order_t,
243
                 boolean no_err=FALSE, int sel_field=-1, boolean first_call=TRUE, const RAW_Force_Omit* force_omit = NULL);
Elemer Lelik's avatar
Elemer Lelik committed
244
245
246
247
  int TEXT_encode(const TTCN_Typedescriptor_t&,
                 TTCN_Buffer&) const;
  int TEXT_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&,  Limit_Token_List&,
                  boolean no_err=FALSE, boolean first_call=TRUE);
248
  int XER_encode(const XERdescriptor_t&, TTCN_Buffer&, unsigned int, unsigned int, int, embed_values_enc_struct_t*) const;
Elemer Lelik's avatar
Elemer Lelik committed
249
  int XER_decode(const XERdescriptor_t&, XmlReaderWrap& reader, unsigned int, unsigned int, embed_values_dec_struct_t*);
Elemer Lelik's avatar
Elemer Lelik committed
250
251
252
253
254
255
256
257
  
  /** Returns the charstring in the format a string would appear in C or TTCN-3 code.
    * Inserts double quotation marks to the beginning and end of the string and
    * doubles the backlsashes in escaped characters.
    * Used for JSON encoding.
    * 
    * Example: "He said\nhis name was \"Al\"." -> "\"He said\\nhis name was \\\"Al\\\".\""
    * @note The returned character buffer needs to be freed after use. */
258
  char* to_JSON_string(json_string_escaping mode) const;
Elemer Lelik's avatar
Elemer Lelik committed
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
  
  /** Initializes the charstring with a JSON string value. 
    * The double quotation marks from the beginning and end of the JSON string are
    * removed and double-escaped characters are changed to simple-escaped ones. 
    * JSON characters stored as \u + 4 hex digits are converted to the characters
    * they represent.
    * Returns false if any non-charstring characters were found, otherwise true.
    * Used for JSON decoding.
    * 
    * Example: "\"He said\\nhis name was \\\"Al\\\".\"" -> "He said\nhis name was \"Al\"."
    * Example2: "\u0061" -> "a" 
    *
    * @param check_quotes turn the checking of double quotes (mentioned above) on or off */
  boolean from_JSON_string(const char* p_value, size_t p_value_len, boolean check_quotes);
  
  /** Encodes accordingly to the JSON encoding rules.
    * Returns the length of the encoded data. 
    * @note Since JSON has its own set of escaped characters, the ones in the
    * charstring need to be double-escaped. */
278
  int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean) const;
Elemer Lelik's avatar
Elemer Lelik committed
279
280
281
  
  /** Decodes accordingly to the JSON encoding rules.
    * Returns the length of the decoded data. */
282
  int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean, boolean, int p_chosen_field = CHOSEN_FIELD_UNSET);
Elemer Lelik's avatar
Elemer Lelik committed
283
  
284
285
286
287
  int OER_encode(const TTCN_Typedescriptor_t&, TTCN_Buffer&) const;
  
  int OER_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, OER_struct&);
  
Elemer Lelik's avatar
Elemer Lelik committed
288
289
#ifdef TITAN_RUNTIME_2
  virtual int encode_raw(TTCN_Buffer& p_buf) const;
Elemer Lelik's avatar
Elemer Lelik committed
290
291
292
293
  /** Adds this charstring to the end of a JSON buffer as raw data.
    * Used during the negative testing of the JSON encoder.
    * @return The number of bytes added. */
  int JSON_encode_negtest_raw(JSON_Tokenizer&) const;
Elemer Lelik's avatar
Elemer Lelik committed
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#endif
};

class CHARSTRING_ELEMENT {
  boolean bound_flag;
  CHARSTRING& str_val;
  int char_pos;

public:
  CHARSTRING_ELEMENT(boolean par_bound_flag, CHARSTRING& par_str_val,
                     int par_char_pos);

  CHARSTRING_ELEMENT& operator=(const char* other_value);
  CHARSTRING_ELEMENT& operator=(const CHARSTRING& other_value);
  CHARSTRING_ELEMENT& operator=(const CHARSTRING_ELEMENT& other_value);

  boolean operator==(const char *other_value) const;
  boolean operator==(const CHARSTRING& other_value) const;
  boolean operator==(const CHARSTRING_ELEMENT& other_value) const;
  boolean operator==(const UNIVERSAL_CHARSTRING& other_value) const;
  boolean operator==(const UNIVERSAL_CHARSTRING_ELEMENT& other_value) const;

  inline boolean operator!=(const char *other_value) const
  { return !(*this == other_value); }
  inline boolean operator!=(const CHARSTRING& other_value) const
  { return !(*this == other_value); }
  inline boolean operator!=(const CHARSTRING_ELEMENT& other_value) const
  { return !(*this == other_value); }

  CHARSTRING operator+(const char *other_value) const;
  CHARSTRING operator+(const CHARSTRING& other_value) const;
  CHARSTRING operator+(const CHARSTRING_ELEMENT& other_value) const;
  UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING& other_value) const;
  UNIVERSAL_CHARSTRING operator+
    (const UNIVERSAL_CHARSTRING_ELEMENT& other_value) const;

  inline boolean is_bound() const { return bound_flag; }
  inline boolean is_present() const { return bound_flag; }
  inline boolean is_value() const { return bound_flag; }
  inline void must_bound(const char *err_msg) const
    { if (!bound_flag) TTCN_error("%s", err_msg); }

  char get_char() const;

  void log() const;
};

extern boolean operator==(const char* string_value,
                          const CHARSTRING& other_value);
extern boolean operator==(const char* string_value,
                          const CHARSTRING_ELEMENT& other_value);

inline boolean operator!=(const char* string_value,
                          const CHARSTRING& other_value)
{
  return !(string_value == other_value);
}

inline boolean operator!=(const char* string_value,
                          const CHARSTRING_ELEMENT& other_value)
{
  return !(string_value == other_value);
}

extern CHARSTRING operator+(const char* string_value,
                            const CHARSTRING& other_value);
extern CHARSTRING operator+(const char* string_value,
                            const CHARSTRING_ELEMENT& other_value);

extern CHARSTRING operator<<=(const char *string_value,
                              const INTEGER& rotate_count);
extern CHARSTRING operator>>=(const char *string_value,
                              const INTEGER& rotate_count);

// charstring template class

370
371
struct unichar_decmatch_struct;

Elemer Lelik's avatar
Elemer Lelik committed
372
373
374
class CHARSTRING_template : public Restricted_Length_Template {

  friend class UNIVERSAL_CHARSTRING_template;
375
  
376
#ifdef TITAN_RUNTIME_2
377
378
379
380
381
382
383
384
385
386
387
388
389
  friend CHARSTRING_template operator+(const CHARSTRING& left_value,
    const CHARSTRING_template& right_template);
  friend CHARSTRING_template operator+(const CHARSTRING_ELEMENT& left_value,
    const CHARSTRING_template& right_template);
  friend UNIVERSAL_CHARSTRING_template operator+(
    const UNIVERSAL_CHARSTRING& left_value,
    const CHARSTRING_template& right_template);
  friend UNIVERSAL_CHARSTRING_template operator+(
    const UNIVERSAL_CHARSTRING_ELEMENT& left_value,
    const CHARSTRING_template& right_template);
  friend UNIVERSAL_CHARSTRING_template operator+(
    const CHARSTRING_template& left_template,
    const UNIVERSAL_CHARSTRING_template& right_template);
390
#endif
Elemer Lelik's avatar
Elemer Lelik committed
391
392
393
394
395
396
397
398
399
400

private:
  CHARSTRING single_value;
  union {
    struct {
      unsigned int n_values;
      CHARSTRING_template *list_value;
    } value_list;
    struct {
      boolean min_is_set, max_is_set;
401
      boolean min_is_exclusive, max_is_exclusive;
Elemer Lelik's avatar
Elemer Lelik committed
402
403
404
405
406
      char min_value, max_value;
    } value_range;
    mutable struct {
      boolean regexp_init;
      regex_t posix_regexp;
407
      boolean nocase;
Elemer Lelik's avatar
Elemer Lelik committed
408
    } pattern_value;
409
    unichar_decmatch_struct* dec_match;
Elemer Lelik's avatar
Elemer Lelik committed
410
411
412
  };

  void copy_template(const CHARSTRING_template& other_value);
413
  static void log_pattern(int n_chars, const char *chars_ptr, boolean nocase);
Elemer Lelik's avatar
Elemer Lelik committed
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438

public:
  CHARSTRING_template();
  /** Constructor for any/omit/any-or-omit
   * @param other_value must be ANY_VALUE, OMIT_VALUE or ANY_OR_OMIT
   */
  CHARSTRING_template(template_sel other_value);
  /** Construct from a string
   * @post template_selection is SPECIFIC_VALUE
   * @param other_value
   */
  CHARSTRING_template(const CHARSTRING& other_value);
  /** Construct from a one-character string (result of CHARSTRING::op[])
   * @post template_selection is SPECIFIC_VALUE
   * @param other_value
   */
  CHARSTRING_template(const CHARSTRING_ELEMENT& other_value);
  /** Construct from an optional string
   * @post template_selection is SPECIFIC_VALUE or OMIT_VALUE
   * @param other_value
   */
  CHARSTRING_template(const OPTIONAL<CHARSTRING>& other_value);
  /** Constructor for STRING_PATTERN
   * @param p_sel must be STRING_PATTERN or else Dynamic Testcase Error
   * @param p_str pattern string
439
   * @param p_nocase case sensitivity (FALSE = case sensitive)
Elemer Lelik's avatar
Elemer Lelik committed
440
   */
441
442
  CHARSTRING_template(template_sel p_sel, const CHARSTRING& p_str,
    boolean p_nocase = FALSE);
Elemer Lelik's avatar
Elemer Lelik committed
443
444
445
446
447
448
449
450
451
452
453
  /// Copy constructor
  CHARSTRING_template(const CHARSTRING_template& other_value);

  ~CHARSTRING_template();
  void clean_up();

  CHARSTRING_template& operator=(template_sel other_value);
  CHARSTRING_template& operator=(const CHARSTRING& other_value);
  CHARSTRING_template& operator=(const CHARSTRING_ELEMENT& other_value);
  CHARSTRING_template& operator=(const OPTIONAL<CHARSTRING>& other_value);
  CHARSTRING_template& operator=(const CHARSTRING_template& other_value);
454
  
455
#ifdef TITAN_RUNTIME_2
456
457
458
459
460
461
462
  CHARSTRING_template operator+(const CHARSTRING_template& other_value) const;
  CHARSTRING_template operator+(const CHARSTRING& other_value) const;
  CHARSTRING_template operator+(const CHARSTRING_ELEMENT& other_value) const;
  UNIVERSAL_CHARSTRING_template operator+(
    const UNIVERSAL_CHARSTRING& other_value) const;
  UNIVERSAL_CHARSTRING_template operator+(
    const UNIVERSAL_CHARSTRING_ELEMENT& other_value) const;
463
#endif
Elemer Lelik's avatar
Elemer Lelik committed
464
465
466
467
468
469

  CHARSTRING_ELEMENT operator[](int index_value);
  CHARSTRING_ELEMENT operator[](const INTEGER& index_value);
  const CHARSTRING_ELEMENT operator[](int index_value) const;
  const CHARSTRING_ELEMENT operator[](const INTEGER& index_value) const;

Elemer Lelik's avatar
Elemer Lelik committed
470
  boolean match(const CHARSTRING& other_value, boolean legacy = FALSE) const;
Elemer Lelik's avatar
Elemer Lelik committed
471
472
473
474
475
476
  const CHARSTRING& valueof() const;

  int lengthof() const;

  void set_type(template_sel template_type, unsigned int list_length = 0);
  CHARSTRING_template& list_item(unsigned int list_index);
477
  
Elemer Lelik's avatar
Elemer Lelik committed
478
479
  void set_min(const CHARSTRING& min_value);
  void set_max(const CHARSTRING& max_value);
480
481
  void set_min_exclusive(boolean min_exclusive);
  void set_max_exclusive(boolean max_exclusive);
482
483
  
  void set_decmatch(Dec_Match_Interface* new_instance);
484
485
  
  void* get_decmatch_dec_res() const;
486
  const TTCN_Typedescriptor_t* get_decmatch_type_descr() const;
Elemer Lelik's avatar
Elemer Lelik committed
487
488

  void log() const;
Elemer Lelik's avatar
Elemer Lelik committed
489
  void log_match(const CHARSTRING& match_value, boolean legacy = FALSE) const;
Elemer Lelik's avatar
Elemer Lelik committed
490
491
492
493
494
495

  void set_param(Module_Param& param);

  void encode_text(Text_Buf& text_buf) const;
  void decode_text(Text_Buf& text_buf);

Elemer Lelik's avatar
Elemer Lelik committed
496
497
  boolean is_present(boolean legacy = FALSE) const;
  boolean match_omit(boolean legacy = FALSE) const;
Elemer Lelik's avatar
Elemer Lelik committed
498
#ifdef TITAN_RUNTIME_2
499
  Module_Param* get_param(Module_Param_Name& param_name) const;
Elemer Lelik's avatar
Elemer Lelik committed
500
501
502
503
504
  void valueofv(Base_Type* value) const { *(static_cast<CHARSTRING*>(value)) = valueof(); }
  void set_value(template_sel other_value) { *this = other_value; }
  void copy_value(const Base_Type* other_value) { *this = *(static_cast<const CHARSTRING*>(other_value)); }
  Base_Template* clone() const { return new CHARSTRING_template(*this); }
  const TTCN_Typedescriptor_t* get_descriptor() const { return &CHARSTRING_descr_; }
Elemer Lelik's avatar
Elemer Lelik committed
505
506
  boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const CHARSTRING*>(other_value)), legacy); }
  void log_matchv(const Base_Type* match_value, boolean legacy) const  { log_match(*(static_cast<const CHARSTRING*>(match_value)), legacy); }
Elemer Lelik's avatar
Elemer Lelik committed
507
#else
Elemer Lelik's avatar
Elemer Lelik committed
508
  void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
Elemer Lelik's avatar
Elemer Lelik committed
509
510
511
512
513
514
515
#endif

  /** Returns the single_value member
   *  @pre template_selection is SPECIFIC_VALUE or STRING_PATTERN */
  const CHARSTRING& get_single_value() const;
};

516
#ifdef TITAN_RUNTIME_2
517
518
519
520
521
522
523
524
525
526
extern CHARSTRING_template operator+(const CHARSTRING& left_value,
  const CHARSTRING_template& right_template);
extern CHARSTRING_template operator+(const CHARSTRING_ELEMENT& left_value,
  const CHARSTRING_template& right_template);
extern UNIVERSAL_CHARSTRING_template operator+(
  const UNIVERSAL_CHARSTRING& left_value,
  const CHARSTRING_template& right_template);
extern UNIVERSAL_CHARSTRING_template operator+(
  const UNIVERSAL_CHARSTRING_ELEMENT& left_value,
  const CHARSTRING_template& right_template);
527
#endif
528

Elemer Lelik's avatar
Elemer Lelik committed
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
typedef CHARSTRING NumericString;
typedef CHARSTRING PrintableString;
typedef CHARSTRING IA5String;
typedef CHARSTRING VisibleString;
typedef VisibleString ISO646String;

typedef CHARSTRING_template NumericString_template;
typedef CHARSTRING_template PrintableString_template;
typedef CHARSTRING_template IA5String_template;
typedef CHARSTRING_template VisibleString_template;
typedef VisibleString_template ISO646String_template;

typedef VisibleString ASN_GeneralizedTime;
typedef VisibleString ASN_UTCTime;

typedef VisibleString_template ASN_GeneralizedTime_template;
typedef VisibleString_template ASN_UTCTime_template;

// Only for backward compatibility
typedef CHARSTRING CHAR;
typedef CHARSTRING_template CHAR_template;

// TTCN_TYPE is a class that represents a ttcn-3 value or template
template<typename TTCN_TYPE>
CHARSTRING ttcn_to_string(const TTCN_TYPE& ttcn_data) {
  Logger_Format_Scope logger_format(TTCN_Logger::LF_TTCN);
  TTCN_Logger::begin_event_log2str();
  ttcn_data.log();
  return TTCN_Logger::end_event_log2str();
}

template<typename TTCN_TYPE>
void string_to_ttcn(const CHARSTRING& ttcn_string, TTCN_TYPE& ttcn_value) {
  Module_Param* parsed_mp = process_config_string2ttcn((const char*)ttcn_string, ttcn_value.is_component());
  try {
    Ttcn_String_Parsing ttcn_string_parsing;
    ttcn_value.set_param(*parsed_mp);
    delete parsed_mp;
  }
  catch (...) {
    delete parsed_mp;
    throw;
  }
}

#endif