//
// Generated file, do not edit! Created by opp_msgc 4.1 from src/node/application/WiseApplicationPacket.msg.
//

// Disable warnings about unused variables, empty switch stmts, etc:
#ifdef _MSC_VER
#  pragma warning(disable:4101)
#  pragma warning(disable:4065)
#endif

#include <iostream>
#include <sstream>
#include "WiseApplicationPacket_m.h"

// Template rule which fires if a struct or class doesn't have operator<<
template<typename T>
std::ostream& operator<<(std::ostream& out,const T&) {return out;}

// Another default rule (prevents compiler from choosing base class' doPacking())
template<typename T>
void doPacking(cCommBuffer *, T& t) {
    throw cRuntimeError("Parsim error: no doPacking() function for type %s or its base class (check .msg and _m.cc/h files!)",opp_typename(typeid(t)));
}

template<typename T>
void doUnpacking(cCommBuffer *, T& t) {
    throw cRuntimeError("Parsim error: no doUnpacking() function for type %s or its base class (check .msg and _m.cc/h files!)",opp_typename(typeid(t)));
}




EXECUTE_ON_STARTUP(
    cEnum *e = cEnum::find("WiseApplicationPacketType");
    if (!e) enums.getInstance()->add(e = new cEnum("WiseApplicationPacketType"));
    e->insert(WISE_APP_NORMAL, "WISE_APP_NORMAL");
    e->insert(WISE_APP_DIRECT_COMMUNICATION, "WISE_APP_DIRECT_COMMUNICATION");
);

Register_Class(WiseApplicationPacket);

WiseApplicationPacket::WiseApplicationPacket(const char *name, int kind) : ApplicationPacket(name,kind)
{
    payload_arraysize = 0;
    this->payload_var = 0;
    this->type_var = WISE_APP_NORMAL;
    this->sensedValue_var = 0;
    this->source_var = 0;
    this->byteLength_var = 0;
    this->angle_var = 0;
}

WiseApplicationPacket::WiseApplicationPacket(const WiseApplicationPacket& other) : ApplicationPacket()
{
    setName(other.getName());
    payload_arraysize = 0;
    this->payload_var = 0;
    operator=(other);
}

WiseApplicationPacket::~WiseApplicationPacket()
{
    delete [] payload_var;
}

WiseApplicationPacket& WiseApplicationPacket::operator=(const WiseApplicationPacket& other)
{
    if (this==&other) return *this;
    ApplicationPacket::operator=(other);
    this->src_var = other.src_var;
    delete [] this->payload_var;
    this->payload_var = (other.payload_arraysize==0) ? NULL : new unsigned char[other.payload_arraysize];
    payload_arraysize = other.payload_arraysize;
    for (unsigned int i=0; i<payload_arraysize; i++)
        this->payload_var[i] = other.payload_var[i];
    this->type_var = other.type_var;
    this->sensedValue_var = other.sensedValue_var;
    this->source_var = other.source_var;
    this->byteLength_var = other.byteLength_var;
    this->angle_var = other.angle_var;
    this->info_var = other.info_var;
    return *this;
}

void WiseApplicationPacket::parsimPack(cCommBuffer *b)
{
    ApplicationPacket::parsimPack(b);
    doPacking(b,this->src_var);
    b->pack(payload_arraysize);
    doPacking(b,this->payload_var,payload_arraysize);
    doPacking(b,this->type_var);
    doPacking(b,this->sensedValue_var);
    doPacking(b,this->source_var);
    doPacking(b,this->byteLength_var);
    doPacking(b,this->angle_var);
    doPacking(b,this->info_var);
}

void WiseApplicationPacket::parsimUnpack(cCommBuffer *b)
{
    ApplicationPacket::parsimUnpack(b);
    doUnpacking(b,this->src_var);
    delete [] this->payload_var;
    b->unpack(payload_arraysize);
    if (payload_arraysize==0) {
        this->payload_var = 0;
    } else {
        this->payload_var = new unsigned char[payload_arraysize];
        doUnpacking(b,this->payload_var,payload_arraysize);
    }
    doUnpacking(b,this->type_var);
    doUnpacking(b,this->sensedValue_var);
    doUnpacking(b,this->source_var);
    doUnpacking(b,this->byteLength_var);
    doUnpacking(b,this->angle_var);
    doUnpacking(b,this->info_var);
}

Node& WiseApplicationPacket::getSrc()
{
    return src_var;
}

void WiseApplicationPacket::setSrc(const Node& src_var)
{
    this->src_var = src_var;
}

void WiseApplicationPacket::setPayloadArraySize(unsigned int size)
{
    unsigned char *payload_var2 = (size==0) ? NULL : new unsigned char[size];
    unsigned int sz = payload_arraysize < size ? payload_arraysize : size;
    for (unsigned int i=0; i<sz; i++)
        payload_var2[i] = this->payload_var[i];
    for (unsigned int i=sz; i<size; i++)
        payload_var2[i] = 0;
    payload_arraysize = size;
    delete [] this->payload_var;
    this->payload_var = payload_var2;
}

