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

#include "Types.h"
#include "Basetype.hh"
#include "Template.hh"
#include "Error.hh"

class Module_Param;

32
33
34
template<typename T>
class OPTIONAL;

Elemer Lelik's avatar
Elemer Lelik committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class BOOLEAN : public Base_Type {
  friend class BOOLEAN_template;

  friend boolean operator&&(boolean bool_value, const BOOLEAN& other_value);
  friend boolean operator^(boolean bool_value, const BOOLEAN& other_value);
  friend boolean operator||(boolean bool_value, const BOOLEAN& other_value);
  friend boolean operator==(boolean bool_value, const BOOLEAN& other_value);

  boolean bound_flag;
  boolean boolean_value;

public:
  BOOLEAN();
  BOOLEAN(boolean other_value);
  BOOLEAN(const BOOLEAN& other_value);

  BOOLEAN& operator=(boolean other_value);
  BOOLEAN& operator=(const BOOLEAN& other_value);

  boolean operator!() const;
  boolean operator&&(boolean other_value) const;
  boolean operator&&(const BOOLEAN& other_value) const;
  boolean operator^(boolean other_value) const;
  boolean operator^(const BOOLEAN& other_value) const;
  boolean operator||(const BOOLEAN& other_value) const;
  boolean operator||(boolean other_value) const;

  boolean operator==(boolean other_value) const;
  boolean operator==(const BOOLEAN& other_value) const;

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

  operator boolean() const;

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

#ifdef TITAN_RUNTIME_2
  boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const BOOLEAN*>(other_value)); }
  void set_value(const Base_Type* other_value) { *this = *(static_cast<const BOOLEAN*>(other_value)); }
  Base_Type* clone() const { return new BOOLEAN(*this); }
  const TTCN_Typedescriptor_t* get_descriptor() const { return &BOOLEAN_descr_; }
83
  Module_Param* get_param(Module_Param_Name& param_name) const;
Elemer Lelik's avatar
Elemer Lelik committed
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
113
114
115
116
117
118
119
120
121
#else
  inline boolean is_present() const { return is_bound(); }
#endif

  void log() const;

  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,
              TTCN_EncDec::coding_t p_coding, ...) const;

  void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
              TTCN_EncDec::coding_t p_coding, ...);

  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,
                 boolean no_err=FALSE, int sel_field=-1, boolean first_call=TRUE);
  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);
  int XER_encode(const XERdescriptor_t& p_td,
122
                 TTCN_Buffer& p_buf, unsigned int flavor, unsigned int flavor2, int indent, embed_values_enc_struct_t*) const;
Elemer Lelik's avatar
Elemer Lelik committed
123
  int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
Elemer Lelik's avatar
Elemer Lelik committed
124
                 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*);
Elemer Lelik's avatar
Elemer Lelik committed
125
126
127
128
129
130
131
  
  /** Encodes accordingly to the JSON encoding rules.
    * Returns the length of the encoded data. */
  int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const;
  
  /** Decodes accordingly to the JSON encoding rules.
    * Returns the length of the decoded data. */
132
  int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean, int p_chosen_field = CHOSEN_FIELD_UNSET);
133
134
135
136
137
138
139
  
  /** Encodes accordingly to the OER encoding rules.
    * Returns the length of the encoded data. */
  int OER_encode(const TTCN_Typedescriptor_t&, TTCN_Buffer& p_buf) const;
  
  /** Decodes accordingly to the OER encoding rules.
    * Returns the length of the decoded data. */
140
  int OER_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer& p_buf, OER_struct&);
Elemer Lelik's avatar
Elemer Lelik committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
};

extern boolean operator&&(boolean bool_value, const BOOLEAN& other_value);
extern boolean operator^(boolean bool_value, const BOOLEAN& other_value);
extern boolean operator||(boolean bool_value, const BOOLEAN& other_value);

extern boolean operator==(boolean bool_value, const BOOLEAN& other_value);
inline boolean operator!=(boolean bool_value, const BOOLEAN& other_value)
  { return !(bool_value == other_value); }


// boolean template class


class BOOLEAN_template : public Base_Template {
  union {
    boolean single_value;
    struct {
      unsigned int n_values;
      BOOLEAN_template *list_value;
    } value_list;
  };

  void copy_template(const BOOLEAN_template& other_value);

public:

  BOOLEAN_template();
  BOOLEAN_template(template_sel other_value);
  BOOLEAN_template(boolean other_value);
  BOOLEAN_template(const BOOLEAN& other_value);
  BOOLEAN_template(const OPTIONAL<BOOLEAN>& other_value);
  BOOLEAN_template(const BOOLEAN_template& other_value);

  ~BOOLEAN_template();
  void clean_up();

  BOOLEAN_template& operator=(template_sel other_value);
  BOOLEAN_template& operator=(boolean other_value);
  BOOLEAN_template& operator=(const BOOLEAN& other_value);
  BOOLEAN_template& operator=(const OPTIONAL<BOOLEAN>& other_value);
  BOOLEAN_template& operator=(const BOOLEAN_template& other_value);

Elemer Lelik's avatar
Elemer Lelik committed
184
185
  boolean match(boolean other_value, boolean legacy = FALSE) const;
  boolean match(const BOOLEAN& other_value, boolean legacy = FALSE) const;
Elemer Lelik's avatar
Elemer Lelik committed
186
187
188
189
190
191
  boolean valueof() const;

  void set_type(template_sel template_type, unsigned int list_length);
  BOOLEAN_template& list_item(unsigned int list_index);

  void log() const;
Elemer Lelik's avatar
Elemer Lelik committed
192
  void log_match(const BOOLEAN& match_value, boolean legacy = FALSE) const;
Elemer Lelik's avatar
Elemer Lelik committed
193
194
195
196
197
198

  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
199
200
  boolean is_present(boolean legacy = FALSE) const;
  boolean match_omit(boolean legacy = FALSE) const;
Elemer Lelik's avatar
Elemer Lelik committed
201
#ifdef TITAN_RUNTIME_2
202
  Module_Param* get_param(Module_Param_Name& param_name) const;
Elemer Lelik's avatar
Elemer Lelik committed
203
204
205
206
207
  void valueofv(Base_Type* value) const { *(static_cast<BOOLEAN*>(value)) = valueof(); }
  void set_value(template_sel other_value) { *this = other_value; }
  void copy_value(const Base_Type* other_value) { *this = *(static_cast<const BOOLEAN*>(other_value)); }
  Base_Template* clone() const { return new BOOLEAN_template(*this); }
  const TTCN_Typedescriptor_t* get_descriptor() const { return &BOOLEAN_descr_; }
Elemer Lelik's avatar
Elemer Lelik committed
208
209
  boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const BOOLEAN*>(other_value)), legacy); }
  void log_matchv(const Base_Type* match_value, boolean legacy) const  { log_match(*(static_cast<const BOOLEAN*>(match_value)), legacy); }
Elemer Lelik's avatar
Elemer Lelik committed
210
#else
Elemer Lelik's avatar
Elemer Lelik committed
211
  void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
Elemer Lelik's avatar
Elemer Lelik committed
212
213
214
215
#endif
};

#endif