// This C++ source file was generated by the TTCN-3 compiler
// of the TTCN-3 Test Executor version 11.1.0
// The generation of user and time information were disabled by the -D flag.

// Copyright (c) 2000-2025 Ericsson Telecom AB

// Do not edit this file unless you know what you are doing.

/* Including header files */

#include "Q931_Types.hh"

namespace Q931__Types {

/* Literal string constants */

const unsigned char module_checksum[] = { 0x18, 0x98, 0x40, 0xcf, 0xbb, 0xa3, 0xcf, 0x3f, 0x1d, 0x9d, 0xbd, 0x82, 0xc2, 0xfb, 0x82, 0xfd };

/* Global variable definitions */

const TTCN_RAWdescriptor_t Q931__MessageType_raw_ = {8,SG_NO,ORDER_LSB,ORDER_LSB,ORDER_LSB,ORDER_LSB,EXT_BIT_NO,ORDER_LSB,ORDER_LSB,TOP_BIT_INHERITED,0,0,0,8,0,NULL,-1,CharCoding::UNKNOWN_CHAR_CODING,NULL,false};
// No XER for Q931__MessageType
const TTCN_Typedescriptor_t Q931__MessageType_descr_ = { "@Q931_Types.Q931_MessageType", NULL, &Q931__MessageType_raw_, NULL, NULL, NULL, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE };
UNIVERSAL_CHARSTRING Q931__MessageType_default_coding("RAW");
TTCN_Module module_object("Q931_Types", __DATE__, __TIME__, module_checksum, NULL, NULL, 0U, 4294967295U, 4294967295U, 4294967295U, NULL, 0LU, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

const RuntimeVersionChecker ver_checker(  current_runtime_version.requires_major_version_11,
  current_runtime_version.requires_minor_version_1,
  current_runtime_version.requires_patch_level_0,  current_runtime_version.requires_runtime_1);

/* Member functions of C++ classes */

Q931__MessageType::Q931__MessageType()
{
enum_value = UNBOUND_VALUE;
}

Q931__MessageType::Q931__MessageType(int other_value)
{
if (!is_valid_enum(other_value)) TTCN_error("Initializing a variable of enumerated type @Q931_Types.Q931_MessageType with invalid numeric value %d.", other_value);
enum_value = (enum_type)other_value;
}

Q931__MessageType::Q931__MessageType(enum_type other_value)
{
enum_value = other_value;
}

Q931__MessageType::Q931__MessageType(const Q931__MessageType& other_value)
: Base_Type()
{
if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("Copying an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
enum_value = other_value.enum_value;
}

Q931__MessageType& Q931__MessageType::operator=(int other_value)
{
if (!is_valid_enum(other_value)) TTCN_error("Assigning unknown numeric value %d to a variable of enumerated type @Q931_Types.Q931_MessageType.", other_value);
enum_value = (enum_type)other_value;
return *this;
}

Q931__MessageType& Q931__MessageType::operator=(enum_type other_value)
{
enum_value = other_value;
return *this;
}

Q931__MessageType& Q931__MessageType::operator=(const Q931__MessageType& other_value)
{
if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("Assignment of an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
enum_value = other_value.enum_value;
return *this;
}

boolean Q931__MessageType::operator==(int other_value) const
{
if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
if (!is_valid_enum(other_value)) TTCN_error("The right operand of enumerated type @Q931_Types.Q931_MessageType comparison is an unknown numeric value %d", other_value);
return enum_value == other_value;
}

boolean Q931__MessageType::operator==(enum_type other_value) const
{
if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
return enum_value == other_value;
}

boolean Q931__MessageType::operator==(const Q931__MessageType& other_value) const
{
if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("The right operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
return enum_value == other_value.enum_value;
}

boolean Q931__MessageType::operator<(int other_value) const
{
if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
if (!is_valid_enum(other_value)) TTCN_error("The right operand of enumerated type @Q931_Types.Q931_MessageType comparison is an unknown numeric value %d", other_value);
return enum_value < other_value;
}

boolean Q931__MessageType::operator<(enum_type other_value) const
{
if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
return enum_value < other_value;
}

boolean Q931__MessageType::operator<(const Q931__MessageType& other_value) const
{
if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("The right operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
return enum_value < other_value.enum_value;
}

boolean Q931__MessageType::operator>(int other_value) const
{
if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
if (!is_valid_enum(other_value)) TTCN_error("The right operand of enumerated type @Q931_Types.Q931_MessageType comparison is an unknown numeric value %d", other_value);
return enum_value > other_value;
}

boolean Q931__MessageType::operator>(enum_type other_value) const
{
if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
return enum_value > other_value;
}

boolean Q931__MessageType::operator>(const Q931__MessageType& other_value) const
{
if (enum_value == UNBOUND_VALUE) TTCN_error("The left operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
if (other_value.enum_value == UNBOUND_VALUE) TTCN_error("The right operand of comparison is an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
return enum_value > other_value.enum_value;
}

const char *Q931__MessageType::enum_to_str(enum_type enum_par)
{
switch (enum_par) {
case Q931__MSGT__ALERTING: return "Q931_MSGT_ALERTING";
case Q931__MSGT__CALL__PROCEEDING: return "Q931_MSGT_CALL_PROCEEDING";
case Q931__MSGT__CONNECT: return "Q931_MSGT_CONNECT";
case Q931__MSGT__CONNECT__ACK: return "Q931_MSGT_CONNECT_ACK";
case Q931__MSGT__PROGRESS: return "Q931_MSGT_PROGRESS";
case Q931__MSGT__SETUP: return "Q931_MSGT_SETUP";
case Q931__MSGT__SETUP__ACK: return "Q931_MSGT_SETUP_ACK";
case Q931__MSGT__RESUME: return "Q931_MSGT_RESUME";
case Q931__MSGT__RESUME__ACK: return "Q931_MSGT_RESUME_ACK";
case Q931__MSGT__RESUME__REJ: return "Q931_MSGT_RESUME_REJ";
case Q931__MSGT__SUSPEND: return "Q931_MSGT_SUSPEND";
case Q931__MSGT__SUSPEND__ACK: return "Q931_MSGT_SUSPEND_ACK";
case Q931__MSGT__SUSPEND__REJ: return "Q931_MSGT_SUSPEND_REJ";
case Q931__MSGT__USER__INFO: return "Q931_MSGT_USER_INFO";
case Q931__MSGT__DISCONNECT: return "Q931_MSGT_DISCONNECT";
case Q931__MSGT__RELEASE: return "Q931_MSGT_RELEASE";
case Q931__MSGT__RELEASE__COMPL: return "Q931_MSGT_RELEASE_COMPL";
case Q931__MSGT__RESTART: return "Q931_MSGT_RESTART";
case Q931__MSGT__RESTART__ACK: return "Q931_MSGT_RESTART_ACK";
case Q931__MSGT__SEGMENT: return "Q931_MSGT_SEGMENT";
case Q931__MSGT__CONGESTION__CTRL: return "Q931_MSGT_CONGESTION_CTRL";
case Q931__MSGT__INFORMATION: return "Q931_MSGT_INFORMATION";
case Q931__MSGT__NOTIFY: return "Q931_MSGT_NOTIFY";
case Q931__MSGT__STATUS: return "Q931_MSGT_STATUS";
case Q931__MSGT__STATUS__ENQ: return "Q931_MSGT_STATUS_ENQ";
default:
return "<unknown>";
}
}

Q931__MessageType::enum_type Q931__MessageType::str_to_enum(const char *str_par, const int* int_par, const int* int_par2)
{
if (int_par == NULL && int_par2 == NULL) {
if (!strcmp(str_par, "Q931_MSGT_ALERTING")) return Q931__MSGT__ALERTING;
if (!strcmp(str_par, "Q931_MSGT_CALL_PROCEEDING")) return Q931__MSGT__CALL__PROCEEDING;
if (!strcmp(str_par, "Q931_MSGT_CONNECT")) return Q931__MSGT__CONNECT;
if (!strcmp(str_par, "Q931_MSGT_CONNECT_ACK")) return Q931__MSGT__CONNECT__ACK;
if (!strcmp(str_par, "Q931_MSGT_PROGRESS")) return Q931__MSGT__PROGRESS;
if (!strcmp(str_par, "Q931_MSGT_SETUP")) return Q931__MSGT__SETUP;
if (!strcmp(str_par, "Q931_MSGT_SETUP_ACK")) return Q931__MSGT__SETUP__ACK;
if (!strcmp(str_par, "Q931_MSGT_RESUME")) return Q931__MSGT__RESUME;
if (!strcmp(str_par, "Q931_MSGT_RESUME_ACK")) return Q931__MSGT__RESUME__ACK;
if (!strcmp(str_par, "Q931_MSGT_RESUME_REJ")) return Q931__MSGT__RESUME__REJ;
if (!strcmp(str_par, "Q931_MSGT_SUSPEND")) return Q931__MSGT__SUSPEND;
if (!strcmp(str_par, "Q931_MSGT_SUSPEND_ACK")) return Q931__MSGT__SUSPEND__ACK;
if (!strcmp(str_par, "Q931_MSGT_SUSPEND_REJ")) return Q931__MSGT__SUSPEND__REJ;
if (!strcmp(str_par, "Q931_MSGT_USER_INFO")) return Q931__MSGT__USER__INFO;
if (!strcmp(str_par, "Q931_MSGT_DISCONNECT")) return Q931__MSGT__DISCONNECT;
if (!strcmp(str_par, "Q931_MSGT_RELEASE")) return Q931__MSGT__RELEASE;
if (!strcmp(str_par, "Q931_MSGT_RELEASE_COMPL")) return Q931__MSGT__RELEASE__COMPL;
if (!strcmp(str_par, "Q931_MSGT_RESTART")) return Q931__MSGT__RESTART;
if (!strcmp(str_par, "Q931_MSGT_RESTART_ACK")) return Q931__MSGT__RESTART__ACK;
if (!strcmp(str_par, "Q931_MSGT_SEGMENT")) return Q931__MSGT__SEGMENT;
if (!strcmp(str_par, "Q931_MSGT_CONGESTION_CTRL")) return Q931__MSGT__CONGESTION__CTRL;
if (!strcmp(str_par, "Q931_MSGT_INFORMATION")) return Q931__MSGT__INFORMATION;
if (!strcmp(str_par, "Q931_MSGT_NOTIFY")) return Q931__MSGT__NOTIFY;
if (!strcmp(str_par, "Q931_MSGT_STATUS")) return Q931__MSGT__STATUS;
if (!strcmp(str_par, "Q931_MSGT_STATUS_ENQ")) return Q931__MSGT__STATUS__ENQ;
}
return UNKNOWN_VALUE;
}

boolean Q931__MessageType::is_valid_enum(int int_par)
{
switch (int_par) {
case 1:
case 2:
case 7:
case 15:
case 3:
case 5:
case 13:
case 38:
case 46:
case 34:
case 37:
case 45:
case 33:
case 32:
case 69:
case 77:
case 90:
case 70:
case 78:
case 96:
case 121:
case 123:
case 110:
case 125:
case 117:
return TRUE;
default:
return FALSE;
}
}

int Q931__MessageType::enum2int(enum_type enum_par)
{
if (enum_par==UNBOUND_VALUE || enum_par==UNKNOWN_VALUE) TTCN_error("The argument of function enum2int() is an %s value of enumerated type @Q931_Types.Q931_MessageType.", enum_par==UNBOUND_VALUE?"unbound":"invalid");
return enum_par;
}

int Q931__MessageType::enum2int(const Q931__MessageType& enum_par)
{
if (enum_par.enum_value==UNBOUND_VALUE || enum_par.enum_value==UNKNOWN_VALUE) TTCN_error("The argument of function enum2int() is an %s value of enumerated type @Q931_Types.Q931_MessageType.", enum_par==UNBOUND_VALUE?"unbound":"invalid");
return enum_par.enum_value;
}

void Q931__MessageType::int2enum(int int_val)
{
if (!is_valid_enum(int_val)) TTCN_error("Assigning invalid numeric value %d to a variable of enumerated type @Q931_Types.Q931_MessageType.", int_val);
enum_value = (enum_type)int_val;
}

Q931__MessageType::operator Q931__MessageType::enum_type() const
{
if (enum_value == UNBOUND_VALUE) TTCN_error("Using the value of an unbound variable of enumerated type @Q931_Types.Q931_MessageType.");
return enum_value;
}

void Q931__MessageType::log() const
{
if (enum_value != UNBOUND_VALUE) TTCN_Logger::log_event_enum(enum_to_str(enum_value), enum_value);
else TTCN_Logger::log_event_unbound();
}

void Q931__MessageType::set_param(Module_Param& param)
{
  param.basic_check(Module_Param::BC_VALUE, "enumerated value");
  if (param.get_type()!=Module_Param::MP_Enumerated) param.type_error("enumerated value", "@Q931_Types.Q931_MessageType");
  enum_value = str_to_enum(param.get_enumerated(), param.get_enumerated_value());
  if (!is_valid_enum(enum_value)) {
    param.error("Invalid enumerated value for type @Q931_Types.Q931_MessageType.");
  }
}

void Q931__MessageType::encode_text(Text_Buf& text_buf) const
{
if (enum_value == UNBOUND_VALUE) TTCN_error("Text encoder: Encoding an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
text_buf.push_int(enum_value);
}

void Q931__MessageType::decode_text(Text_Buf& text_buf)
{
enum_value = (enum_type)text_buf.pull_int().get_val();
if (!is_valid_enum(enum_value)) TTCN_error("Text decoder: Unknown numeric value %d was received for enumerated type @Q931_Types.Q931_MessageType.", enum_value);
}

void Q931__MessageType::encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...) const
{
  va_list pvar;
  va_start(pvar, p_coding);
  switch(p_coding) {
  case TTCN_EncDec::CT_BER: {
    TTCN_EncDec_ErrorContext ec("While BER-encoding type '%s': ", p_td.name);
    unsigned BER_coding=va_arg(pvar, unsigned);
    BER_encode_chk_coding(BER_coding);
    ASN_BER_TLV_t *tlv=BER_encode_TLV(p_td, BER_coding);
    tlv->put_in_buffer(p_buf);
    ASN_BER_TLV_t::destruct(tlv);
    break;}
  case TTCN_EncDec::CT_RAW: {
    TTCN_EncDec_ErrorContext ec("While RAW-encoding type '%s': ", p_td.name);
    if(!p_td.raw)
      TTCN_EncDec_ErrorContext::error_internal
        ("No RAW descriptor available for type '%s'.", p_td.name);
    RAW_enc_tr_pos rp;
    rp.level=0;
    rp.pos=NULL;
    RAW_enc_tree root(TRUE, NULL, &rp, 1, p_td.raw);
    RAW_encode(p_td, root);
    root.put_to_buf(p_buf);
    break;}
  case TTCN_EncDec::CT_TEXT: {
    TTCN_EncDec_ErrorContext ec("While TEXT-encoding type '%s': ", p_td.name);
    if(!p_td.text)
      TTCN_EncDec_ErrorContext::error_internal
      ("No TEXT descriptor available for type '%s'.", p_td.name);
    TEXT_encode(p_td,p_buf);
    break;}
  case TTCN_EncDec::CT_XER: {
    TTCN_EncDec_ErrorContext ec("While XER-encoding type '%s': ", p_td.name);
    unsigned XER_coding=va_arg(pvar, unsigned);
    XER_encode_chk_coding(XER_coding, p_td);
    XER_encode(*(p_td.xer),p_buf, XER_coding, 0, 0, 0);
    p_buf.put_c('\n');
    break;}
  case TTCN_EncDec::CT_JSON: {
    TTCN_EncDec_ErrorContext ec("While JSON-encoding type '%s': ", p_td.name);
    if(!p_td.json)
      TTCN_EncDec_ErrorContext::error_internal
        ("No JSON descriptor available for type '%s'.", p_td.name);
    JSON_Tokenizer tok(va_arg(pvar, int) != 0);
    JSON_encode(p_td, tok, FALSE);
    p_buf.put_s(tok.get_buffer_length(), (const unsigned char*)tok.get_buffer());
    break;}
  case TTCN_EncDec::CT_OER: {
    TTCN_EncDec_ErrorContext ec("While OER-encoding type '%s': ", p_td.name);
    if(!p_td.oer)
      TTCN_EncDec_ErrorContext::error_internal
        ("No OER descriptor available for type '%s'.", p_td.name);
    OER_encode(p_td, p_buf);
    break;}
  case TTCN_EncDec::CT_PER: {
    TTCN_EncDec_ErrorContext ec("While PER-encoding type '%s': ", p_td.name);
    if (!p_td.per) TTCN_EncDec_ErrorContext::error_internal(
      "No PER descriptor available for type '%s'.", p_td.name);
    int opt = va_arg(pvar, int);
    PER_encode(p_td, p_buf, opt);
    break; }
  default:
    TTCN_error("Unknown coding method requested to encode type '%s'", p_td.name);
  }
  va_end(pvar);
}

void Q931__MessageType::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int p_coding, ...)
{
  va_list pvar;
  va_start(pvar, p_coding);
  switch(p_coding) {
  case TTCN_EncDec::CT_BER: {
    TTCN_EncDec_ErrorContext ec("While BER-decoding type '%s': ", p_td.name);
    unsigned L_form=va_arg(pvar, unsigned);
    ASN_BER_TLV_t tlv;
    BER_decode_str2TLV(p_buf, tlv, L_form);
    BER_decode_TLV(p_td, tlv, L_form);
    if(tlv.isComplete) p_buf.increase_pos(tlv.get_len());
    break;}
  case TTCN_EncDec::CT_RAW: {
    TTCN_EncDec_ErrorContext ec("While RAW-decoding type '%s': ", p_td.name);
    if(!p_td.raw)
      TTCN_EncDec_ErrorContext::error_internal
        ("No RAW descriptor available for type '%s'.", p_td.name);
    raw_order_t r_order;
    switch(p_td.raw->top_bit_order) {
    case TOP_BIT_LEFT:
      r_order=ORDER_LSB;
      break;
    case TOP_BIT_RIGHT:
    default:
      r_order=ORDER_MSB;
    }
    int rawr = RAW_decode(p_td, p_buf, p_buf.get_len()*8, r_order);
    if(rawr<0) switch (-rawr) {
    case TTCN_EncDec::ET_INCOMPL_MSG:
    case TTCN_EncDec::ET_LEN_ERR:
      ec.error((TTCN_EncDec::error_type_t)-rawr, "Can not decode type '%s', because incomplete message was received", p_td.name);
      break;
    case 1:
    default:
      ec.error(TTCN_EncDec::ET_INVAL_MSG, "Can not decode type '%s', because invalid message was received", p_td.name);
      break;
    }
    break;}
  case TTCN_EncDec::CT_TEXT: {
    Limit_Token_List limit;
    TTCN_EncDec_ErrorContext ec("While TEXT-decoding type '%s': ", p_td.name);
    if(!p_td.text)
      TTCN_EncDec_ErrorContext::error_internal
        ("No TEXT descriptor available for type '%s'.", p_td.name);
    const unsigned char *b_data=p_buf.get_data();
    int null_added=0;
    if(b_data[p_buf.get_len()-1]!='\0'){
      null_added=1;
      p_buf.set_pos(p_buf.get_len());
      p_buf.put_zero(8,ORDER_LSB);
      p_buf.rewind();
    }
    if(TEXT_decode(p_td,p_buf,limit)<0)
      ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name);
    if(null_added){
      size_t actpos=p_buf.get_pos();
      p_buf.set_pos(p_buf.get_len()-1);
      p_buf.cut_end();
      p_buf.set_pos(actpos);
    }
    break;}
  case TTCN_EncDec::CT_XER: {
    TTCN_EncDec_ErrorContext ec("While XER-decoding type '%s': ", p_td.name);
    unsigned XER_coding=va_arg(pvar, unsigned);
    XER_encode_chk_coding(XER_coding, p_td);
    XmlReaderWrap reader(p_buf);
    for (int rd_ok=reader.Read(); rd_ok==1; rd_ok=reader.Read()) {
      if (reader.NodeType() == XML_READER_TYPE_ELEMENT) break;
    }
    XER_decode(*(p_td.xer), reader, XER_coding | XER_TOPLEVEL, XER_NONE, 0);
    size_t bytes = reader.ByteConsumed();
    p_buf.set_pos(bytes);
    break;}
  case TTCN_EncDec::CT_JSON: {
    TTCN_EncDec_ErrorContext ec("While JSON-decoding type '%s': ", p_td.name);
    if(!p_td.json)
      TTCN_EncDec_ErrorContext::error_internal
        ("No JSON descriptor available for type '%s'.", p_td.name);
    JSON_Tokenizer tok((const char*)p_buf.get_data(), p_buf.get_len());
    if(JSON_decode(p_td, tok, FALSE, FALSE)<0)
      ec.error(TTCN_EncDec::ET_INCOMPL_MSG,"Can not decode type '%s', because invalid or incomplete message was received", p_td.name);
    p_buf.set_pos(tok.get_buf_pos());
    break;}
  case TTCN_EncDec::CT_OER: {
    TTCN_EncDec_ErrorContext ec("While OER-decoding type '%s': ", p_td.name);
    if(!p_td.oer)
      TTCN_EncDec_ErrorContext::error_internal
        ("No OER descriptor available for type '%s'.", p_td.name);
     OER_struct p_oer;
    OER_decode(p_td, p_buf, p_oer);
    break;}
  case TTCN_EncDec::CT_PER: {
    TTCN_EncDec_ErrorContext ec("While PER-decoding type '%s': ", p_td.name);
    if(!p_td.per)  TTCN_EncDec_ErrorContext::error_internal(
      "No PER descriptor available for type '%s'.", p_td.name);
    int opt = va_arg(pvar, int);
    try {
      PER_decode(p_td, p_buf, opt);
      p_buf.PER_octet_align(FALSE);
    }
    catch (PER_Buffer_Exception) { }
    break; }
  default:
    TTCN_error("Unknown coding method requested to decode type '%s'", p_td.name);
  }
  va_end(pvar);
}

int Q931__MessageType::RAW_decode(const TTCN_Typedescriptor_t& p_td,TTCN_Buffer& p_buf,int limit, raw_order_t top_bit_ord, boolean no_err, int, boolean, const RAW_Force_Omit*)
{
  int decoded_value = 0;
  int decoded_length = RAW_decode_enum_type(p_td, p_buf, limit, top_bit_ord, decoded_value, 7, no_err);
  if (decoded_length < 0) return decoded_length;
  if (is_valid_enum(decoded_value)) enum_value = (enum_type)decoded_value;
  else {
    if(no_err){
     return -1;
    } else {
    TTCN_EncDec_ErrorContext::error
      (TTCN_EncDec::ET_ENC_ENUM, "Invalid enum value '%d' for '%s': ",decoded_value, p_td.name);
    enum_value = UNKNOWN_VALUE;
    }
  }
  return decoded_length;
}

int Q931__MessageType::RAW_encode(const TTCN_Typedescriptor_t& p_td, RAW_enc_tree& myleaf) const
{
  return RAW_encode_enum_type(p_td, myleaf, (int)enum_value, 7);
}

void Q931__MessageType_template::copy_template(const Q931__MessageType_template& other_value)
{
set_selection(other_value);
switch (template_selection) {
case SPECIFIC_VALUE:
single_value = other_value.single_value;
break;
case OMIT_VALUE:
case ANY_VALUE:
case ANY_OR_OMIT:
break;
case VALUE_LIST:
case COMPLEMENTED_LIST:
case CONJUNCTION_MATCH:
value_list.n_values = other_value.value_list.n_values;
value_list.list_value = new Q931__MessageType_template[value_list.n_values];
for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
value_list.list_value[list_count].copy_template(other_value.value_list.list_value[list_count]);
break;
case IMPLICATION_MATCH:
implication_.precondition = new Q931__MessageType_template(*other_value.implication_.precondition);
implication_.implied_template = new Q931__MessageType_template(*other_value.implication_.implied_template);
break;
case DYNAMIC_MATCH:
dyn_match = other_value.dyn_match;
dyn_match->ref_count++;
break;
default:
TTCN_error("Copying an uninitialized/unsupported template of enumerated type @Q931_Types.Q931_MessageType.");
}
}

Q931__MessageType_template::Q931__MessageType_template()
{
}

Q931__MessageType_template::Q931__MessageType_template(template_sel other_value)
 : Base_Template(other_value)
{
check_single_selection(other_value);
}

Q931__MessageType_template::Q931__MessageType_template(int other_value)
 : Base_Template(SPECIFIC_VALUE)
{
if (!Q931__MessageType::is_valid_enum(other_value)) TTCN_error("Initializing a template of enumerated type @Q931_Types.Q931_MessageType with unknown numeric value %d.", other_value);
single_value = (Q931__MessageType::enum_type)other_value;
}

Q931__MessageType_template::Q931__MessageType_template(Q931__MessageType::enum_type other_value)
 : Base_Template(SPECIFIC_VALUE)
{
single_value = other_value;
}

Q931__MessageType_template::Q931__MessageType_template(const Q931__MessageType& other_value)
 : Base_Template(SPECIFIC_VALUE)
{
if (other_value.enum_value == Q931__MessageType::UNBOUND_VALUE) TTCN_error("Creating a template from an unbound value of enumerated type @Q931_Types.Q931_MessageType.");
single_value = other_value.enum_value;
}

Q931__MessageType_template::Q931__MessageType_template(const OPTIONAL<Q931__MessageType>& other_value)
{
switch (other_value.get_selection()) {
case OPTIONAL_PRESENT:
set_selection(SPECIFIC_VALUE);
single_value = (Q931__MessageType::enum_type)(const Q931__MessageType&)other_value;
break;
case OPTIONAL_OMIT:
set_selection(OMIT_VALUE);
break;
default:
TTCN_error("Creating a template of enumerated type @Q931_Types.Q931_MessageType from an unbound optional field.");
}
}

Q931__MessageType_template::Q931__MessageType_template(Q931__MessageType_template* p_precondition, Q931__MessageType_template* p_implied_template)
 : Base_Template(IMPLICATION_MATCH)
{
implication_.precondition = p_precondition;
implication_.implied_template = p_implied_template;
}

Q931__MessageType_template::Q931__MessageType_template(Dynamic_Match_Interface<Q931__MessageType>* p_dyn_match)
 : Base_Template(DYNAMIC_MATCH)
{
dyn_match = new dynmatch_struct<Q931__MessageType>;
dyn_match->ptr = p_dyn_match;
dyn_match->ref_count = 1;
}

Q931__MessageType_template::Q931__MessageType_template(const Q931__MessageType_template& other_value)
 : Base_Template()
{
copy_template(other_value);
}

Q931__MessageType_template::~Q931__MessageType_template()
{
clean_up();
}

boolean Q931__MessageType_template::is_bound() const
{
if (template_selection == UNINITIALIZED_TEMPLATE && !is_ifpresent) return FALSE;
return TRUE;
}

boolean Q931__MessageType_template::is_value() const
{
if (template_selection != SPECIFIC_VALUE || is_ifpresent) return FALSE;
return single_value != Q931__MessageType::UNBOUND_VALUE;
}

void Q931__MessageType_template::clean_up()
{
switch (template_selection) {
case VALUE_LIST:
case COMPLEMENTED_LIST:
case CONJUNCTION_MATCH:
delete [] value_list.list_value;
break;
case IMPLICATION_MATCH:
delete implication_.precondition;
delete implication_.implied_template;
break;
case DYNAMIC_MATCH:
dyn_match->ref_count--;
if (dyn_match->ref_count == 0) {
delete dyn_match->ptr;
delete dyn_match;
}
break;
default:
break;
}
template_selection = UNINITIALIZED_TEMPLATE;
}

Q931__MessageType_template& Q931__MessageType_template::operator=(template_sel other_value)
{
check_single_selection(other_value);
clean_up();
set_selection(other_value);
return *this;
}

Q931__MessageType_template& Q931__MessageType_template::operator=(int other_value)
{
if (!Q931__MessageType::is_valid_enum(other_value)) TTCN_warning("Assigning unknown numeric value %d to a template of enumerated type @Q931_Types.Q931_MessageType.", other_value);
clean_up();
set_selection(SPECIFIC_VALUE);
single_value = (Q931__MessageType::enum_type)other_value;
return *this;
}

Q931__MessageType_template& Q931__MessageType_template::operator=(Q931__MessageType::enum_type other_value)
{
clean_up();
set_selection(SPECIFIC_VALUE);
single_value = other_value;
return *this;
}

Q931__MessageType_template& Q931__MessageType_template::operator=(const Q931__MessageType& other_value)
{
if (other_value.enum_value == Q931__MessageType::UNBOUND_VALUE) TTCN_error("Assignment of an unbound value of enumerated type @Q931_Types.Q931_MessageType to a template.");
clean_up();
set_selection(SPECIFIC_VALUE);
single_value = other_value.enum_value;
return *this;
}

Q931__MessageType_template& Q931__MessageType_template::operator=(const OPTIONAL<Q931__MessageType>& other_value)
{
clean_up();
switch (other_value.get_selection()) {
case OPTIONAL_PRESENT:
set_selection(SPECIFIC_VALUE);
single_value = (Q931__MessageType::enum_type)(const Q931__MessageType&)other_value;
break;
case OPTIONAL_OMIT:
set_selection(OMIT_VALUE);
break;
default:
TTCN_error("Assignment of an unbound optional field to a template of enumerated type @Q931_Types.Q931_MessageType.");
}
return *this;
}

Q931__MessageType_template& Q931__MessageType_template::operator=(const Q931__MessageType_template& other_value)
{
if (&other_value != this) {
clean_up();
copy_template(other_value);
}
return *this;
}

boolean Q931__MessageType_template::match(Q931__MessageType::enum_type other_value, boolean) const
{
switch (template_selection) {
case SPECIFIC_VALUE:
return single_value == other_value;
case OMIT_VALUE:
return FALSE;
case ANY_VALUE:
case ANY_OR_OMIT:
return TRUE;
case VALUE_LIST:
case COMPLEMENTED_LIST:
for (unsigned int list_count = 0; list_count < value_list.n_values; list_count++)
if (value_list.list_value[list_count].match(other_value)) return template_selection == VALUE_LIST;
return template_selection == COMPLEMENTED_LIST;
case CONJUNCTION_MATCH:
for (unsigned int i = 0; i < value_list.n_values; i++) {
if (!value_list.list_value[i].match(other_value)) {
return FALSE;
}
}
return TRUE;
case IMPLICATION_MATCH:
return !implication_.precondition->match(other_value) || implication_.implied_template->match(other_value);
case DYNAMIC_MATCH:
return dyn_match->ptr->match(other_value);
default:
TTCN_error("Matching an uninitialized/unsupported template of enumerated type @Q931_Types.Q931_MessageType.");
}
return FALSE;
}

boolean Q931__MessageType_template::match(const Q931__MessageType& other_value, boolean) const
{
if (other_value.enum_value == Q931__MessageType::UNBOUND_VALUE) TTCN_error("Matching a template of enumerated type @Q931_Types.Q931_MessageType with an unbound value.");
return match(other_value.enum_value);
}

Q931__MessageType::enum_type Q931__MessageType_template::valueof() const
{
if (template_selection != SPECIFIC_VALUE || is_ifpresent) TTCN_error("Performing a valueof or send operation on a non-specific template of enumerated type @Q931_Types.Q931_MessageType.");
return single_value;
}

void Q931__MessageType_template::set_type(template_sel template_type, unsigned int list_length)
{
clean_up();
switch (template_type) {
case VALUE_LIST:
case COMPLEMENTED_LIST:
case CONJUNCTION_MATCH:
set_selection(template_type);
value_list.n_values = list_length;
value_list.list_value = new Q931__MessageType_template[list_length];
break;
default:
TTCN_error("Setting an invalid type for a template of enumerated type @Q931_Types.Q931_MessageType.");
}
}

Q931__MessageType_template& Q931__MessageType_template::list_item(unsigned int list_index)
{
if (template_selection != VALUE_LIST && template_selection != COMPLEMENTED_LIST && template_selection != CONJUNCTION_MATCH) TTCN_error("Accessing a list element in a non-list template of enumerated type @Q931_Types.Q931_MessageType.");
if (list_index >= value_list.n_values) TTCN_error("Index overflow in a value list template of enumerated type @Q931_Types.Q931_MessageType.");
return value_list.list_value[list_index];
}

void Q931__MessageType_template::log() const
{
switch (template_selection) {
case SPECIFIC_VALUE:
TTCN_Logger::log_event_enum(Q931__MessageType::enum_to_str(single_value), single_value);
break;
case COMPLEMENTED_LIST:
TTCN_Logger::log_event_str("complement");
case CONJUNCTION_MATCH:
if (template_selection == CONJUNCTION_MATCH) {
TTCN_Logger::log_event_str("conjunct");
}
case VALUE_LIST:
TTCN_Logger::log_char('(');
for (unsigned int elem_count = 0; elem_count < value_list.n_values; elem_count++) {
if (elem_count > 0) TTCN_Logger::log_event_str(", ");
value_list.list_value[elem_count].log();
}
TTCN_Logger::log_char(')');
break;
case IMPLICATION_MATCH:
implication_.precondition->log();
TTCN_Logger::log_event_str(" implies ");
implication_.implied_template->log();
break;
case DYNAMIC_MATCH:
TTCN_Logger::log_event_str("@dynamic template");
break;
default:
log_generic();
}
log_ifpresent();
}

void Q931__MessageType_template::log_match(const Q931__MessageType& match_value, boolean) const
{
match_value.log();
TTCN_Logger::log_event_str(" with ");
log();
if (match(match_value)) TTCN_Logger::log_event_str(" matched");
else TTCN_Logger::log_event_str(" unmatched");
}

void Q931__MessageType_template::encode_text(Text_Buf& text_buf) const
{
encode_text_base(text_buf);
switch (template_selection) {
case SPECIFIC_VALUE:
text_buf.push_int(single_value);
case OMIT_VALUE:
case ANY_VALUE:
case ANY_OR_OMIT:
break;
case VALUE_LIST:
case COMPLEMENTED_LIST:
text_buf.push_int(value_list.n_values);
for (unsigned int elem_count = 0; elem_count < value_list.n_values; elem_count++)
value_list.list_value[elem_count].encode_text(text_buf);
break;
default:
TTCN_error("Text encoder: Encoding an uninitialized/unsupported template of enumerated type @Q931_Types.Q931_MessageType.");
}
}

void Q931__MessageType_template::decode_text(Text_Buf& text_buf)
{
clean_up();
decode_text_base(text_buf);
switch (template_selection) {
case SPECIFIC_VALUE:
single_value = (Q931__MessageType::enum_type)text_buf.pull_int().get_val();
if (!Q931__MessageType::is_valid_enum(single_value)) TTCN_error("Text decoder: Unknown numeric value %d was received for a template of enumerated type @Q931_Types.Q931_MessageType.", single_value);
case OMIT_VALUE:
case ANY_VALUE:
case ANY_OR_OMIT:
break;
case VALUE_LIST:
case COMPLEMENTED_LIST:
value_list.n_values = text_buf.pull_int().get_val();
value_list.list_value = new Q931__MessageType_template[value_list.n_values];
for (unsigned int elem_count = 0; elem_count < value_list.n_values; elem_count++)
value_list.list_value[elem_count].decode_text(text_buf);
break;
default:
TTCN_error("Text decoder: An unknown/unsupported selection was received for a template of enumerated type @Q931_Types.Q931_MessageType.");
}
}

boolean Q931__MessageType_template::is_present(boolean legacy) const
{
if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE;
return !match_omit(legacy);
}

boolean Q931__MessageType_template::match_omit(boolean legacy) const
{
if (is_ifpresent) return TRUE;
switch (template_selection) {
case OMIT_VALUE:
case ANY_OR_OMIT:
return TRUE;
case IMPLICATION_MATCH:
return !implication_.precondition->match_omit() || implication_.implied_template->match_omit();
case VALUE_LIST:
case COMPLEMENTED_LIST:
if (legacy) {
for (unsigned int i=0; i<value_list.n_values; i++)
if (value_list.list_value[i].match_omit())
return template_selection==VALUE_LIST;
return template_selection==COMPLEMENTED_LIST;
} // else fall through
default:
return FALSE;
}
return FALSE;
}

void Q931__MessageType_template::set_param(Module_Param& param)
{
  param.basic_check(Module_Param::BC_TEMPLATE, "enumerated template");
  Module_Param_Ptr m_p = &param;
  switch (m_p->get_type()) {
  case Module_Param::MP_Omit:
    *this = OMIT_VALUE;
    break;
  case Module_Param::MP_Any:
    *this = ANY_VALUE;
    break;
  case Module_Param::MP_AnyOrNone:
    *this = ANY_OR_OMIT;
    break;
  case Module_Param::MP_List_Template:
  case Module_Param::MP_ComplementList_Template:
  case Module_Param::MP_ConjunctList_Template: {
    Q931__MessageType_template new_temp;
    new_temp.set_type(m_p->get_type()==Module_Param::MP_List_Template ? VALUE_LIST : (m_p->get_type() == Module_Param::MP_ConjunctList_Template ? CONJUNCTION_MATCH : COMPLEMENTED_LIST), m_p->get_size());
    for (size_t p_i=0; p_i<m_p->get_size(); p_i++) {
      new_temp.list_item(p_i).set_param(*m_p->get_elem(p_i));
    }
    *this = new_temp;
    break; }
  case Module_Param::MP_Enumerated: {
    Q931__MessageType::enum_type enum_val = Q931__MessageType::str_to_enum(m_p->get_enumerated(), m_p->get_enumerated_value());
    if (!Q931__MessageType::is_valid_enum(enum_val)) {
      param.error("Invalid enumerated value for type @Q931_Types.Q931_MessageType.");
    }
    *this = enum_val;
  } break;
  case Module_Param::MP_Implication_Template: {
    Q931__MessageType_template* precondition = new Q931__MessageType_template;
    precondition->set_param(*m_p->get_elem(0));
    Q931__MessageType_template* implied_template = new Q931__MessageType_template;
    implied_template->set_param(*m_p->get_elem(1));
    *this = Q931__MessageType_template(precondition, implied_template);
  } break;
  default:
    param.type_error("enumerated template", "@Q931_Types.Q931_MessageType");
  }
  is_ifpresent = param.get_ifpresent();
}

void Q931__MessageType_template::check_restriction(template_res t_res, const char* t_name,
boolean legacy) const
{
if (template_selection==UNINITIALIZED_TEMPLATE) return;
switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) {
case TR_VALUE:
if (!is_ifpresent && template_selection==SPECIFIC_VALUE) return;
break;
case TR_OMIT:
if (!is_ifpresent && (template_selection==OMIT_VALUE || template_selection==SPECIFIC_VALUE)) return;
break;
case TR_PRESENT:
if (!match_omit(legacy)) return;
break;
default:
return;
}
TTCN_error("Restriction `%s' on template of type %s violated.", get_res_name(t_res), t_name ? t_name : "@Q931_Types.Q931_MessageType");
}


/* Bodies of functions, altsteps and testcases */

void Q931__MessageType_encoder(const Q931__MessageType& input_value, OCTETSTRING& output_stream, const UNIVERSAL_CHARSTRING& coding_name)
{
TTCN_EncDec::coding_t coding_type;
unsigned int extra_options = 0;
TTCN_EncDec::get_coding_from_str(coding_name, &coding_type, &extra_options, TRUE);
if (coding_type != TTCN_EncDec::CT_RAW) {
TTCN_Logger::begin_event_log2str();
coding_name.log();
TTCN_error("Type `@Q931_Types.Q931_MessageType' does not support %s encoding", (const char*) TTCN_Logger::end_event_log2str());
}
TTCN_Buffer ttcn_buf;
input_value.encode(Q931__MessageType_descr_, ttcn_buf, coding_type, extra_options);
ttcn_buf.get_string(output_stream);
}

INTEGER Q931__MessageType_decoder(OCTETSTRING& input_stream, Q931__MessageType& output_value, const UNIVERSAL_CHARSTRING& coding_name)
{
TTCN_EncDec::coding_t coding_type;
unsigned int extra_options = 0;
TTCN_EncDec::get_coding_from_str(coding_name, &coding_type, &extra_options, FALSE);
if (coding_type != TTCN_EncDec::CT_RAW) {
TTCN_Logger::begin_event_log2str();
coding_name.log();
TTCN_error("Type `@Q931_Types.Q931_MessageType' does not support %s encoding", (const char*) TTCN_Logger::end_event_log2str());
}
TTCN_Buffer ttcn_buf(input_stream);
output_value.decode(Q931__MessageType_descr_, ttcn_buf, coding_type, extra_options);
switch (TTCN_EncDec::get_last_error_type()) {
case TTCN_EncDec::ET_NONE:
ttcn_buf.cut();
ttcn_buf.get_string(input_stream);
return 0;
case TTCN_EncDec::ET_INCOMPL_MSG:
case TTCN_EncDec::ET_LEN_ERR:
return 2;
default:
return 1;
}
}


} /* end of namespace */