unsigned int WiseApplicationPacket::getPayloadArraySize() const
{
    return payload_arraysize;
}

unsigned char WiseApplicationPacket::getPayload(unsigned int k) const
{
    if (k>=payload_arraysize) throw cRuntimeError("Array of size %d indexed by %d", payload_arraysize, k);
    return payload_var[k];
}

void WiseApplicationPacket::setPayload(unsigned int k, unsigned char payload_var)
{
    if (k>=payload_arraysize) throw cRuntimeError("Array of size %d indexed by %d", payload_arraysize, k);
    this->payload_var[k]=payload_var;
}

unsigned int WiseApplicationPacket::getType() const
{
    return type_var;
}

void WiseApplicationPacket::setType(unsigned int type_var)
{
    this->type_var = type_var;
}

double WiseApplicationPacket::getSensedValue() const
{
    return sensedValue_var;
}

void WiseApplicationPacket::setSensedValue(double sensedValue_var)
{
    this->sensedValue_var = sensedValue_var;
}

int WiseApplicationPacket::getSource() const
{
    return source_var;
}

void WiseApplicationPacket::setSource(int source_var)
{
    this->source_var = source_var;
}

int WiseApplicationPacket::getByteLength() const
{
    return byteLength_var;
}

void WiseApplicationPacket::setByteLength(int byteLength_var)
{
    this->byteLength_var = byteLength_var;
}

int WiseApplicationPacket::getAngle() const
{
    return angle_var;
}

void WiseApplicationPacket::setAngle(int angle_var)
{
    this->angle_var = angle_var;
}

TraceInfo& WiseApplicationPacket::getInfo()
{
    return info_var;
}

void WiseApplicationPacket::setInfo(const TraceInfo& info_var)
{
    this->info_var = info_var;
}

class WiseApplicationPacketDescriptor : public cClassDescriptor
{
  public:
    WiseApplicationPacketDescriptor();
    virtual ~WiseApplicationPacketDescriptor();

    virtual bool doesSupport(cObject *obj) const;
    virtual const char *getProperty(const char *propertyname) const;
    virtual int getFieldCount(void *object) const;
    virtual const char *getFieldName(void *object, int field) const;
    virtual int findField(void *object, const char *fieldName) const;
    virtual unsigned int getFieldTypeFlags(void *object, int field) const;
    virtual const char *getFieldTypeString(void *object, int field) const;
    virtual const char *getFieldProperty(void *object, int field, const char *propertyname) const;
    virtual int getArraySize(void *object, int field) const;

    virtual std::string getFieldAsString(void *object, int field, int i) const;
    virtual bool setFieldAsString(void *object, int field, int i, const char *value) const;

    virtual const char *getFieldStructName(void *object, int field) const;
    virtual void *getFieldStructPointer(void *object, int field, int i) const;
};

Register_ClassDescriptor(WiseApplicationPacketDescriptor);

WiseApplicationPacketDescriptor::WiseApplicationPacketDescriptor() : cClassDescriptor("WiseApplicationPacket", "ApplicationPacket")
{
}

WiseApplicationPacketDescriptor::~WiseApplicationPacketDescriptor()
{
}

bool WiseApplicationPacketDescriptor::doesSupport(cObject *obj) const
{
    return dynamic_cast<WiseApplicationPacket *>(obj)!=NULL;
}

const char *WiseApplicationPacketDescriptor::getProperty(const char *propertyname) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    return basedesc ? basedesc->getProperty(propertyname) : NULL;
}

int WiseApplicationPacketDescriptor::getFieldCount(void *object) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    return basedesc ? 8+basedesc->getFieldCount(object) : 8;
}

unsigned int WiseApplicationPacketDescriptor::getFieldTypeFlags(void *object, int field) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    if (basedesc) {
        if (field < basedesc->getFieldCount(object))
            return basedesc->getFieldTypeFlags(object, field);
        field -= basedesc->getFieldCount(object);
    }
    static unsigned int fieldTypeFlags[] = {
        FD_ISCOMPOUND,
        FD_ISARRAY | FD_ISEDITABLE,
        FD_ISEDITABLE,
        FD_ISEDITABLE,
        FD_ISEDITABLE,
        FD_ISEDITABLE,
        FD_ISEDITABLE,
        FD_ISCOMPOUND,
    };
    return (field>=0 && field<8) ? fieldTypeFlags[field] : 0;
}

const char *WiseApplicationPacketDescriptor::getFieldName(void *object, int field) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    if (basedesc) {
        if (field < basedesc->getFieldCount(object))
            return basedesc->getFieldName(object, field);
        field -= basedesc->getFieldCount(object);
    }
    static const char *fieldNames[] = {
        "src",
        "payload",
        "type",
        "sensedValue",
        "source",
        "byteLength",
        "angle",
        "info",
    };
    return (field>=0 && field<8) ? fieldNames[field] : NULL;
}

