/* This software is distributed under the Lesser General Public License */
//
// Attribute_list.cpp
//
// This file implements the classes
//   GT_Attribute_list
//
//------------------------------------------ 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_list.cpp,v $
// $Author: himsolt $
// $Revision: 1.3 $
// $Date: 1999/03/05 20:43:02 $
// $Locker:  $
// $State: Exp $
//
//------------------------------------------ CVS
//
// (C) University of Passau 1995-1999, graphlet Project
//

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

#include "Attribute_list.h"


//////////////////////////////////////////
//
// GT_Attribute_list
//
//////////////////////////////////////////


GT_Attribute_list::GT_Attribute_list (const GT_Key key,
    GT_List_of_Attributes* l,
    const int flags) :
	GT_Attribute_Base (key, flags)
{
    the_value = l;
    the_flags |= the_is_list;
}


GT_Attribute_list::GT_Attribute_list (const GT_Key key,
    GT_Tagged_Attributes* l,
    const int flags) :
	GT_Attribute_Base (key, flags)
{
    the_value = l;
    the_flags |= the_is_list | the_is_complex;
}


GT_Attribute_list::~GT_Attribute_list ()
{
    delete the_value;
}



//////////////////////////////////////////
//
// Cloning
//
//////////////////////////////////////////


void GT_Attribute_list::copy (const GT_Attribute_list* from,
    GT_Copy type)
{
    GT_Attribute_Base::copy (from, type);
    if (type.is_deep()) {
	the_value = from->the_value->clone(type);
    } else {
	the_value = from->the_value;
    }
}


GT_Attribute_Base* GT_Attribute_list::clone (GT_Copy type) const
{
    if (the_flags | the_is_safe) {

	GT_Attribute_list* new_attrs = new GT_Attribute_list (the_key,
	    (GT_List_of_Attributes*)0,
	    the_flags);
	if (type.is_deep()) {
	    new_attrs->copy (this, type);
	} else {
	    new_attrs->the_value = the_value;
	}
	return new_attrs;
	
    } else {
	return 0;
    }
}



//////////////////////////////////////////
//
// Printing
//
//////////////////////////////////////////


void GT_Attribute_list::print (ostream &out) const
{
    if (the_key.description()->safe() || (the_flags & the_is_safe)) {
	if (do_print()) {
	    baseclass::print (out);
	    GT_print (out, the_value);
	}
    }
}


bool GT_Attribute_list::do_print () const
{
    return the_value->do_print();
}



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


bool GT_Attribute_list::value_list (GT_List_of_Attributes*& i) const
{
    i = the_value;
    return true;
}


bool GT_Attribute_list::value_list (const GT_List_of_Attributes*& i) const
{
    i = the_value;
    return true;
}
