/* This software is distributed under the Lesser General Public License */
//
// Attributes.cpp
//
// This file implements the classes
//   GT_Attribute_Base
//   GT_Attribut<T>
//   GT_Attributes
//   GT_List_of_Attributes
//
//------------------------------------------ CVS
//
// CVS Headers -- The following headers are generated by the CVS
// version control system. Note that especially the attribute
// Author is not necessarily the author of the code.
//
// $Source: /home/br/CVS/graphlet/src/gt_base/Attribute_Base.cpp,v $
// $Author: himsolt $
// $Revision: 1.3 $
// $Date: 1999/03/05 20:42:52 $
// $Locker:  $
// $State: Exp $
//
//------------------------------------------ CVS
//
// (C) University of Passau 1995-1999, graphlet Project
//

#include "Graphlet.h"
#include "GML.h"
#include "Key_description.h"

#include "Attribute_Base.h"


//////////////////////////////////////////
//
// class GT_Attribute_Base
//
//////////////////////////////////////////

//
// Constructor && Destructor
//


GT_Attribute_Base::GT_Attribute_Base (const GT_Key key, const int flags)
{
    the_key = key;
    the_flags = flags;

    if (key.description()->safe()) {
	the_flags |= the_is_safe;
    }
};



GT_Attribute_Base::~GT_Attribute_Base()
{
};


void GT_Attribute_Base::set_safe() {
    the_flags |= the_is_safe;
}


void GT_Attribute_Base::copy (const GT_Attribute_Base* from,
    GT_Copy /* type */)
{
    // shallow and dep copy are the same; type is ignored
    
    the_flags = from->the_flags;
    the_key = from->the_key;
}


//////////////////////////////////////////
//
// Print Function
//
//////////////////////////////////////////


void GT_Attribute_Base::print (ostream &out, const GT_Key& key)
{
    assert (key.defined());

    if (key.description()->visible()) {
	out << key.description()->name() << ' ';
    }
}



void GT_Attribute_Base::print (ostream &out) const
{
    print (out, the_key);
}



//////////////////////////////////////////
//
// Value extraction
//
//////////////////////////////////////////


bool GT_Attribute_Base::value_int (int& /* i */) const
{
    return false;
}


bool GT_Attribute_Base::value_double (double& /* d */) const
{
    return false;
}


bool GT_Attribute_Base::value_string (string& /* s */) const
{
    return false;
}


bool GT_Attribute_Base::value_list (GT_List_of_Attributes*&) const
{
    return false;
}

bool GT_Attribute_Base::value_list (const GT_List_of_Attributes*&) const
{
    return false;
}



//////////////////////////////////////////
//
// A bite of optimization: if do_print returns false, the
// attribute should not be printed.
//
//////////////////////////////////////////


bool GT_Attribute_Base::do_print () const
{
    return true;
}


//////////////////////////////////////////
//
// Output operator << defaults to print
//
//////////////////////////////////////////



ostream& operator<< (ostream& out, const GT_Attribute_Base* attr)
{
    if (attr) {
        attr->print (out);
    }
    return out;
}