int WiseApplicationPacketDescriptor::findField(void *object, const char *fieldName) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    int base = basedesc ? basedesc->getFieldCount(object) : 0;
    if (fieldName[0]=='s' && strcmp(fieldName, "src")==0) return base+0;
    if (fieldName[0]=='p' && strcmp(fieldName, "payload")==0) return base+1;
    if (fieldName[0]=='t' && strcmp(fieldName, "type")==0) return base+2;
    if (fieldName[0]=='s' && strcmp(fieldName, "sensedValue")==0) return base+3;
    if (fieldName[0]=='s' && strcmp(fieldName, "source")==0) return base+4;
    if (fieldName[0]=='b' && strcmp(fieldName, "byteLength")==0) return base+5;
    if (fieldName[0]=='a' && strcmp(fieldName, "angle")==0) return base+6;
    if (fieldName[0]=='i' && strcmp(fieldName, "info")==0) return base+7;
    return basedesc ? basedesc->findField(object, fieldName) : -1;
}

const char *WiseApplicationPacketDescriptor::getFieldTypeString(void *object, int field) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    if (basedesc) {
        if (field < basedesc->getFieldCount(object))
            return basedesc->getFieldTypeString(object, field);
        field -= basedesc->getFieldCount(object);
    }
    static const char *fieldTypeStrings[] = {
        "Node",
        "unsigned char",
        "unsigned int",
        "double",
        "int",
        "int",
        "int",
        "TraceInfo",
    };
    return (field>=0 && field<8) ? fieldTypeStrings[field] : NULL;
}

const char *WiseApplicationPacketDescriptor::getFieldProperty(void *object, int field, const char *propertyname) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    if (basedesc) {
        if (field < basedesc->getFieldCount(object))
            return basedesc->getFieldProperty(object, field, propertyname);
        field -= basedesc->getFieldCount(object);
    }
    switch (field) {
        default: return NULL;
    }
}

int WiseApplicationPacketDescriptor::getArraySize(void *object, int field) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    if (basedesc) {
        if (field < basedesc->getFieldCount(object))
            return basedesc->getArraySize(object, field);
        field -= basedesc->getFieldCount(object);
    }
    WiseApplicationPacket *pp = (WiseApplicationPacket *)object; (void)pp;
    switch (field) {
        case 1: return pp->getPayloadArraySize();
        default: return 0;
    }
}

std::string WiseApplicationPacketDescriptor::getFieldAsString(void *object, int field, int i) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    if (basedesc) {
        if (field < basedesc->getFieldCount(object))
            return basedesc->getFieldAsString(object,field,i);
        field -= basedesc->getFieldCount(object);
    }
    WiseApplicationPacket *pp = (WiseApplicationPacket *)object; (void)pp;
    switch (field) {
        case 0: {std::stringstream out; out << pp->getSrc(); return out.str();}
        case 1: return ulong2string(pp->getPayload(i));
        case 2: return ulong2string(pp->getType());
        case 3: return double2string(pp->getSensedValue());
        case 4: return long2string(pp->getSource());
        case 5: return long2string(pp->getByteLength());
        case 6: return long2string(pp->getAngle());
        case 7: {std::stringstream out; out << pp->getInfo(); return out.str();}
        default: return "";
    }
}

bool WiseApplicationPacketDescriptor::setFieldAsString(void *object, int field, int i, const char *value) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    if (basedesc) {
        if (field < basedesc->getFieldCount(object))
            return basedesc->setFieldAsString(object,field,i,value);
        field -= basedesc->getFieldCount(object);
    }
    WiseApplicationPacket *pp = (WiseApplicationPacket *)object; (void)pp;
    switch (field) {
        case 1: pp->setPayload(i,string2ulong(value)); return true;
        case 2: pp->setType(string2ulong(value)); return true;
        case 3: pp->setSensedValue(string2double(value)); return true;
        case 4: pp->setSource(string2long(value)); return true;
        case 5: pp->setByteLength(string2long(value)); return true;
        case 6: pp->setAngle(string2long(value)); return true;
        default: return false;
    }
}

const char *WiseApplicationPacketDescriptor::getFieldStructName(void *object, int field) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    if (basedesc) {
        if (field < basedesc->getFieldCount(object))
            return basedesc->getFieldStructName(object, field);
        field -= basedesc->getFieldCount(object);
    }
    static const char *fieldStructNames[] = {
        "Node",
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        "TraceInfo",
    };
    return (field>=0 && field<8) ? fieldStructNames[field] : NULL;
}

void *WiseApplicationPacketDescriptor::getFieldStructPointer(void *object, int field, int i) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    if (basedesc) {
        if (field < basedesc->getFieldCount(object))
            return basedesc->getFieldStructPointer(object, field, i);
        field -= basedesc->getFieldCount(object);
    }
    WiseApplicationPacket *pp = (WiseApplicationPacket *)object; (void)pp;
    switch (field) {
        case 0: return (void *)(&pp->getSrc()); break;
        case 7: return (void *)(&pp->getInfo()); break;
        default: return NULL;
    }
}


