38c0a00112706c3010c8ab24e92a6aadf7c10e5e
[deliverable/titan.core.git] / core / Objid.hh
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 OBJID_HH
9 #define OBJID_HH
10
11 #include "Optional.hh"
12 // the following are pulled in by Optional.hh:
13 //#include "Basetype.hh"
14 //#include "Template.hh"
15
16 class Text_Buf;
17 class Module_Param;
18 class INTEGER;
19
20 /** Runtime class for object identifiers (objid)
21 *
22 */
23 class OBJID : public Base_Type {
24 /** No user serviceable parts. */
25 struct objid_struct;
26 objid_struct *val_ptr;
27
28 void init_struct(int n_components);
29 void copy_value();
30
31 /** Initializes the object identifier with a string containing the components
32 * separated by dots. */
33 void from_string(char* p_str);
34
35 public:
36 typedef unsigned int objid_element;
37 OBJID();
38 OBJID(int init_n_components, ...);
39 OBJID(int init_n_components, const objid_element *init_components);
40 OBJID(const OBJID& other_value);
41
42 ~OBJID();
43
44 OBJID& operator=(const OBJID& other_value);
45
46 boolean operator==(const OBJID& other_value) const;
47 inline boolean operator!=(const OBJID& other_value) const
48 { return !(*this == other_value); }
49
50 objid_element& operator[](int index_value);
51 objid_element operator[](int index_value) const;
52
53 inline boolean is_bound() const { return val_ptr != NULL; }
54 inline boolean is_value() const { return val_ptr != NULL; }
55 void clean_up();
56
57 int size_of() const;
58 int lengthof() const { return size_of(); } // for backward compatibility
59
60 operator const objid_element*() const;
61
62 static objid_element from_INTEGER(const INTEGER& p_int);
63
64 #ifdef TITAN_RUNTIME_2
65 boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const OBJID*>(other_value)); }
66 void set_value(const Base_Type* other_value) { *this = *(static_cast<const OBJID*>(other_value)); }
67 Base_Type* clone() const { return new OBJID(*this); }
68 const TTCN_Typedescriptor_t* get_descriptor() const { return &OBJID_descr_; }
69 #else
70 inline boolean is_present() const { return is_bound(); }
71 #endif
72
73 void log() const;
74
75 void set_param(Module_Param& param);
76 Module_Param* get_param(Module_Param_Name& param_name) const;
77
78 void encode_text(Text_Buf& text_buf) const;
79 void decode_text(Text_Buf& text_buf);
80
81 void encode(const TTCN_Typedescriptor_t&, TTCN_Buffer&,
82 TTCN_EncDec::coding_t, ...) const;
83
84 void decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&,
85 TTCN_EncDec::coding_t, ...);
86
87 ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td,
88 unsigned p_coding) const;
89
90 boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td,
91 const ASN_BER_TLV_t& p_tlv, unsigned L_form);
92 int XER_encode(const XERdescriptor_t& p_td,
93 TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t*) const;
94 int XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
95 unsigned int flavor, unsigned int flavor2, embed_values_dec_struct_t*);
96
97 /** Encodes accordingly to the JSON encoding rules.
98 * Returns the length of the encoded data. */
99 int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const;
100
101 /** Decodes accordingly to the JSON decoding rules.
102 * Returns the length of the encoded data. */
103 int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean);
104 };
105
106 // objid template class
107
108 class OBJID_template : public Base_Template {
109 OBJID single_value;
110 struct {
111 unsigned int n_values;
112 OBJID_template *list_value;
113 } value_list;
114
115 void copy_template(const OBJID_template& other_value);
116
117 public:
118 OBJID_template();
119 OBJID_template(template_sel other_value);
120 OBJID_template(const OBJID& other_value);
121 OBJID_template(const OPTIONAL<OBJID>& other_value);
122 OBJID_template(const OBJID_template& other_value);
123
124 ~OBJID_template();
125 void clean_up();
126
127 OBJID_template& operator=(template_sel other_value);
128 OBJID_template& operator=(const OBJID& other_value);
129 OBJID_template& operator=(const OPTIONAL<OBJID>& other_value);
130 OBJID_template& operator=(const OBJID_template& other_value);
131
132 boolean match(const OBJID& other_value, boolean legacy = FALSE) const;
133 const OBJID& valueof() const;
134
135 int size_of() const;
136
137 void set_type(template_sel template_type, unsigned int list_length);
138 OBJID_template& list_item(unsigned int list_index);
139
140 void log() const;
141 void log_match(const OBJID& match_value, boolean legacy = FALSE) const;
142
143 void set_param(Module_Param& param);
144 Module_Param* get_param(Module_Param_Name& param_name) const;
145
146 void encode_text(Text_Buf& text_buf) const;
147 void decode_text(Text_Buf& text_buf);
148
149 boolean is_present(boolean legacy = FALSE) const;
150 boolean match_omit(boolean legacy = FALSE) const;
151 #ifdef TITAN_RUNTIME_2
152 void valueofv(Base_Type* value) const { *(static_cast<OBJID*>(value)) = valueof(); }
153 void set_value(template_sel other_value) { *this = other_value; }
154 void copy_value(const Base_Type* other_value) { *this = *(static_cast<const OBJID*>(other_value)); }
155 Base_Template* clone() const { return new OBJID_template(*this); }
156 const TTCN_Typedescriptor_t* get_descriptor() const { return &OBJID_descr_; }
157 boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const OBJID*>(other_value)), legacy); }
158 void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const OBJID*>(match_value)), legacy); }
159 #else
160 void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const;
161 #endif
162 };
163
164 typedef OBJID ASN_ROID;
165 typedef OBJID_template ASN_ROID_template;
166
167 #endif
This page took 0.034321 seconds and 5 git commands to generate.