#include <BinnerFilter.h>
#include <DataNode.h>

// ****************************************************************************
// Method: Binner::Binner
//
// Purpose: 
//   Constructor for the Binner class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

Binner::Binner() : AttributeSubject("iii")
{
}

// ****************************************************************************
// Method: Binner::Binner
//
// Purpose: 
//   Copy constructor for the Binner class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

Binner::Binner(const Binner &obj) : AttributeSubject("iii")
{
    dim1 = obj.dim1;
    dim2 = obj.dim2;
    dim3 = obj.dim3;

    SelectAll();
}

// ****************************************************************************
// Method: Binner::~Binner
//
// Purpose: 
//   Destructor for the Binner class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

Binner::~Binner()
{
    // nothing here
}

// ****************************************************************************
// Method: Binner::operator = 
//
// Purpose: 
//   Assignment operator for the Binner class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

Binner& 
Binner::operator = (const Binner &obj)
{
    if (this == &obj) return *this;
    dim1 = obj.dim1;
    dim2 = obj.dim2;
    dim3 = obj.dim3;

    SelectAll();
    return *this;
}

// ****************************************************************************
// Method: Binner::operator == 
//
// Purpose: 
//   Comparison operator == for the Binner class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

bool
Binner::operator == (const Binner &obj) const
{
    // Create the return value
    return ((dim1 == obj.dim1) &&
            (dim2 == obj.dim2) &&
            (dim3 == obj.dim3));
}

// ****************************************************************************
// Method: Binner::operator != 
//
// Purpose: 
//   Comparison operator != for the Binner class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

bool
Binner::operator != (const Binner &obj) const
{
    return !(this->operator == (obj));
}

// ****************************************************************************
// Method: Binner::TypeName
//
// Purpose: 
//   Type name method for the Binner class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

const std::string
Binner::TypeName() const
{
    return "Binner";
}

// ****************************************************************************
// Method: Binner::CopyAttributes
//
// Purpose: 
//   CopyAttributes method for the Binner class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

bool
Binner::CopyAttributes(const AttributeGroup *atts)
{
    if(TypeName() != atts->TypeName())
        return false;

    // Call assignment operator.
    const Binner *tmp = (const Binner *)atts;
    *this = *tmp;

    return true;
}

// ****************************************************************************
// Method: Binner::CreateCompatible
//
// Purpose: 
//   CreateCompatible method for the Binner class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

AttributeSubject *
Binner::CreateCompatible(const std::string &tname) const
{
    AttributeSubject *retval = 0;
    if(TypeName() == tname)
        retval = new Binner(*this);
    // Other cases could go here too. 

    return retval;
}

// ****************************************************************************
// Method: Binner::NewInstance
//
// Purpose: 
//   NewInstance method for the Binner class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

AttributeSubject *
Binner::NewInstance(bool copy) const
{
    AttributeSubject *retval = 0;
    if(copy)
        retval = new Binner(*this);
    else
        retval = new Binner;

    return retval;
}

// ****************************************************************************
// Method: Binner::SelectAll
//
// Purpose: 
//   Selects all attributes.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

void
Binner::SelectAll()
{
    Select(0, (void *)&dim1);
    Select(1, (void *)&dim2);
    Select(2, (void *)&dim3);
}

///////////////////////////////////////////////////////////////////////////////
// Persistence methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: Binner::CreateNode
//
// Purpose: 
//   This method creates a DataNode representation of the object so it can be saved to a config file.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

bool
Binner::CreateNode(DataNode *parentNode, bool completeSave, bool forceAdd)
{
    if(parentNode == 0)
        return false;

    Binner defaultObject;
    bool addToParent = false;
    // Create a node for Binner.
    DataNode *node = new DataNode("Binner");

    if(completeSave || !FieldsEqual(0, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("dim1", dim1));
    }

    if(completeSave || !FieldsEqual(1, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("dim2", dim2));
    }

    if(completeSave || !FieldsEqual(2, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("dim3", dim3));
    }


    // Add the node to the parent node.
    if(addToParent || forceAdd)
        parentNode->AddNode(node);
    else
        delete node;

    return (addToParent || forceAdd);
}

// ****************************************************************************
// Method: Binner::SetFromNode
//
// Purpose: 
//   This method sets attributes in this object from values in a DataNode representation of the object.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

void
Binner::SetFromNode(DataNode *parentNode)
{
    int i;
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("Binner");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("dim1")) != 0)
        SetDim1(node->AsInt());
    if((node = searchNode->GetNode("dim2")) != 0)
        SetDim2(node->AsInt());
    if((node = searchNode->GetNode("dim3")) != 0)
        SetDim3(node->AsInt());
}

///////////////////////////////////////////////////////////////////////////////
// Set property methods
///////////////////////////////////////////////////////////////////////////////

void
Binner::SetDim1(int dim1_)
{
    dim1 = dim1_;
    Select(0, (void *)&dim1);
}

void
Binner::SetDim2(int dim2_)
{
    dim2 = dim2_;
    Select(1, (void *)&dim2);
}

void
Binner::SetDim3(int dim3_)
{
    dim3 = dim3_;
    Select(2, (void *)&dim3);
}

///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////

int
Binner::GetDim1() const
{
    return dim1;
}

int
Binner::GetDim2() const
{
    return dim2;
}

int
Binner::GetDim3() const
{
    return dim3;
}

///////////////////////////////////////////////////////////////////////////////
// Keyframing methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: Binner::GetFieldName
//
// Purpose: 
//   This method returns the name of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

std::string
Binner::GetFieldName(int index) const
{
    switch (index)
    {
        case 0:  return "dim1";
        case 1:  return "dim2";
        case 2:  return "dim3";
        default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: Binner::GetFieldType
//
// Purpose: 
//   This method returns the type of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

AttributeGroup::FieldType
Binner::GetFieldType(int index) const
{
    switch (index)
    {
        case 0:  return FieldType_int;
        case 1:  return FieldType_int;
        case 2:  return FieldType_int;
        default:  return FieldType_unknown;
    }
}

// ****************************************************************************
// Method: Binner::GetFieldTypeName
//
// Purpose: 
//   This method returns the name of a field type given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

std::string
Binner::GetFieldTypeName(int index) const
{
    switch (index)
    {
        case 0:  return "int";
        case 1:  return "int";
        case 2:  return "int";
        default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: Binner::FieldsEqual
//
// Purpose: 
//   This method compares two fields and return true if they are equal.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   Thu Mar 30 12:05:25 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

bool
Binner::FieldsEqual(int index_, const AttributeGroup *rhs) const
{
    const Binner &obj = *((const Binner*)rhs);
    bool retval = false;
    switch (index_)
    {
    case 0:
        {  // new scope
        retval = (dim1 == obj.dim1);
        }
        break;
    case 1:
        {  // new scope
        retval = (dim2 == obj.dim2);
        }
        break;
    case 2:
        {  // new scope
        retval = (dim3 == obj.dim3);
        }
        break;
    default: retval = false;
    }

    return retval;
}

///////////////////////////////////////////////////////////////////////////////
// User-defined methods.
///////////////////////////////////////////////////////////////////////////////

