//
// Generated file, do not edit! Created by opp_msgc 4.1 from baseNetwork/node/messages/LEACH_TDMA_Schedule.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 "LEACH_TDMA_Schedule_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)));
}




Register_Class(LEACH_TDMA_Schedule);

LEACH_TDMA_Schedule::LEACH_TDMA_Schedule(const char *name, int kind) : NetwPkt(name,kind)
{
    schedule_arraysize = 0;
    this->schedule_var = 0;
}

LEACH_TDMA_Schedule::LEACH_TDMA_Schedule(const LEACH_TDMA_Schedule& other) : NetwPkt()
{
    setName(other.getName());
    schedule_arraysize = 0;
    this->schedule_var = 0;
    operator=(other);
}

LEACH_TDMA_Schedule::~LEACH_TDMA_Schedule()
{
    delete [] schedule_var;
}

LEACH_TDMA_Schedule& LEACH_TDMA_Schedule::operator=(const LEACH_TDMA_Schedule& other)
{
    if (this==&other) return *this;
    NetwPkt::operator=(other);
    delete [] this->schedule_var;
    this->schedule_var = (other.schedule_arraysize==0) ? NULL : new int[other.schedule_arraysize];
    schedule_arraysize = other.schedule_arraysize;
    for (unsigned int i=0; i<schedule_arraysize; i++)
        this->schedule_var[i] = other.schedule_var[i];
    return *this;
}

void LEACH_TDMA_Schedule::parsimPack(cCommBuffer *b)
{
    NetwPkt::parsimPack(b);
    b->pack(schedule_arraysize);
    doPacking(b,this->schedule_var,schedule_arraysize);
}

void LEACH_TDMA_Schedule::parsimUnpack(cCommBuffer *b)
{
    NetwPkt::parsimUnpack(b);
    delete [] this->schedule_var;
    b->unpack(schedule_arraysize);
    if (schedule_arraysize==0) {
        this->schedule_var = 0;
    } else {
        this->schedule_var = new int[schedule_arraysize];
        doUnpacking(b,this->schedule_var,schedule_arraysize);
    }
}

void LEACH_TDMA_Schedule::setScheduleArraySize(unsigned int size)
{
    int *schedule_var2 = (size==0) ? NULL : new int[size];
    unsigned int sz = schedule_arraysize < size ? schedule_arraysize : size;
    for (unsigned int i=0; i<sz; i++)
        schedule_var2[i] = this->schedule_var[i];
    for (unsigned int i=sz; i<size; i++)
        schedule_var2[i] = 0;
    schedule_arraysize = size;
    delete [] this->schedule_var;
    this->schedule_var = schedule_var2;
}

unsigned int LEACH_TDMA_Schedule::getScheduleArraySize() const
{
    return schedule_arraysize;
}

int LEACH_TDMA_Schedule::getSchedule(unsigned int k) const
{
    if (k>=schedule_arraysize) throw cRuntimeError("Array of size %d indexed by %d", schedule_arraysize, k);
    return schedule_var[k];
}

void LEACH_TDMA_Schedule::setSchedule(unsigned int k, int schedule_var)
{
    if (k>=schedule_arraysize) throw cRuntimeError("Array of size %d indexed by %d", schedule_arraysize, k);
    this->schedule_var[k]=schedule_var;
}

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

    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(LEACH_TDMA_ScheduleDescriptor);

LEACH_TDMA_ScheduleDescriptor::LEACH_TDMA_ScheduleDescriptor() : cClassDescriptor("LEACH_TDMA_Schedule", "NetwPkt")
{
}

LEACH_TDMA_ScheduleDescriptor::~LEACH_TDMA_ScheduleDescriptor()
{
}

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

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

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

unsigned int LEACH_TDMA_ScheduleDescriptor::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_ISARRAY | FD_ISEDITABLE,
    };
    return (field>=0 && field<1) ? fieldTypeFlags[field] : 0;
}

const char *LEACH_TDMA_ScheduleDescriptor::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[] = {
        "schedule",
    };
    return (field>=0 && field<1) ? fieldNames[field] : NULL;
}

int LEACH_TDMA_ScheduleDescriptor::findField(void *object, const char *fieldName) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    int base = basedesc ? basedesc->getFieldCount(object) : 0;
    if (fieldName[0]=='s' && strcmp(fieldName, "schedule")==0) return base+0;
    return basedesc ? basedesc->findField(object, fieldName) : -1;
}

const char *LEACH_TDMA_ScheduleDescriptor::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[] = {
        "int",
    };
    return (field>=0 && field<1) ? fieldTypeStrings[field] : NULL;
}

const char *LEACH_TDMA_ScheduleDescriptor::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 LEACH_TDMA_ScheduleDescriptor::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);
    }
    LEACH_TDMA_Schedule *pp = (LEACH_TDMA_Schedule *)object; (void)pp;
    switch (field) {
        case 0: return pp->getScheduleArraySize();
        default: return 0;
    }
}

std::string LEACH_TDMA_ScheduleDescriptor::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);
    }
    LEACH_TDMA_Schedule *pp = (LEACH_TDMA_Schedule *)object; (void)pp;
    switch (field) {
        case 0: return long2string(pp->getSchedule(i));
        default: return "";
    }
}

bool LEACH_TDMA_ScheduleDescriptor::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);
    }
    LEACH_TDMA_Schedule *pp = (LEACH_TDMA_Schedule *)object; (void)pp;
    switch (field) {
        case 0: pp->setSchedule(i,string2long(value)); return true;
        default: return false;
    }
}

const char *LEACH_TDMA_ScheduleDescriptor::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[] = {
        NULL,
    };
    return (field>=0 && field<1) ? fieldStructNames[field] : NULL;
}

void *LEACH_TDMA_ScheduleDescriptor::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);
    }
    LEACH_TDMA_Schedule *pp = (LEACH_TDMA_Schedule *)object; (void)pp;
    switch (field) {
        default: return NULL;
    }
}


