Merge pull request #10 from egerpil/master
[deliverable/titan.core.git] / core / Verdicttype.hh
CommitLineData
970ed795 1///////////////////////////////////////////////////////////////////////////////
3abe9331 2// Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
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 VERDICTTYPE_HH
9#define VERDICTTYPE_HH
10
11#include "Basetype.hh"
12#include "Template.hh"
13#include "Optional.hh"
14
15class Module_Param;
16
17/// verdicttype value class
18
19class VERDICTTYPE: public Base_Type {
20 friend class VERDICTTYPE_template;
21 friend boolean operator==(verdicttype par_value,
22 const VERDICTTYPE& other_value);
23
24 verdicttype verdict_value;
25 verdicttype str_to_verdict(const char *v, boolean silent = false);
26public:
27 /** Default constructor.
28 * Initialises \p verdict_value to UNBOUND_VERDICT, a private macro
29 * outside the range of \p verdicttype enum.
30 *
31 * @post \p is_bound() would return \p false */
32 VERDICTTYPE();
33 VERDICTTYPE(verdicttype other_value);
34 VERDICTTYPE(const VERDICTTYPE& other_value);
35
36 VERDICTTYPE& operator=(verdicttype other_value);
37 VERDICTTYPE& operator=(const VERDICTTYPE& other_value);
38
39 boolean operator==(verdicttype other_value) const;
40 boolean operator==(const VERDICTTYPE& other_value) const;
41 inline boolean operator!=(verdicttype other_value) const
42 {
43 return !(*this == other_value);
44 }
45 inline boolean operator!=(const VERDICTTYPE& other_value) const
46 {
47 return !(*this == other_value);
48 }
49
50 operator verdicttype() const;
51
52 inline boolean is_bound() const
53 {
54 return verdict_value >= NONE && verdict_value <= ERROR;
55 }
56 inline boolean is_value() const
57 {
58 return is_bound();
59 }
60 void clean_up();
61
62#ifdef TITAN_RUNTIME_2
63 boolean is_equal(const Base_Type* other_value) const {return *this == *(static_cast<const VERDICTTYPE*>(other_value));}
64 void set_value(const Base_Type* other_value) {*this = *(static_cast<const VERDICTTYPE*>(other_value));}
65 Base_Type* clone() const {return new VERDICTTYPE(*this);}
66 const TTCN_Typedescriptor_t* get_descriptor() const {return &VERDICTTYPE_descr_;}
67#else
68 inline boolean is_present() const { return is_bound(); }
69#endif
70
71 void log() const;
72
73 void set_param(Module_Param& param);
3abe9331 74 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
75
76 void encode_text(Text_Buf& text_buf) const;
77 void decode_text(Text_Buf& text_buf);
78
79 void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
80 TTCN_EncDec::coding_t p_coding, ...) const;
81
82 void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
83 TTCN_EncDec::coding_t p_coding, ...);
84
85 int XER_encode(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf,
af710487 86 unsigned int flavor, int indent, embed_values_enc_struct_t*) const;
970ed795 87 int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
feade998 88 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*);
970ed795
EL
89
90 /** Encodes accordingly to the JSON encoding rules.
91 * Returns the length of the encoded data. */
92 int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const;
93
94 /** Decodes accordingly to the JSON encoding rules.
95 * Returns the length of the decoded data. */
96 int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean);
97};
98
99inline boolean operator==(verdicttype par_value, verdicttype other_value)
100{
101 return (int) par_value == (int) other_value;
102}
103
104inline boolean operator!=(verdicttype par_value, verdicttype other_value)
105{
106 return (int) par_value != (int) other_value;
107}
108
109extern boolean operator==(verdicttype par_value, const VERDICTTYPE& other_value);
110
111inline boolean operator!=(verdicttype par_value, const VERDICTTYPE& other_value)
112{
113 return !(par_value == other_value);
114}
115
116// verdicttype template class
117
118class VERDICTTYPE_template: public Base_Template {
119 union {
120 verdicttype single_value;
121 struct {
122 unsigned int n_values;
123 VERDICTTYPE_template *list_value;
124 } value_list;
125 };
126
127 void copy_value(const VERDICTTYPE& other_value);
128 void copy_template(const VERDICTTYPE_template& other_value);
129
130public:
131 VERDICTTYPE_template();
132 VERDICTTYPE_template(template_sel other_value);
133 VERDICTTYPE_template(verdicttype other_value);
134 VERDICTTYPE_template(const VERDICTTYPE& other_value);
135 VERDICTTYPE_template(const OPTIONAL<VERDICTTYPE>& other_value);
136 VERDICTTYPE_template(const VERDICTTYPE_template& other_value);
137
138 ~VERDICTTYPE_template();
139 void clean_up();
140
141 VERDICTTYPE_template& operator=(template_sel other_value);
142 VERDICTTYPE_template& operator=(verdicttype other_value);
143 VERDICTTYPE_template& operator=(const VERDICTTYPE& other_value);
144 VERDICTTYPE_template& operator=(const OPTIONAL<VERDICTTYPE>& other_value);
145 VERDICTTYPE_template& operator=(const VERDICTTYPE_template& other_value);
146
3abe9331 147 boolean match(verdicttype other_value, boolean legacy = FALSE) const;
148 boolean match(const VERDICTTYPE& other_value, boolean legacy = FALSE) const;
970ed795
EL
149 verdicttype valueof() const;
150
151 void set_type(template_sel template_type, unsigned int list_length);
152 VERDICTTYPE_template& list_item(unsigned int list_index);
153
154 void log() const;
3abe9331 155 void log_match(const VERDICTTYPE& match_value, boolean legacy = FALSE) const;
970ed795
EL
156
157 void set_param(Module_Param& param);
3abe9331 158 Module_Param* get_param(Module_Param_Name& param_name) const;
970ed795
EL
159
160 void encode_text(Text_Buf& text_buf) const;
161 void decode_text(Text_Buf& text_buf);
162
3abe9331 163 boolean is_present(boolean legacy = FALSE) const;
164 boolean match_omit(boolean legacy = FALSE) const;
970ed795
EL
165#ifdef TITAN_RUNTIME_2
166 void valueofv(Base_Type* value) const {*(static_cast<VERDICTTYPE*>(value)) = valueof();}
167 void set_value(template_sel other_value) {*this = other_value;}
168 void copy_value(const Base_Type* other_value) {*this = *(static_cast<const VERDICTTYPE*>(other_value));}
169 Base_Template* clone() const {return new VERDICTTYPE_template(*this);}
170 const TTCN_Typedescriptor_t* get_descriptor() const {return &VERDICTTYPE_descr_;}
3abe9331 171 boolean matchv(const Base_Type* other_value, boolean legacy) const {return match(*(static_cast<const VERDICTTYPE*>(other_value)), legacy);}
172 void log_matchv(const Base_Type* match_value, boolean legacy) const {log_match(*(static_cast<const VERDICTTYPE*>(match_value)), legacy);}
970ed795 173#else
3abe9331 174 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
970ed795
EL
175#endif
176};
177
178#endif
This page took 0.033577 seconds and 5 git commands to generate.